Title: [224037] trunk/Source/WebCore
Revision
224037
Author
[email protected]
Date
2017-10-26 11:58:29 -0700 (Thu, 26 Oct 2017)

Log Message

[Curl] Rename CurlJobManager to CurlRequestScheduler
https://bugs.webkit.org/show_bug.cgi?id=178775

To match the meaning of the class.
It was originally meant to be more generic purpose, but as
other classes was introduced, the objective of the class is
now only to handle the life cycle of curl requests.

The delegate is also renamed to CurlRequestSchedulerClient.

Patch by Basuke Suzuki <[email protected]> on 2017-10-26
Reviewed by Alex Christensen.

* platform/Curl.cmake:
* platform/network/curl/CurlDownload.cpp:
(WebCore::CurlDownload::~CurlDownload):
(WebCore::CurlDownload::willSendRequest):
* platform/network/curl/CurlDownload.h:
* platform/network/curl/CurlRequest.cpp:
(WebCore::CurlRequest::CurlRequest):
(WebCore::CurlRequest::start):
(WebCore::CurlRequest::startWithJobManager):
(WebCore::CurlRequest::cancel):
(WebCore::CurlRequest::callClient):
(WebCore::CurlRequest::didReceiveData):
(WebCore::CurlRequest::didCompleteTransfer):
(WebCore::CurlRequest::invokeDidReceiveResponseForFile):
(WebCore::CurlRequest::invokeDidReceiveResponse):
(WebCore::CurlRequest::completeDidReceiveResponse):
(WebCore::CurlRequest::pausedStatusChanged):
(WebCore::CurlRequest::callDelegate): Deleted.
* platform/network/curl/CurlRequest.h:
(WebCore::CurlRequest::create):
(WebCore::CurlRequest::setClient):
(WebCore::CurlRequest::setDelegate): Deleted.
* platform/network/curl/CurlRequestClient.h: Renamed from Source/WebCore/platform/network/curl/CurlRequestDelegate.h.
* platform/network/curl/CurlRequestScheduler.cpp: Renamed from Source/WebCore/platform/network/curl/CurlJobManager.cpp.
(WebCore::CurlJobList::startJobs):
(WebCore::CurlJobList::finishJobs):
(WebCore::CurlRequestScheduler::singleton):
(WebCore::CurlRequestScheduler::add):
(WebCore::CurlRequestScheduler::cancel):
(WebCore::CurlRequestScheduler::callOnWorkerThread):
(WebCore::CurlRequestScheduler::startThreadIfNeeded):
(WebCore::CurlRequestScheduler::stopThreadIfNoMoreJobRunning):
(WebCore::CurlRequestScheduler::stopThread):
(WebCore::CurlRequestScheduler::updateJobList):
(WebCore::CurlRequestScheduler::workerThread):
* platform/network/curl/CurlRequestScheduler.h: Renamed from Source/WebCore/platform/network/curl/CurlJobManager.h.
(WebCore::CurlRequestScheduler::~CurlRequestScheduler):
* platform/network/curl/CurlRequestSchedulerClient.h: Added.
(WebCore::CurlRequestSchedulerClient::~CurlRequestSchedulerClient):
* platform/network/curl/ResourceHandleCurlDelegate.cpp:
(WebCore::ResourceHandleCurlDelegate::~ResourceHandleCurlDelegate):
(WebCore::ResourceHandleCurlDelegate::setAuthentication):
(WebCore::ResourceHandleCurlDelegate::continueAfterWillSendRequest):
* platform/network/curl/ResourceHandleCurlDelegate.h:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (224036 => 224037)


