Diff
Modified: trunk/Source/WebCore/ChangeLog (222507 => 222508)
--- trunk/Source/WebCore/ChangeLog 2017-09-26 18:12:50 UTC (rev 222507)
+++ trunk/Source/WebCore/ChangeLog 2017-09-26 18:20:59 UTC (rev 222508)
@@ -1,3 +1,58 @@
+2017-09-26 Basuke Suzuki <[email protected]>
+
+ [Curl] Simplify JobManager's duty and move the tasks to client
+ for easy handling. Also simlify CurlHandle by not storing internal
+ error value as a member variable.
+ https://bugs.webkit.org/show_bug.cgi?id=177466
+
+ Reviewed by Alex Christensen.
+
+ * platform/network/curl/CurlContext.cpp:
+ (WebCore::CurlHandle::perform):
+ (WebCore::CurlHandle::pause):
+ (WebCore::CurlHandle::getEffectiveURL):
+ (WebCore::CurlHandle::getPrimaryPort):
+ (WebCore::CurlHandle::getResponseCode):
+ (WebCore::CurlHandle::getContentLength):
+ (WebCore::CurlHandle::getHttpAuthAvail):
+ (WebCore::CurlHandle::getNetworkLoadMetrics):
+ * platform/network/curl/CurlContext.h:
+ (WebCore::CurlHandle::errorCode const): Deleted.
+ (WebCore::CurlHandle::setErrorCode): Deleted.
+ * platform/network/curl/CurlDownload.cpp:
+ (WebCore::CurlDownload::start):
+ (WebCore::CurlDownload::cancel):
+ (WebCore::CurlDownload::setupTransfer):
+ (WebCore::CurlDownload::didCompleteTransfer):
+ (WebCore::CurlDownload::didCancelTransfer):
+ (WebCore::CurlDownload::setupRequest): Deleted.
+ (WebCore::CurlDownload::notifyFinish): Deleted.
+ (WebCore::CurlDownload::notifyFail): Deleted.
+ * platform/network/curl/CurlDownload.h:
+ * platform/network/curl/CurlJobManager.cpp:
+ (WebCore::CurlJobList::startJobs):
+ (WebCore::CurlJobList::finishJobs):
+ (WebCore::CurlJobManager::add):
+ (WebCore::CurlJobManager::cancel):
+ (WebCore::CurlJobManager::callOnJobThread):
+ (WebCore::CurlJobManager::updateJobList):
+ (WebCore::CurlJobManager::workerThread):
+ (WebCore::CurlJobList::notifyResult): Deleted.
+ * platform/network/curl/CurlJobManager.h:
+ * platform/network/curl/ResourceHandleCurlDelegate.cpp:
+ (WebCore::ResourceHandleCurlDelegate::start):
+ (WebCore::ResourceHandleCurlDelegate::cancel):
+ (WebCore::ResourceHandleCurlDelegate::dispatchSynchronousJob):
+ (WebCore::ResourceHandleCurlDelegate::setupTransfer):
+ (WebCore::ResourceHandleCurlDelegate::didCompleteTransfer):
+ (WebCore::ResourceHandleCurlDelegate::didCancelTransfer):
+ (WebCore::ResourceHandleCurlDelegate::didFinish):
+ (WebCore::ResourceHandleCurlDelegate::didFail):
+ (WebCore::ResourceHandleCurlDelegate::setupRequest): Deleted.
+ (WebCore::ResourceHandleCurlDelegate::notifyFinish): Deleted.
+ (WebCore::ResourceHandleCurlDelegate::notifyFail): Deleted.
+ * platform/network/curl/ResourceHandleCurlDelegate.h:
+
2017-09-26 Daniel Bates <[email protected]>
Cleanup: Consolidate non-selection background painting code for text
Modified: trunk/Source/WebCore/platform/network/curl/CurlContext.cpp (222507 => 222508)
--- trunk/Source/WebCore/platform/network/curl/CurlContext.cpp 2017-09-26 18:12:50 UTC (rev 222507)
+++ trunk/Source/WebCore/platform/network/curl/CurlContext.cpp 2017-09-26 18:20:59 UTC (rev 222508)
@@ -270,14 +270,12 @@
CURLcode CurlHandle::perform()
{
- m_errorCode = curl_easy_perform(m_handle);
- return m_errorCode;
+ return curl_easy_perform(m_handle);
}
CURLcode CurlHandle::pause(int bitmask)
{
- m_errorCode = curl_easy_pause(m_handle, bitmask);
- return m_errorCode;
+ return curl_easy_pause(m_handle, bitmask);
}
void CurlHandle::enableShareHandle()
@@ -541,14 +539,12 @@
URL CurlHandle::getEffectiveURL()
{
- if (!m_handle) {
- m_errorCode = CURLE_FAILED_INIT;
+ if (!m_handle)
return URL();
- }
char* url;
- m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_EFFECTIVE_URL, &url);
- if (m_errorCode != CURLE_OK)
+ CURLcode errorCode = curl_easy_getinfo(m_handle, CURLINFO_EFFECTIVE_URL, &url);
+ if (errorCode != CURLE_OK)
return URL();
return URL(URL(), url);
@@ -556,14 +552,12 @@
std::optional<uint16_t> CurlHandle::getPrimaryPort()
{
- if (!m_handle) {
- m_errorCode = CURLE_FAILED_INIT;
+ if (!m_handle)
return std::nullopt;
- }
long port;
- m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_PRIMARY_PORT, &port);
- if (m_errorCode != CURLE_OK)
+ CURLcode errorCode = curl_easy_getinfo(m_handle, CURLINFO_PRIMARY_PORT, &port);
+ if (errorCode != CURLE_OK)
return std::nullopt;
/*
@@ -575,14 +569,12 @@
std::optional<long> CurlHandle::getResponseCode()
{
- if (!m_handle) {
- m_errorCode = CURLE_FAILED_INIT;
+ if (!m_handle)
return std::nullopt;
- }
long responseCode;
- m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_RESPONSE_CODE, &responseCode);
- if (m_errorCode != CURLE_OK)
+ CURLcode errorCode = curl_easy_getinfo(m_handle, CURLINFO_RESPONSE_CODE, &responseCode);
+ if (errorCode != CURLE_OK)
return std::nullopt;
return responseCode;
@@ -590,15 +582,13 @@
std::optional<long long> CurlHandle::getContentLength()
{
- if (!m_handle) {
- m_errorCode = CURLE_FAILED_INIT;
+ if (!m_handle)
return std::nullopt;
- }
double contentLength;
- m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &contentLength);
- if (m_errorCode != CURLE_OK)
+ CURLcode errorCode = curl_easy_getinfo(m_handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &contentLength);
+ if (errorCode != CURLE_OK)
return std::nullopt;
return static_cast<long long>(contentLength);
@@ -606,14 +596,12 @@
std::optional<long> CurlHandle::getHttpAuthAvail()
{
- if (!m_handle) {
- m_errorCode = CURLE_FAILED_INIT;
+ if (!m_handle)
return std::nullopt;
- }
long httpAuthAvailable;
- m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_HTTPAUTH_AVAIL, &httpAuthAvailable);
- if (m_errorCode != CURLE_OK)
+ CURLcode errorCode = curl_easy_getinfo(m_handle, CURLINFO_HTTPAUTH_AVAIL, &httpAuthAvailable);
+ if (errorCode != CURLE_OK)
return std::nullopt;
return httpAuthAvailable;
@@ -626,25 +614,23 @@
double appConnect = 0.0;
double startTransfer = 0.0;
- if (!m_handle) {
- m_errorCode = CURLE_FAILED_INIT;
+ if (!m_handle)
return std::nullopt;
- }
- m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_NAMELOOKUP_TIME, &nameLookup);
- if (m_errorCode != CURLE_OK)
+ CURLcode errorCode = curl_easy_getinfo(m_handle, CURLINFO_NAMELOOKUP_TIME, &nameLookup);
+ if (errorCode != CURLE_OK)
return std::nullopt;
- m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_CONNECT_TIME, &connect);
- if (m_errorCode != CURLE_OK)
+ errorCode = curl_easy_getinfo(m_handle, CURLINFO_CONNECT_TIME, &connect);
+ if (errorCode != CURLE_OK)
return std::nullopt;
- m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_APPCONNECT_TIME, &appConnect);
- if (m_errorCode != CURLE_OK)
+ errorCode = curl_easy_getinfo(m_handle, CURLINFO_APPCONNECT_TIME, &appConnect);
+ if (errorCode != CURLE_OK)
return std::nullopt;
- m_errorCode = curl_easy_getinfo(m_handle, CURLINFO_STARTTRANSFER_TIME, &startTransfer);
- if (m_errorCode != CURLE_OK)
+ errorCode = curl_easy_getinfo(m_handle, CURLINFO_STARTTRANSFER_TIME, &startTransfer);
+ if (errorCode != CURLE_OK)
return std::nullopt;
NetworkLoadMetrics networkLoadMetrics;
Modified: trunk/Source/WebCore/platform/network/curl/CurlContext.h (222507 => 222508)
--- trunk/Source/WebCore/platform/network/curl/CurlContext.h 2017-09-26 18:12:50 UTC (rev 222507)
+++ trunk/Source/WebCore/platform/network/curl/CurlContext.h 2017-09-26 18:20:59 UTC (rev 222508)
@@ -224,9 +224,6 @@
CURLcode perform();
CURLcode pause(int);
- CURLcode errorCode() const { return m_errorCode; }
- void setErrorCode(CURLcode errorCode) { m_errorCode = errorCode; }
-
static const String errorDescription(CURLcode);
void enableShareHandle();
@@ -298,7 +295,6 @@
CURL* m_handle { nullptr };
char m_errorBuffer[CURL_ERROR_SIZE] { };
- CURLcode m_errorCode;
CurlSList m_requestHeaders;
};
Modified: trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp (222507 => 222508)
--- trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp 2017-09-26 18:12:50 UTC (rev 222507)
+++ trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp 2017-09-26 18:20:59 UTC (rev 222508)
@@ -77,15 +77,13 @@
bool CurlDownload::start()
{
- m_job = CurlJobManager::singleton().add(m_curlHandle, *this);
- return !!m_job;
+ CurlJobManager::singleton().add(this);
+ return true;
}
bool CurlDownload::cancel()
{
- CurlJobTicket job = m_job;
- m_job = nullptr;
- CurlJobManager::singleton().cancel(job);
+ CurlJobManager::singleton().cancel(this);
return true;
}
@@ -107,7 +105,7 @@
deref();
}
-void CurlDownload::setupRequest()
+CURL* CurlDownload::setupTransfer()
{
LockHolder locker(m_mutex);
@@ -121,24 +119,22 @@
m_curlHandle.enableHttpAuthentication(CURLAUTH_ANY);
m_curlHandle.setCACertPath(CurlContext::singleton().sslHandle().getCACertPath());
+ return m_curlHandle.handle();
}
-void CurlDownload::notifyFinish()
+void CurlDownload::didCompleteTransfer(CURLcode result)
{
- callOnMainThread([protectedThis = makeRef(*this)] {
- if (!protectedThis->m_job)
- return;
- protectedThis->didFinish();
+ callOnMainThread([protectedThis = makeRef(*this), result] {
+ if (result == CURLE_OK)
+ protectedThis->didFinish();
+ else
+ protectedThis->didFail();
});
}
-void CurlDownload::notifyFail()
+void CurlDownload::didCancelTransfer()
{
- callOnMainThread([protectedThis = makeRef(*this)] {
- if (!protectedThis->m_job)
- return;
- protectedThis->didFail();
- });
+
}
void CurlDownload::closeFile()
Modified: trunk/Source/WebCore/platform/network/curl/CurlDownload.h (222507 => 222508)
--- trunk/Source/WebCore/platform/network/curl/CurlDownload.h 2017-09-26 18:12:50 UTC (rev 222507)
+++ trunk/Source/WebCore/platform/network/curl/CurlDownload.h 2017-09-26 18:20:59 UTC (rev 222508)
@@ -68,9 +68,10 @@
void retain() override;
void release() override;
- void setupRequest() override;
- void notifyFinish() override;
- void notifyFail() override;
+ CURL* handle() override { return m_curlHandle.handle(); }
+ CURL* setupTransfer() override;
+ void didCompleteTransfer(CURLcode) override;
+ void didCancelTransfer() override;
void closeFile();
void moveFileToDestination();
@@ -93,7 +94,6 @@
CurlHandle m_curlHandle;
URL m_url;
- CurlJobTicket m_job;
String m_tempPath;
String m_destination;
PlatformFileHandle m_tempHandle { invalidPlatformFileHandle };
Modified: trunk/Source/WebCore/platform/network/curl/CurlJobManager.cpp (222507 => 222508)
--- trunk/Source/WebCore/platform/network/curl/CurlJobManager.cpp 2017-09-26 18:12:50 UTC (rev 222507)
+++ trunk/Source/WebCore/platform/network/curl/CurlJobManager.cpp 2017-09-26 18:20:59 UTC (rev 222508)
@@ -30,17 +30,8 @@
#if USE(CURL)
-#include "ResourceHandleCurlDelegate.h"
-#include <iterator>
-#include <wtf/MainThread.h>
-#include <wtf/text/CString.h>
-
-using namespace WebCore;
-
namespace WebCore {
-enum class CurlJobResult { Done, Error, Cancelled };
-
/*
* CurlJobList is used only in background so that no need to manage mutex
*/
@@ -48,79 +39,82 @@
public:
bool isEmpty() const { return m_activeJobs.isEmpty(); }
- void startJobs(HashMap<CurlJobTicket, CurlJobClient*>&& jobs)
+ void startJobs(HashSet<CurlJobClient*>&& jobs)
{
auto localJobs = WTFMove(jobs);
- for (auto& job : localJobs) {
- job.value->setupRequest();
- m_activeJobs.add(job.key, job.value);
- addHandle(job.key);
+ for (auto& client : localJobs) {
+ CURL* handle = client->setupTransfer();
+ if (!handle)
+ return;
+
+ m_activeJobs.add(handle, client);
+ addHandle(handle);
}
}
- void finishJobs(HashSet<CurlJobTicket>&& tickets, CurlJobResult result)
+ void finishJobs(HashMap<CURL*, CURLcode>&& tickets, WTF::Function<void(CurlJobClient*, CURLcode)> completionHandler)
{
auto localTickets = WTFMove(tickets);
for (auto& ticket : localTickets) {
- if (!m_activeJobs.contains(ticket))
+ if (!m_activeJobs.contains(ticket.key))
continue;
- removeHandle(ticket);
- notifyResult(m_activeJobs.inlineGet(ticket), result);
- m_activeJobs.remove(ticket);
+
+ CURL* handle = ticket.key;
+ CURLcode result = ticket.value;
+ CurlJobClient* client = m_activeJobs.inlineGet(handle);
+
+ removeHandle(handle);
+ m_activeJobs.remove(handle);
+ completionHandler(client, result);
+
+ callOnMainThread([client]() {
+ client->release();
+ });
}
}
private:
- void notifyResult(CurlJobClient* client, CurlJobResult result)
- {
- switch (result) {
- case CurlJobResult::Done:
- client->notifyFinish();
- break;
- case CurlJobResult::Error:
- client->notifyFail();
- break;
- case CurlJobResult::Cancelled:
- break;
- }
-
- client->release();
- }
-
- HashMap<CurlJobTicket, CurlJobClient*> m_activeJobs;
+ HashMap<CURL*, CurlJobClient*> m_activeJobs;
};
-CurlJobTicket CurlJobManager::add(CurlHandle& curl, CurlJobClient& client)
+bool CurlJobManager::add(CurlJobClient* client)
{
ASSERT(isMainThread());
- client.retain();
+ if (!client)
+ return false;
- CurlJobTicket ticket = static_cast<CurlJobTicket>(curl.handle());
+ client->retain();
{
LockHolder locker(m_mutex);
- m_cancelledTickets.remove(ticket);
- m_pendingJobs.add(ticket, &client);
+ m_pendingJobs.add(client);
}
startThreadIfNeeded();
- return ticket;
+ return true;
}
-void CurlJobManager::cancel(CurlJobTicket job)
+void CurlJobManager::cancel(CurlJobClient* client)
{
ASSERT(isMainThread());
+ if (!client || !client->handle())
+ return;
+
LockHolder locker(m_mutex);
- m_cancelledTickets.add(job);
+ m_cancelledJobs.add(client->handle(), CURLE_OK);
}
void CurlJobManager::callOnJobThread(WTF::Function<void()>&& task)
{
- LockHolder locker(m_mutex);
- m_taskQueue.append(WTFMove(task));
+ {
+ LockHolder locker(m_mutex);
+ m_taskQueue.append(WTFMove(task));
+ }
+
+ startThreadIfNeeded();
}
void CurlJobManager::startThreadIfNeeded()
@@ -164,8 +158,8 @@
{
ASSERT(!isMainThread());
- HashMap<CurlJobTicket, CurlJobClient*> pendingJobs;
- HashSet<CurlJobTicket> cancelledTickets;
+ HashSet<CurlJobClient*> pendingJobs;
+ HashMap<CURL*, CURLcode> cancelledJobs;
Vector<WTF::Function<void()>> taskQueue;
{
@@ -172,17 +166,22 @@
LockHolder locker(m_mutex);
pendingJobs = WTFMove(m_pendingJobs);
- cancelledTickets = WTFMove(m_cancelledTickets);
+ cancelledJobs = WTFMove(m_cancelledJobs);
taskQueue = WTFMove(m_taskQueue);
}
+ for (auto& task : taskQueue)
+ task();
+
jobs.startJobs(WTFMove(pendingJobs));
- jobs.finishJobs(WTFMove(cancelledTickets), CurlJobResult::Cancelled);
- jobs.finishJobs(WTFMove(m_finishedTickets), CurlJobResult::Done);
- jobs.finishJobs(WTFMove(m_failedTickets), CurlJobResult::Error);
- for (auto& task : taskQueue)
- task();
+ jobs.finishJobs(WTFMove(cancelledJobs), [](CurlJobClient* client, CURLcode) {
+ client->didCancelTransfer();
+ });
+
+ jobs.finishJobs(WTFMove(m_finishedJobs), [](CurlJobClient* client, CURLcode result) {
+ client->didCompleteTransfer(result);
+ });
}
void CurlJobManager::workerThread()
@@ -229,11 +228,7 @@
break;
ASSERT(msg->msg == CURLMSG_DONE);
- auto ticket = static_cast<CurlJobTicket>(msg->easy_handle);
- if (msg->data.result == CURLE_OK)
- m_finishedTickets.add(ticket);
- else
- m_failedTickets.add(ticket);
+ m_finishedJobs.add(msg->easy_handle, msg->data.result);
}
if (jobs.isEmpty())
Modified: trunk/Source/WebCore/platform/network/curl/CurlJobManager.h (222507 => 222508)
--- trunk/Source/WebCore/platform/network/curl/CurlJobManager.h 2017-09-26 18:12:50 UTC (rev 222507)
+++ trunk/Source/WebCore/platform/network/curl/CurlJobManager.h 2017-09-26 18:20:59 UTC (rev 222508)
@@ -37,7 +37,6 @@
namespace WebCore {
class CurlJobList;
-using CurlJobTicket = void*;
class CurlJobClient {
public:
@@ -44,9 +43,10 @@
virtual void retain() = 0;
virtual void release() = 0;
- virtual void setupRequest() = 0;
- virtual void notifyFinish() = 0;
- virtual void notifyFail() = 0;
+ virtual CURL* handle() = 0;
+ virtual CURL* setupTransfer() = 0;
+ virtual void didCompleteTransfer(CURLcode) = 0;
+ virtual void didCancelTransfer() = 0;
};
class CurlJobManager {
@@ -61,8 +61,8 @@
CurlJobManager() = default;
~CurlJobManager() { stopThread(); }
- CurlJobTicket add(CurlHandle&, CurlJobClient&);
- void cancel(CurlJobTicket);
+ bool add(CurlJobClient*);
+ void cancel(CurlJobClient*);
void callOnJobThread(WTF::Function<void()>&&);
@@ -76,10 +76,9 @@
void workerThread();
RefPtr<Thread> m_thread;
- HashMap<CurlJobTicket, CurlJobClient*> m_pendingJobs;
- HashSet<CurlJobTicket> m_cancelledTickets;
- HashSet<CurlJobTicket> m_finishedTickets;
- HashSet<CurlJobTicket> m_failedTickets;
+ HashSet<CurlJobClient*> m_pendingJobs;
+ HashMap<CURL*, CURLcode> m_finishedJobs;
+ HashMap<CURL*, CURLcode> m_cancelledJobs;
Vector<WTF::Function<void()>> m_taskQueue;
mutable Lock m_mutex;
bool m_runThread { false };
Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp (222507 => 222508)
--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp 2017-09-26 18:12:50 UTC (rev 222507)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp 2017-09-26 18:20:59 UTC (rev 222508)
@@ -93,16 +93,31 @@
m_handle = nullptr;
}
-bool ResourceHandleCurlDelegate::start()
+void ResourceHandleCurlDelegate::start(bool isSyncRequest)
{
- m_job = CurlJobManager::singleton().add(m_curlHandle, *this);
- return !!m_job;
+ m_isSyncRequest = isSyncRequest;
+
+ if (!m_isSyncRequest) {
+ // For asynchronous, use CurlJobManager. Curl processes runs on sub thread.
+ CurlJobManager::singleton().add(this);
+ } else {
+ // For synchronous, does not use CurlJobManager. Curl processes runs on main thread.
+ retain();
+ setupTransfer();
+
+ // curl_easy_perform blocks until the transfer is finished.
+ CURLcode resultCode = m_curlHandle.perform();
+ didCompleteTransfer(resultCode);
+ release();
+ }
}
void ResourceHandleCurlDelegate::cancel()
{
releaseHandle();
- CurlJobManager::singleton().cancel(m_job);
+
+ if (!m_isSyncRequest)
+ CurlJobManager::singleton().cancel(this);
}
void ResourceHandleCurlDelegate::setDefersLoading(bool defers)
@@ -143,9 +158,7 @@
void ResourceHandleCurlDelegate::dispatchSynchronousJob()
{
- URL kurl = m_firstRequest.url();
-
- if (kurl.protocolIsData()) {
+ if (m_firstRequest.url().protocolIsData()) {
handleDataURL();
return;
}
@@ -155,15 +168,7 @@
// and we would assert so force defersLoading to be false.
m_defersLoading = false;
- setupRequest();
-
- // curl_easy_perform blocks until the transfer is finished.
- CURLcode ret = m_curlHandle.perform();
-
- if (ret != CURLE_OK)
- notifyFail();
- else
- notifyFinish();
+ start(true);
}
void ResourceHandleCurlDelegate::retain()
@@ -176,7 +181,7 @@
deref();
}
-void ResourceHandleCurlDelegate::setupRequest()
+CURL* ResourceHandleCurlDelegate::setupTransfer()
{
CurlContext& context = CurlContext::singleton();
@@ -245,38 +250,46 @@
applyAuthentication();
m_curlHandle.enableProxyIfExists();
+
+ return m_curlHandle.handle();
}
-void ResourceHandleCurlDelegate::notifyFinish()
+void ResourceHandleCurlDelegate::didCompleteTransfer(CURLcode result)
{
- NetworkLoadMetrics networkLoadMetrics = getNetworkLoadMetrics();
+ if (result == CURLE_OK) {
+ NetworkLoadMetrics networkLoadMetrics = getNetworkLoadMetrics();
- if (isMainThread())
- didFinish(networkLoadMetrics);
- else {
- callOnMainThread([protectedThis = makeRef(*this), metrics = networkLoadMetrics.isolatedCopy()] {
- if (!protectedThis->m_handle)
- return;
- protectedThis->didFinish(metrics);
- });
+ if (isMainThread())
+ didFinish(networkLoadMetrics);
+ else {
+ callOnMainThread([protectedThis = makeRef(*this), metrics = networkLoadMetrics.isolatedCopy()] {
+ if (!protectedThis->m_handle)
+ return;
+ protectedThis->didFinish(metrics);
+ });
+ }
+ } else {
+ ResourceError resourceError = ResourceError::httpError(result, m_firstRequest.url());
+ if (m_sslVerifier.sslErrors())
+ resourceError.setSslErrors(m_sslVerifier.sslErrors());
+
+ if (isMainThread())
+ didFail(resourceError);
+ else {
+ callOnMainThread([protectedThis = makeRef(*this), error = resourceError.isolatedCopy()] {
+ if (!protectedThis->m_handle)
+ return;
+ protectedThis->didFail(error);
+ });
+ }
}
+
+ m_formDataStream = nullptr;
}
-void ResourceHandleCurlDelegate::notifyFail()
+void ResourceHandleCurlDelegate::didCancelTransfer()
{
- ResourceError resourceError = ResourceError::httpError(m_curlHandle.errorCode(), m_firstRequest.url());
- if (m_sslVerifier.sslErrors())
- resourceError.setSslErrors(m_sslVerifier.sslErrors());
-
- if (isMainThread())
- didFail(resourceError);
- else {
- callOnMainThread([protectedThis = makeRef(*this), error = resourceError.isolatedCopy()] {
- if (!protectedThis->m_handle)
- return;
- protectedThis->didFail(error);
- });
- }
+ m_formDataStream = nullptr;
}
ResourceResponse& ResourceHandleCurlDelegate::response()
@@ -425,8 +438,6 @@
{
response().setDeprecatedNetworkLoadMetrics(networkLoadMetrics);
- m_formDataStream = nullptr;
-
if (!m_handle)
return;
@@ -447,8 +458,6 @@
void ResourceHandleCurlDelegate::didFail(const ResourceError& resourceError)
{
- m_formDataStream = nullptr;
-
if (!m_handle)
return;
Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h (222507 => 222508)
--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h 2017-09-26 18:12:50 UTC (rev 222507)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h 2017-09-26 18:20:59 UTC (rev 222508)
@@ -29,7 +29,6 @@
#if USE(CURL)
#include "Credential.h"
-#include "CurlContext.h"
#include "CurlJobManager.h"
#include "CurlSSLVerifier.h"
#include "FormDataStreamCurl.h"
@@ -54,7 +53,7 @@
bool hasHandle() const;
void releaseHandle();
- bool start();
+ bool start() { start(false); return true; }
void cancel();
void setDefersLoading(bool);
@@ -66,13 +65,16 @@
void retain() override;
void release() override;
- void setupRequest() override;
- void notifyFinish() override;
- void notifyFail() override;
+ CURL* handle() override { return m_curlHandle.handle(); }
+ CURL* setupTransfer() override;
+ void didCompleteTransfer(CURLcode) override;
+ void didCancelTransfer() override;
// Called from main thread.
ResourceResponse& response();
+ void start(bool isSyncRequest);
+
void setupAuthentication();
void didReceiveAllHeaders(long httpCode, long long contentLength, uint16_t connectPort, long availableHttpAuth);
@@ -108,7 +110,6 @@
std::unique_ptr<FormDataStream> m_formDataStream;
std::unique_ptr<MultipartHandle> m_multipartHandle;
unsigned short m_authFailureCount { 0 };
- CurlJobTicket m_job { nullptr };
// Used by worker thread.
ResourceRequest m_firstRequest;
HTTPHeaderMap m_customHTTPHeaderFields;
@@ -122,6 +123,7 @@
CurlHandle m_curlHandle;
CurlSSLVerifier m_sslVerifier;
// Used by both threads.
+ bool m_isSyncRequest { false };
Condition m_workerThreadConditionVariable;
Lock m_workerThreadMutex;
size_t m_sendBytes { 0 };