--- trunk/Source/WebCore/ChangeLog	2017-10-26 18:56:55 UTC (rev 224036)
+++ trunk/Source/WebCore/ChangeLog	2017-10-26 18:58:29 UTC (rev 224037)
@@ -1,3 +1,62 @@
+2017-10-26  Basuke Suzuki  <[email protected]>
+
+        [Curl] Rename CurlJobManager to CurlRequestScheduler
+        https://bugs.webkit.org/show_bug.cgi?id=178775
+
+        To match the meaning of the class.
+        It was originally meant to be more generic purpose, but as
+        other classes was introduced, the objective of the class is
+        now only to handle the life cycle of curl requests.
+
+        The delegate is also renamed to CurlRequestSchedulerClient.
+
+        Reviewed by Alex Christensen.
+
+        * platform/Curl.cmake:
+        * platform/network/curl/CurlDownload.cpp:
+        (WebCore::CurlDownload::~CurlDownload):
+        (WebCore::CurlDownload::willSendRequest):
+        * platform/network/curl/CurlDownload.h:
+        * platform/network/curl/CurlRequest.cpp:
+        (WebCore::CurlRequest::CurlRequest):
+        (WebCore::CurlRequest::start):
+        (WebCore::CurlRequest::startWithJobManager):
+        (WebCore::CurlRequest::cancel):
+        (WebCore::CurlRequest::callClient):
+        (WebCore::CurlRequest::didReceiveData):
+        (WebCore::CurlRequest::didCompleteTransfer):
+        (WebCore::CurlRequest::invokeDidReceiveResponseForFile):
+        (WebCore::CurlRequest::invokeDidReceiveResponse):
+        (WebCore::CurlRequest::completeDidReceiveResponse):
+        (WebCore::CurlRequest::pausedStatusChanged):
+        (WebCore::CurlRequest::callDelegate): Deleted.
+        * platform/network/curl/CurlRequest.h:
+        (WebCore::CurlRequest::create):
+        (WebCore::CurlRequest::setClient):
+        (WebCore::CurlRequest::setDelegate): Deleted.
+        * platform/network/curl/CurlRequestClient.h: Renamed from Source/WebCore/platform/network/curl/CurlRequestDelegate.h.
+        * platform/network/curl/CurlRequestScheduler.cpp: Renamed from Source/WebCore/platform/network/curl/CurlJobManager.cpp.
+        (WebCore::CurlJobList::startJobs):
+        (WebCore::CurlJobList::finishJobs):
+        (WebCore::CurlRequestScheduler::singleton):
+        (WebCore::CurlRequestScheduler::add):
+        (WebCore::CurlRequestScheduler::cancel):
+        (WebCore::CurlRequestScheduler::callOnWorkerThread):
+        (WebCore::CurlRequestScheduler::startThreadIfNeeded):
+        (WebCore::CurlRequestScheduler::stopThreadIfNoMoreJobRunning):
+        (WebCore::CurlRequestScheduler::stopThread):
+        (WebCore::CurlRequestScheduler::updateJobList):
+        (WebCore::CurlRequestScheduler::workerThread):
+        * platform/network/curl/CurlRequestScheduler.h: Renamed from Source/WebCore/platform/network/curl/CurlJobManager.h.
+        (WebCore::CurlRequestScheduler::~CurlRequestScheduler):
+        * platform/network/curl/CurlRequestSchedulerClient.h: Added.
+        (WebCore::CurlRequestSchedulerClient::~CurlRequestSchedulerClient):
+        * platform/network/curl/ResourceHandleCurlDelegate.cpp:
+        (WebCore::ResourceHandleCurlDelegate::~ResourceHandleCurlDelegate):
+        (WebCore::ResourceHandleCurlDelegate::setAuthentication):
+        (WebCore::ResourceHandleCurlDelegate::continueAfterWillSendRequest):
+        * platform/network/curl/ResourceHandleCurlDelegate.h:
+
 2017-10-26  Antti Koivisto  <[email protected]>
 
         Remove unnecessary whitespace invalidation logic from RenderTreeUpdater

Modified: trunk/Source/WebCore/platform/Curl.cmake (224036 => 224037)


--- trunk/Source/WebCore/platform/Curl.cmake	2017-10-26 18:56:55 UTC (rev 224036)
+++ trunk/Source/WebCore/platform/Curl.cmake	2017-10-26 18:58:29 UTC (rev 224037)
@@ -10,8 +10,8 @@
     platform/network/curl/CurlCacheManager.cpp
     platform/network/curl/CurlContext.cpp
     platform/network/curl/CurlDownload.cpp
-    platform/network/curl/CurlJobManager.cpp
     platform/network/curl/CurlRequest.cpp
+    platform/network/curl/CurlRequestScheduler.cpp
     platform/network/curl/CurlSSLHandle.cpp
     platform/network/curl/CurlSSLVerifier.cpp
     platform/network/curl/DNSCurl.cpp

Modified: trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp (224036 => 224037)


--- trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp	2017-10-26 18:56:55 UTC (rev 224036)
+++ trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp	2017-10-26 18:58:29 UTC (rev 224037)
@@ -40,7 +40,7 @@
 CurlDownload::~CurlDownload()
 {
     if (m_curlRequest)
-        m_curlRequest->setDelegate(nullptr);
+        m_curlRequest->setClient(nullptr);
 }
 
 void CurlDownload::init(CurlDownloadListener& listener, const URL& url)
@@ -196,7 +196,7 @@
     }
 
     m_curlRequest->cancel();
-    m_curlRequest->setDelegate(nullptr);
+    m_curlRequest->setClient(nullptr);
 
     m_curlRequest = createCurlRequest(newRequest);
     m_curlRequest->start();

Modified: trunk/Source/WebCore/platform/network/curl/CurlDownload.h (224036 => 224037)


--- trunk/Source/WebCore/platform/network/curl/CurlDownload.h	2017-10-26 18:56:55 UTC (rev 224036)
+++ trunk/Source/WebCore/platform/network/curl/CurlDownload.h	2017-10-26 18:58:29 UTC (rev 224037)
@@ -30,7 +30,7 @@
 #if USE(CURL)
 
 #include "CurlRequest.h"
-#include "CurlRequestDelegate.h"
+#include "CurlRequestClient.h"
 #include "ResourceRequest.h"
 #include "ResourceResponse.h"
 
@@ -47,7 +47,7 @@
     virtual void didFail() { }
 };
 
-class CurlDownload : public ThreadSafeRefCounted<CurlDownload>, public CurlRequestDelegate {
+class CurlDownload : public ThreadSafeRefCounted<CurlDownload>, public CurlRequestClient {
 public:
     CurlDownload() = default;
     ~CurlDownload();

Deleted: trunk/Source/WebCore/platform/network/curl/CurlJobManager.cpp (224036 => 224037)


--- trunk/Source/WebCore/platform/network/curl/CurlJobManager.cpp	2017-10-26 18:56:55 UTC (rev 224036)
+++ trunk/Source/WebCore/platform/network/curl/CurlJobManager.cpp	2017-10-26 18:58:29 UTC (rev 224037)
@@ -1,249 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc.  All rights reserved.
- * Copyright (C) 2017 Sony Interactive Entertainment Inc.
- * Copyright (C) 2017 NAVER Corp.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#include "config.h"
-#include "CurlJobManager.h"
-
-#if USE(CURL)
-
-#include <wtf/NeverDestroyed.h>
-
-namespace WebCore {
-
-/*
- * CurlJobList is used only in background so that no need to manage mutex
- */
-class CurlJobList : public CurlMultiHandle {
-public:
-    bool isEmpty() const { return m_activeJobs.isEmpty(); }
-
-    void startJobs(HashSet<CurlJobClient*>&& jobs)
-    {
-        auto localJobs = WTFMove(jobs);
-        for (auto& client : localJobs) {
-            CURL* handle = client->setupTransfer();
-            if (!handle)
-                return;
-
-            m_activeJobs.add(handle, client);
-            addHandle(handle);
-        }
-    }
-
-    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.key))
-                continue;
-
-            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:
-    HashMap<CURL*, CurlJobClient*> m_activeJobs;
-};
-
-CurlJobManager& CurlJobManager::singleton()
-{
-    static NeverDestroyed<CurlJobManager> sharedInstance;
-    return sharedInstance;
-}
-
-bool CurlJobManager::add(CurlJobClient* client)
-{
-    ASSERT(isMainThread());
-
-    if (!client)
-        return false;
-
-    client->retain();
-
-    {
-        LockHolder locker(m_mutex);
-        m_pendingJobs.add(client);
-    }
-
-    startThreadIfNeeded();
-
-    return true;
-}
-
-void CurlJobManager::cancel(CurlJobClient* client)
-{
-    ASSERT(isMainThread());
-
-    if (!client || !client->handle())
-        return;
-
-    LockHolder locker(m_mutex);
-    m_cancelledJobs.add(client->handle(), CURLE_OK);
-}
-
-void CurlJobManager::callOnJobThread(WTF::Function<void()>&& task)
-{
-    {
-        LockHolder locker(m_mutex);
-        m_taskQueue.append(WTFMove(task));
-    }
-
-    startThreadIfNeeded();
-}
-
-void CurlJobManager::startThreadIfNeeded()
-{
-    ASSERT(isMainThread());
-
-    LockHolder locker(m_mutex);
-    if (!m_runThread) {
-        if (m_thread)
-            m_thread->waitForCompletion();
-
-        m_runThread = true;
-        m_thread = Thread::create("curlThread", [this] {
-            workerThread();
-            m_runThread = false;
-        });
-    }
-}
-
-void CurlJobManager::stopThreadIfNoMoreJobRunning()
-{
-    ASSERT(!isMainThread());
-
-    LockHolder locker(m_mutex);
-
-    if (m_pendingJobs.isEmpty())
-        m_runThread = false;
-}
-
-void CurlJobManager::stopThread()
-{
-    m_runThread = false;
-
-    if (m_thread) {
-        m_thread->waitForCompletion();
-        m_thread = nullptr;
-    }
-}
-
-void CurlJobManager::updateJobList(CurlJobList& jobs)
-{
-    ASSERT(!isMainThread());
-
-    HashSet<CurlJobClient*> pendingJobs;
-    HashMap<CURL*, CURLcode> cancelledJobs;
-    Vector<WTF::Function<void()>> taskQueue;
-
-    {
-        LockHolder locker(m_mutex);
-
-        pendingJobs = WTFMove(m_pendingJobs);
-        cancelledJobs = WTFMove(m_cancelledJobs);
-        taskQueue = WTFMove(m_taskQueue);
-    }
-
-    for (auto& task : taskQueue)
-        task();
-
-    jobs.startJobs(WTFMove(pendingJobs));
-
-    jobs.finishJobs(WTFMove(cancelledJobs), [](CurlJobClient* client, CURLcode) {
-        client->didCancelTransfer();
-    });
-
-    jobs.finishJobs(WTFMove(m_finishedJobs), [](CurlJobClient* client, CURLcode result) {
-        client->didCompleteTransfer(result);
-    });
-}
-
-void CurlJobManager::workerThread()
-{
-    ASSERT(!isMainThread());
-
-    CurlJobList jobs;
-
-    while (m_runThread) {
-        updateJobList(jobs);
-
-        // Retry 'select' if it was interrupted by a process signal.
-        int rc = 0;
-        do {
-            fd_set fdread;
-            fd_set fdwrite;
-            fd_set fdexcep;
-            int maxfd = 0;
-
-            const int selectTimeoutMS = 5;
-
-            struct timeval timeout;
-            timeout.tv_sec = 0;
-            timeout.tv_usec = selectTimeoutMS * 1000; // select waits microseconds
-
-            jobs.getFdSet(fdread, fdwrite, fdexcep, maxfd);
-
-            // When the 3 file descriptors are empty, winsock will return -1
-            // and bail out, stopping the file download. So make sure we
-            // have valid file descriptors before calling select.
-            if (maxfd >= 0)
-                rc = ::select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
-        } while (rc == -1 && errno == EINTR);
-
-        int activeCount = 0;
-        while (jobs.perform(activeCount) == CURLM_CALL_MULTI_PERFORM) { }
-
-        // check the curl messages indicating completed transfers
-        // and free their resources
-        while (true) {
-            int messagesInQueue = 0;
-            CURLMsg* msg = jobs.readInfo(messagesInQueue);
-            if (!msg)
-                break;
-
-            ASSERT(msg->msg == CURLMSG_DONE);
-            m_finishedJobs.add(msg->easy_handle, msg->data.result);
-        }
-
-        if (jobs.isEmpty())
-            stopThreadIfNoMoreJobRunning();
-    }
-}
-
-}
-
-#endif

Deleted: trunk/Source/WebCore/platform/network/curl/CurlJobManager.h (224036 => 224037)


--- trunk/Source/WebCore/platform/network/curl/CurlJobManager.h	2017-10-26 18:56:55 UTC (rev 224036)
+++ trunk/Source/WebCore/platform/network/curl/CurlJobManager.h	2017-10-26 18:58:29 UTC (rev 224037)
@@ -1,85 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc.  All rights reserved.
- * Copyright (C) 2017 Sony Interactive Entertainment Inc.
- * Copyright (C) 2017 NAVER Corp.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#pragma once
-
-#include "CurlContext.h"
-#include <wtf/HashMap.h>
-#include <wtf/HashSet.h>
-#include <wtf/Lock.h>
-#include <wtf/Noncopyable.h>
-#include <wtf/Threading.h>
-
-namespace WebCore {
-
-class CurlJobList;
-
-class CurlJobClient {
-public:
-    virtual void retain() = 0;
-    virtual void release() = 0;
-
-    virtual CURL* handle() = 0;
-    virtual CURL* setupTransfer() = 0;
-    virtual void didCompleteTransfer(CURLcode) = 0;
-    virtual void didCancelTransfer() = 0;
-};
-
-class CurlJobManager {
-    WTF_MAKE_NONCOPYABLE(CurlJobManager);
-    friend NeverDestroyed<CurlJobManager>;
-public:
-    static CurlJobManager& singleton();
-
-    ~CurlJobManager() { stopThread(); }
-
-    bool add(CurlJobClient*);
-    void cancel(CurlJobClient*);
-
-    void callOnJobThread(WTF::Function<void()>&&);
-
-private:
-    CurlJobManager() = default;
-
-    void startThreadIfNeeded();
-    void stopThreadIfNoMoreJobRunning();
-    void stopThread();
-
-    void updateJobList(CurlJobList&);
-
-    void workerThread();
-
-    RefPtr<Thread> m_thread;
-    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 };
-};
-
-} // namespace WebCore

Modified: trunk/Source/WebCore/platform/network/curl/CurlRequest.cpp (224036 => 224037)


--- trunk/Source/WebCore/platform/network/curl/CurlRequest.cpp	2017-10-26 18:56:55 UTC (rev 224036)
+++ trunk/Source/WebCore/platform/network/curl/CurlRequest.cpp	2017-10-26 18:58:29 UTC (rev 224037)
@@ -28,7 +28,8 @@
 
 #if USE(CURL)
 
-#include "CurlRequestDelegate.h"
+#include "CurlRequestClient.h"
+#include "CurlRequestScheduler.h"
 #include "MIMETypeRegistry.h"
 #include "ResourceError.h"
 #include "SharedBuffer.h"
@@ -36,13 +37,13 @@
 
 namespace WebCore {
 
-CurlRequest::CurlRequest(const ResourceRequest&request, CurlRequestDelegate* delegate, bool shouldSuspend)
+CurlRequest::CurlRequest(const ResourceRequest&request, CurlRequestClient* client, bool shouldSuspend)
     : m_request(request.isolatedCopy())
     , m_shouldSuspend(shouldSuspend)
 {
     ASSERT(isMainThread());
 
-    setDelegate(delegate);
+    setClient(client);
     resolveBlobReferences(m_request);
 }
 
@@ -72,13 +73,13 @@
     auto url = ""
 
     if (!m_isSyncRequest) {
-        // For asynchronous, use CurlJobManager. Curl processes runs on sub thread.
+        // For asynchronous, use CurlRequestScheduler. Curl processes runs on sub thread.
         if (url.isLocalFile())
             invokeDidReceiveResponseForFile(url);
         else
             startWithJobManager();
     } else {
-        // For synchronous, does not use CurlJobManager. Curl processes runs on main thread.
+        // For synchronous, does not use CurlRequestScheduler. Curl processes runs on main thread.
         // curl_easy_perform blocks until the transfer is finished.
         retain();
         if (url.isLocalFile())
@@ -95,7 +96,7 @@
 {
     ASSERT(isMainThread());
 
-    CurlJobManager::singleton().add(this);
+    CurlRequestScheduler::singleton().add(this);
 }
 
 void CurlRequest::cancel()
@@ -108,7 +109,7 @@
     m_cancelled = true;
 
     if (!m_isSyncRequest)
-        CurlJobManager::singleton().cancel(this);
+        CurlRequestScheduler::singleton().cancel(this);
 
     setRequestPaused(false);
     setCallbackPaused(false);
@@ -129,15 +130,15 @@
 }
 
 /* `this` is protected inside this method. */
-void CurlRequest::callDelegate(WTF::Function<void(CurlRequestDelegate*)> task)
+void CurlRequest::callClient(WTF::Function<void(CurlRequestClient*)> task)
 {
     if (isMainThread()) {
-        if (CurlRequestDelegate* delegate = m_delegate)
-            task(delegate);
+        if (CurlRequestClient* client = m_client)
+            task(client);
     } else {
         callOnMainThread([protectedThis = makeRef(*this), task = WTFMove(task)]() mutable {
-            if (CurlRequestDelegate* delegate = protectedThis->m_delegate)
-                task(delegate);
+            if (CurlRequestClient* client = protectedThis->m_client)
+                task(client);
         });
     }
 }
@@ -328,9 +329,9 @@
     writeDataToDownloadFileIfEnabled(buffer);
 
     if (receiveBytes) {
-        callDelegate([this, buffer = WTFMove(buffer)](CurlRequestDelegate* delegate) mutable {
-            if (delegate)
-                delegate->curlDidReceiveBuffer(WTFMove(buffer));
+        callClient([this, buffer = WTFMove(buffer)](CurlRequestClient* client) mutable {
+            if (client)
+                client->curlDidReceiveBuffer(WTFMove(buffer));
         });
     }
 
@@ -356,9 +357,9 @@
                 m_networkLoadMetrics = *metrics;
 
             finalizeTransfer();
-            callDelegate([this](CurlRequestDelegate* delegate) {
-                if (delegate)
-                    delegate->curlDidComplete();
+            callClient([this](CurlRequestClient* client) {
+                if (client)
+                    client->curlDidComplete();
             });
         }
     } else {
@@ -367,9 +368,9 @@
             resourceError.setSslErrors(m_sslVerifier.sslErrors());
 
         finalizeTransfer();
-        callDelegate([this, error = resourceError.isolatedCopy()](CurlRequestDelegate* delegate) {
-            if (delegate)
-                delegate->curlDidFailWithError(error);
+        callClient([this, error = resourceError.isolatedCopy()](CurlRequestClient* client) {
+            if (client)
+                client->curlDidFailWithError(error);
         });
     }
 }
@@ -496,7 +497,7 @@
 
     if (!m_isSyncRequest) {
         // DidReceiveResponse must not be called immediately
-        CurlJobManager::singleton().callOnJobThread([protectedThis = makeRef(*this)]() {
+        CurlRequestScheduler::singleton().callOnWorkerThread([protectedThis = makeRef(*this)]() {
             protectedThis->invokeDidReceiveResponse(Action::StartTransfer);
         });
     } else {
@@ -512,9 +513,9 @@
     m_didNotifyResponse = true;
     m_actionAfterInvoke = behaviorAfterInvoke;
 
-    callDelegate([this, response = m_response.isolatedCopy()](CurlRequestDelegate* delegate) {
-        if (delegate)
-            delegate->curlDidReceiveResponse(response);
+    callClient([this, response = m_response.isolatedCopy()](CurlRequestClient* client) {
+        if (client)
+            client->curlDidReceiveResponse(response);
     });
 }
 
@@ -538,7 +539,7 @@
     } else if (m_actionAfterInvoke == Action::FinishTransfer) {
         // Keep the calling thread of didCompleteTransfer()
         if (!m_isSyncRequest) {
-            CurlJobManager::singleton().callOnJobThread([protectedThis = makeRef(*this), finishedResultCode = m_finishedResultCode]() {
+            CurlRequestScheduler::singleton().callOnWorkerThread([protectedThis = makeRef(*this), finishedResultCode = m_finishedResultCode]() {
                 protectedThis->didCompleteTransfer(finishedResultCode);
             });
         } else
@@ -580,7 +581,7 @@
         return;
 
     if (!m_isSyncRequest && isMainThread()) {
-        CurlJobManager::singleton().callOnJobThread([protectedThis = makeRef(*this), paused = isPaused()]() {
+        CurlRequestScheduler::singleton().callOnWorkerThread([protectedThis = makeRef(*this), paused = isPaused()]() {
             if (protectedThis->m_cancelled)
                 return;
 

Modified: trunk/Source/WebCore/platform/network/curl/CurlRequest.h (224036 => 224037)


--- trunk/Source/WebCore/platform/network/curl/CurlRequest.h	2017-10-26 18:56:55 UTC (rev 224036)
+++ trunk/Source/WebCore/platform/network/curl/CurlRequest.h	2017-10-26 18:58:29 UTC (rev 224037)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#include "CurlJobManager.h"
+#include "CurlRequestSchedulerClient.h"
 #include "CurlResponse.h"
 #include "CurlSSLVerifier.h"
 #include "FileSystem.h"
@@ -36,22 +36,22 @@
 
 namespace WebCore {
 
-class CurlRequestDelegate;
+class CurlRequestClient;
 class ResourceError;
 class SharedBuffer;
 
-class CurlRequest : public ThreadSafeRefCounted<CurlRequest>, public CurlJobClient {
+class CurlRequest : public ThreadSafeRefCounted<CurlRequest>, public CurlRequestSchedulerClient {
     WTF_MAKE_NONCOPYABLE(CurlRequest);
 
 public:
-    static Ref<CurlRequest> create(const ResourceRequest& request, CurlRequestDelegate* delegate, bool shouldSuspend = false)
+    static Ref<CurlRequest> create(const ResourceRequest& request, CurlRequestClient* client, bool shouldSuspend = false)
     {
-        return adoptRef(*new CurlRequest(request, delegate, shouldSuspend));
+        return adoptRef(*new CurlRequest(request, client, shouldSuspend));
     }
 
     virtual ~CurlRequest() = default;
 
-    void setDelegate(CurlRequestDelegate* delegate) { m_delegate = delegate;  }
+    void setClient(CurlRequestClient* client) { m_client = client;  }
     void setUserPass(const String&, const String&);
 
     void start(bool isSyncRequest = false);
@@ -78,7 +78,7 @@
         FinishTransfer
     };
 
-    CurlRequest(const ResourceRequest&, CurlRequestDelegate*, bool shouldSuspend);
+    CurlRequest(const ResourceRequest&, CurlRequestClient*, bool shouldSuspend);
 
     void retain() override { ref(); }
     void release() override { deref(); }
@@ -86,7 +86,7 @@
 
     void startWithJobManager();
 
-    void callDelegate(WTF::Function<void(CurlRequestDelegate*)>);
+    void callClient(WTF::Function<void(CurlRequestClient*)>);
 
     // Transfer processing of Request body, Response header/body
     // Called by worker thread in case of async, main thread in case of sync.
@@ -126,7 +126,7 @@
     static size_t didReceiveDataCallback(char*, size_t, size_t, void*);
 
 
-    std::atomic<CurlRequestDelegate*> m_delegate { };
+    std::atomic<CurlRequestClient*> m_client { };
     bool m_isSyncRequest { false };
     bool m_cancelled { false };
 

Copied: trunk/Source/WebCore/platform/network/curl/CurlRequestClient.h (from rev 224036, trunk/Source/WebCore/platform/network/curl/CurlRequestDelegate.h) (0 => 224037)


--- trunk/Source/WebCore/platform/network/curl/CurlRequestClient.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlRequestClient.h	2017-10-26 18:58:29 UTC (rev 224037)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/Ref.h>
+
+namespace WebCore {
+
+class CurlResponse;
+class ResourceError;
+class SharedBuffer;
+
+class CurlRequestClient {
+public:
+    virtual void curlDidReceiveResponse(const CurlResponse&) = 0;
+    virtual void curlDidReceiveBuffer(Ref<SharedBuffer>&&) = 0;
+    virtual void curlDidComplete() = 0;
+    virtual void curlDidFailWithError(const ResourceError&) = 0;
+};
+
+} // namespace WebCore

Deleted: trunk/Source/WebCore/platform/network/curl/CurlRequestDelegate.h (224036 => 224037)


--- trunk/Source/WebCore/platform/network/curl/CurlRequestDelegate.h	2017-10-26 18:56:55 UTC (rev 224036)
+++ trunk/Source/WebCore/platform/network/curl/CurlRequestDelegate.h	2017-10-26 18:58:29 UTC (rev 224037)
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2017 Sony Interactive Entertainment Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include <wtf/Ref.h>
-
-namespace WebCore {
-
-class CurlResponse;
-class ResourceError;
-class SharedBuffer;
-
-class CurlRequestDelegate {
-public:
-    virtual void curlDidReceiveResponse(const CurlResponse&) = 0;
-    virtual void curlDidReceiveBuffer(Ref<SharedBuffer>&&) = 0;
-    virtual void curlDidComplete() = 0;
-    virtual void curlDidFailWithError(const ResourceError&) = 0;
-};
-
-} // namespace WebCore

Copied: trunk/Source/WebCore/platform/network/curl/CurlRequestScheduler.cpp (from rev 224036, trunk/Source/WebCore/platform/network/curl/CurlJobManager.cpp) (0 => 224037)


--- trunk/Source/WebCore/platform/network/curl/CurlRequestScheduler.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlRequestScheduler.cpp	2017-10-26 18:58:29 UTC (rev 224037)
@@ -0,0 +1,250 @@
+/*
+ * Copyright (C) 2013 Apple Inc.  All rights reserved.
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2017 NAVER Corp.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "CurlRequestScheduler.h"
+
+#if USE(CURL)
+
+#include "CurlRequestSchedulerClient.h"
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+/*
+ * CurlJobList is used only in background so that no need to manage mutex
+ */
+class CurlJobList : public CurlMultiHandle {
+public:
+    bool isEmpty() const { return m_activeJobs.isEmpty(); }
+
+    void startJobs(HashSet<CurlRequestSchedulerClient*>&& jobs)
+    {
+        auto localJobs = WTFMove(jobs);
+        for (auto& client : localJobs) {
+            CURL* handle = client->setupTransfer();
+            if (!handle)
+                return;
+
+            m_activeJobs.add(handle, client);
+            addHandle(handle);
+        }
+    }
+
+    void finishJobs(HashMap<CURL*, CURLcode>&& tickets, WTF::Function<void(CurlRequestSchedulerClient*, CURLcode)> completionHandler)
+    {
+        auto localTickets = WTFMove(tickets);
+        for (auto& ticket : localTickets) {
+            if (!m_activeJobs.contains(ticket.key))
+                continue;
+
+            CURL* handle = ticket.key;
+            CURLcode result = ticket.value;
+            CurlRequestSchedulerClient* client = m_activeJobs.inlineGet(handle);
+
+            removeHandle(handle);
+            m_activeJobs.remove(handle);
+            completionHandler(client, result);
+
+            callOnMainThread([client]() {
+                client->release();
+            });
+        }
+    }
+
+private:
+    HashMap<CURL*, CurlRequestSchedulerClient*> m_activeJobs;
+};
+
+CurlRequestScheduler& CurlRequestScheduler::singleton()
+{
+    static NeverDestroyed<CurlRequestScheduler> sharedInstance;
+    return sharedInstance;
+}
+
+bool CurlRequestScheduler::add(CurlRequestSchedulerClient* client)
+{
+    ASSERT(isMainThread());
+
+    if (!client)
+        return false;
+
+    client->retain();
+
+    {
+        LockHolder locker(m_mutex);
+        m_pendingJobs.add(client);
+    }
+
+    startThreadIfNeeded();
+
+    return true;
+}
+
+void CurlRequestScheduler::cancel(CurlRequestSchedulerClient* client)
+{
+    ASSERT(isMainThread());
+
+    if (!client || !client->handle())
+        return;
+
+    LockHolder locker(m_mutex);
+    m_cancelledJobs.add(client->handle(), CURLE_OK);
+}
+
+void CurlRequestScheduler::callOnWorkerThread(WTF::Function<void()>&& task)
+{
+    {
+        LockHolder locker(m_mutex);
+        m_taskQueue.append(WTFMove(task));
+    }
+
+    startThreadIfNeeded();
+}
+
+void CurlRequestScheduler::startThreadIfNeeded()
+{
+    ASSERT(isMainThread());
+
+    LockHolder locker(m_mutex);
+    if (!m_runThread) {
+        if (m_thread)
+            m_thread->waitForCompletion();
+
+        m_runThread = true;
+        m_thread = Thread::create("curlThread", [this] {
+            workerThread();
+            m_runThread = false;
+        });
+    }
+}
+
+void CurlRequestScheduler::stopThreadIfNoMoreJobRunning()
+{
+    ASSERT(!isMainThread());
+
+    LockHolder locker(m_mutex);
+
+    if (m_pendingJobs.isEmpty())
+        m_runThread = false;
+}
+
+void CurlRequestScheduler::stopThread()
+{
+    m_runThread = false;
+
+    if (m_thread) {
+        m_thread->waitForCompletion();
+        m_thread = nullptr;
+    }
+}
+
+void CurlRequestScheduler::updateJobList(CurlJobList& jobs)
+{
+    ASSERT(!isMainThread());
+
+    HashSet<CurlRequestSchedulerClient*> pendingJobs;
+    HashMap<CURL*, CURLcode> cancelledJobs;
+    Vector<WTF::Function<void()>> taskQueue;
+
+    {
+        LockHolder locker(m_mutex);
+
+        pendingJobs = WTFMove(m_pendingJobs);
+        cancelledJobs = WTFMove(m_cancelledJobs);
+        taskQueue = WTFMove(m_taskQueue);
+    }
+
+    for (auto& task : taskQueue)
+        task();
+
+    jobs.startJobs(WTFMove(pendingJobs));
+
+    jobs.finishJobs(WTFMove(cancelledJobs), [](CurlRequestSchedulerClient* client, CURLcode) {
+        client->didCancelTransfer();
+    });
+
+    jobs.finishJobs(WTFMove(m_finishedJobs), [](CurlRequestSchedulerClient* client, CURLcode result) {
+        client->didCompleteTransfer(result);
+    });
+}
+
+void CurlRequestScheduler::workerThread()
+{
+    ASSERT(!isMainThread());
+
+    CurlJobList jobs;
+
+    while (m_runThread) {
+        updateJobList(jobs);
+
+        // Retry 'select' if it was interrupted by a process signal.
+        int rc = 0;
+        do {
+            fd_set fdread;
+            fd_set fdwrite;
+            fd_set fdexcep;
+            int maxfd = 0;
+
+            const int selectTimeoutMS = 5;
+
+            struct timeval timeout;
+            timeout.tv_sec = 0;
+            timeout.tv_usec = selectTimeoutMS * 1000; // select waits microseconds
+
+            jobs.getFdSet(fdread, fdwrite, fdexcep, maxfd);
+
+            // When the 3 file descriptors are empty, winsock will return -1
+            // and bail out, stopping the file download. So make sure we
+            // have valid file descriptors before calling select.
+            if (maxfd >= 0)
+                rc = ::select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
+        } while (rc == -1 && errno == EINTR);
+
+        int activeCount = 0;
+        while (jobs.perform(activeCount) == CURLM_CALL_MULTI_PERFORM) { }
+
+        // check the curl messages indicating completed transfers
+        // and free their resources
+        while (true) {
+            int messagesInQueue = 0;
+            CURLMsg* msg = jobs.readInfo(messagesInQueue);
+            if (!msg)
+                break;
+
+            ASSERT(msg->msg == CURLMSG_DONE);
+            m_finishedJobs.add(msg->easy_handle, msg->data.result);
+        }
+
+        if (jobs.isEmpty())
+            stopThreadIfNoMoreJobRunning();
+    }
+}
+
+}
+
+#endif

Copied: trunk/Source/WebCore/platform/network/curl/CurlRequestScheduler.h (from rev 224036, trunk/Source/WebCore/platform/network/curl/CurlJobManager.h) (0 => 224037)


--- trunk/Source/WebCore/platform/network/curl/CurlRequestScheduler.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlRequestScheduler.h	2017-10-26 18:58:29 UTC (rev 224037)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2013 Apple Inc.  All rights reserved.
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2017 NAVER Corp.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#pragma once
+
+#include "CurlContext.h"
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/Lock.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/Threading.h>
+
+namespace WebCore {
+
+class CurlJobList;
+class CurlRequestSchedulerClient;
+
+class CurlRequestScheduler {
+    WTF_MAKE_NONCOPYABLE(CurlRequestScheduler);
+    friend NeverDestroyed<CurlRequestScheduler>;
+public:
+    static CurlRequestScheduler& singleton();
+
+    ~CurlRequestScheduler() { stopThread(); }
+
+    bool add(CurlRequestSchedulerClient*);
+    void cancel(CurlRequestSchedulerClient*);
+
+    void callOnWorkerThread(WTF::Function<void()>&&);
+
+private:
+    CurlRequestScheduler() = default;
+
+    void startThreadIfNeeded();
+    void stopThreadIfNoMoreJobRunning();
+    void stopThread();
+
+    void updateJobList(CurlJobList&);
+
+    void workerThread();
+
+    RefPtr<Thread> m_thread;
+    HashSet<CurlRequestSchedulerClient*> 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 };
+};
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/network/curl/CurlRequestSchedulerClient.h (0 => 224037)


--- trunk/Source/WebCore/platform/network/curl/CurlRequestSchedulerClient.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlRequestSchedulerClient.h	2017-10-26 18:58:29 UTC (rev 224037)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2017 NAVER Corp.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ */
+
+#pragma once
+
+#include "CurlContext.h"
+
+namespace WebCore {
+
+class CurlRequestSchedulerClient {
+public:
+    virtual void retain() = 0;
+    virtual void release() = 0;
+
+    virtual CURL* handle() = 0;
+    virtual CURL* setupTransfer() = 0;
+    virtual void didCompleteTransfer(CURLcode) = 0;
+    virtual void didCancelTransfer() = 0;
+
+protected:
+    ~CurlRequestSchedulerClient() { }
+};
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp (224036 => 224037)


--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp	2017-10-26 18:56:55 UTC (rev 224036)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp	2017-10-26 18:58:29 UTC (rev 224037)
@@ -61,7 +61,7 @@
 ResourceHandleCurlDelegate::~ResourceHandleCurlDelegate()
 {
     if (m_curlRequest)
-        m_curlRequest->setDelegate(nullptr);
+        m_curlRequest->setClient(nullptr);
 }
 
 bool ResourceHandleCurlDelegate::hasHandle() const
@@ -124,7 +124,7 @@
 
     bool isSyncRequest = m_curlRequest->isSyncRequest();
     m_curlRequest->cancel();
-    m_curlRequest->setDelegate(nullptr);
+    m_curlRequest->setClient(nullptr);
 
     m_curlRequest = createCurlRequest(m_currentRequest);
     m_curlRequest->setUserPass(user, password);
@@ -390,7 +390,7 @@
 
     bool isSyncRequest = m_curlRequest->isSyncRequest();
     m_curlRequest->cancel();
-    m_curlRequest->setDelegate(nullptr);
+    m_curlRequest->setClient(nullptr);
 
     m_curlRequest = createCurlRequest(m_currentRequest);
 

Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h (224036 => 224037)


--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h	2017-10-26 18:56:55 UTC (rev 224036)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h	2017-10-26 18:58:29 UTC (rev 224037)
@@ -29,7 +29,7 @@
 #if USE(CURL)
 
 #include "Credential.h"
-#include "CurlRequestDelegate.h"
+#include "CurlRequestClient.h"
 #include "ResourceRequest.h"
 
 namespace WebCore {
@@ -39,7 +39,7 @@
 class ResourceHandle;
 class ResourceResponse;
 
-class ResourceHandleCurlDelegate final : public ThreadSafeRefCounted<ResourceHandleCurlDelegate>, public CurlRequestDelegate {
+class ResourceHandleCurlDelegate final : public ThreadSafeRefCounted<ResourceHandleCurlDelegate>, public CurlRequestClient {
 public:
     ResourceHandleCurlDelegate(ResourceHandle*);
     ~ResourceHandleCurlDelegate();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to