Move ServiceWorkerJob from FetchLoader to ThreadableLoader.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Sep 2017 21:33:02 +0000 (21:33 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Sep 2017 21:33:02 +0000 (21:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176231

Reviewed by Youenn Fablet.

No new tests (No behavior change).

* WebCore.xcodeproj/project.pbxproj:

Re-indent these headers. Yuck!
* loader/ThreadableLoader.h:
(WebCore::ThreadableLoader::ref):
(WebCore::ThreadableLoader::deref):
(WebCore::ThreadableLoader::ThreadableLoader):
(WebCore::ThreadableLoader::~ThreadableLoader):
* loader/ThreadableLoaderClient.h:
(WebCore::ThreadableLoaderClient::didSendData):
(WebCore::ThreadableLoaderClient::didReceiveResponse):
(WebCore::ThreadableLoaderClient::didReceiveData):
(WebCore::ThreadableLoaderClient::didFinishLoading):
(WebCore::ThreadableLoaderClient::didFail):
(WebCore::ThreadableLoaderClient::didFinishTiming):
(WebCore::ThreadableLoaderClient::ThreadableLoaderClient):
(WebCore::ThreadableLoaderClient::~ThreadableLoaderClient):

Move from FetchLoaderClient to ThreadableLoaderClient:
* workers/service/ServiceWorkerJob.cpp:
(WebCore::ServiceWorkerJob::fetchScriptWithContext):
(WebCore::ServiceWorkerJob::didReceiveResponse):
(WebCore::ServiceWorkerJob::didReceiveData):
(WebCore::ServiceWorkerJob::didFinishLoading):
(WebCore::ServiceWorkerJob::didFail):
(WebCore::ServiceWorkerJob::didSucceed): Deleted.
* workers/service/ServiceWorkerJob.h:

* workers/service/server/SWClientConnection.cpp: Add a now-required include.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221495 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/loader/ThreadableLoader.h
Source/WebCore/loader/ThreadableLoaderClient.h
Source/WebCore/workers/service/ServiceWorkerJob.cpp
Source/WebCore/workers/service/ServiceWorkerJob.h
Source/WebCore/workers/service/server/SWClientConnection.cpp

index 7f77f44..309af9b 100644 (file)
@@ -1,3 +1,42 @@
+2017-09-01  Brady Eidson  <beidson@apple.com>
+
+        Move ServiceWorkerJob from FetchLoader to ThreadableLoader.
+        https://bugs.webkit.org/show_bug.cgi?id=176231
+
+        Reviewed by Youenn Fablet.
+
+        No new tests (No behavior change).
+
+        * WebCore.xcodeproj/project.pbxproj:
+
+        Re-indent these headers. Yuck!
+        * loader/ThreadableLoader.h:
+        (WebCore::ThreadableLoader::ref):
+        (WebCore::ThreadableLoader::deref):
+        (WebCore::ThreadableLoader::ThreadableLoader):
+        (WebCore::ThreadableLoader::~ThreadableLoader):
+        * loader/ThreadableLoaderClient.h:
+        (WebCore::ThreadableLoaderClient::didSendData):
+        (WebCore::ThreadableLoaderClient::didReceiveResponse):
+        (WebCore::ThreadableLoaderClient::didReceiveData):
+        (WebCore::ThreadableLoaderClient::didFinishLoading):
+        (WebCore::ThreadableLoaderClient::didFail):
+        (WebCore::ThreadableLoaderClient::didFinishTiming):
+        (WebCore::ThreadableLoaderClient::ThreadableLoaderClient):
+        (WebCore::ThreadableLoaderClient::~ThreadableLoaderClient):
+
+        Move from FetchLoaderClient to ThreadableLoaderClient:
+        * workers/service/ServiceWorkerJob.cpp:
+        (WebCore::ServiceWorkerJob::fetchScriptWithContext):
+        (WebCore::ServiceWorkerJob::didReceiveResponse):
+        (WebCore::ServiceWorkerJob::didReceiveData):
+        (WebCore::ServiceWorkerJob::didFinishLoading):
+        (WebCore::ServiceWorkerJob::didFail):
+        (WebCore::ServiceWorkerJob::didSucceed): Deleted.
+        * workers/service/ServiceWorkerJob.h:
+
+        * workers/service/server/SWClientConnection.cpp: Add a now-required include.
+
 2017-09-01  Eric Carlson  <eric.carlson@apple.com>
 
         Switch HTMLMediaElement to release logging
index 4db7424..9396df4 100644 (file)
                517A53461F50C17F00DCDC0A /* SWServerWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A53421F50C16100DCDC0A /* SWServerWorker.h */; settings = {ATTRIBUTES = (Private, ); }; };
                517A534E1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */; };
                517A534F1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               517A53581F5889E800DCDC0A /* FetchLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 4147E2B61C89912600A7E715 /* FetchLoaderClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               517A535A1F5889EF00DCDC0A /* FetchLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 4147E2B51C89912600A7E715 /* FetchLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               517A53581F5889E800DCDC0A /* FetchLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 4147E2B61C89912600A7E715 /* FetchLoaderClient.h */; };
+               517A535A1F5889EF00DCDC0A /* FetchLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 4147E2B51C89912600A7E715 /* FetchLoader.h */; };
                517A535B1F588A4C00DCDC0A /* FetchBodyConsumer.h in Headers */ = {isa = PBXBuildFile; fileRef = 41CF8BE51D46222000707DC9 /* FetchBodyConsumer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                517A535D1F5899FE00DCDC0A /* ServiceWorkerFetchResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A535C1F5899F200DCDC0A /* ServiceWorkerFetchResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
                517A63C31B74318700E7DCDC /* KeyedDecoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */; };
                7CBA5BA61F0B4BDE0034D745 /* JSDOMConvertWebGL.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMConvertWebGL.cpp; sourceTree = "<group>"; };
                7CBBBCC41F560567005EFAAC /* DOMMatrix2DInit.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DOMMatrix2DInit.idl; sourceTree = "<group>"; };
                7CBBBCC61F560568005EFAAC /* DOMMatrix2DInit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMMatrix2DInit.h; sourceTree = "<group>"; };
-               7CBBBCC81F5617C0005EFAAC /* JSDOMMatrix2DInit.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = JSDOMMatrix2DInit.cpp; path = JSDOMMatrix2DInit.cpp; sourceTree = "<group>"; };
-               7CBBBCC91F5617C0005EFAAC /* JSDOMMatrix2DInit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = JSDOMMatrix2DInit.h; path = JSDOMMatrix2DInit.h; sourceTree = "<group>"; };
+               7CBBBCC81F5617C0005EFAAC /* JSDOMMatrix2DInit.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMMatrix2DInit.cpp; sourceTree = "<group>"; };
+               7CBBBCC91F5617C0005EFAAC /* JSDOMMatrix2DInit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSDOMMatrix2DInit.h; sourceTree = "<group>"; };
                7CC2DDF81EC9415A0027B774 /* NotificationPermission.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NotificationPermission.h; sourceTree = "<group>"; };
                7CC2DDFA1EC9415A0027B774 /* NotificationPermission.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = NotificationPermission.idl; sourceTree = "<group>"; };
                7CC2DDFE1EC95A440027B774 /* JSNotificationPermission.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNotificationPermission.cpp; sourceTree = "<group>"; };
index 630dca0..6be8e42 100644 (file)
 
 namespace WebCore {
 
-    class ResourceError;
-    class ResourceRequest;
-    class ResourceResponse;
-    class ScriptExecutionContext;
-    class ThreadableLoaderClient;
+class ResourceError;
+class ResourceRequest;
+class ResourceResponse;
+class ScriptExecutionContext;
+class ThreadableLoaderClient;
 
-    enum PreflightPolicy {
-        ConsiderPreflight,
-        ForcePreflight,
-        PreventPreflight
-    };
+enum PreflightPolicy {
+    ConsiderPreflight,
+    ForcePreflight,
+    PreventPreflight
+};
 
-    enum class ContentSecurityPolicyEnforcement {
-        DoNotEnforce,
-        EnforceChildSrcDirective,
-        EnforceConnectSrcDirective,
-        EnforceScriptSrcDirective,
-    };
+enum class ContentSecurityPolicyEnforcement {
+    DoNotEnforce,
+    EnforceChildSrcDirective,
+    EnforceConnectSrcDirective,
+    EnforceScriptSrcDirective,
+};
 
-    enum class ResponseFilteringPolicy {
-        Enable,
-        Disable,
-    };
+enum class ResponseFilteringPolicy {
+    Enable,
+    Disable,
+};
 
-    struct ThreadableLoaderOptions : ResourceLoaderOptions {
-        ThreadableLoaderOptions();
-        ThreadableLoaderOptions(const ResourceLoaderOptions&, PreflightPolicy, ContentSecurityPolicyEnforcement, String&& initiator, ResponseFilteringPolicy);
-        ~ThreadableLoaderOptions();
+struct ThreadableLoaderOptions : ResourceLoaderOptions {
+    ThreadableLoaderOptions();
+    ThreadableLoaderOptions(const ResourceLoaderOptions&, PreflightPolicy, ContentSecurityPolicyEnforcement, String&& initiator, ResponseFilteringPolicy);
+    ~ThreadableLoaderOptions();
 
-        ThreadableLoaderOptions isolatedCopy() const;
+    ThreadableLoaderOptions isolatedCopy() const;
 
-        PreflightPolicy preflightPolicy { ConsiderPreflight };
-        ContentSecurityPolicyEnforcement contentSecurityPolicyEnforcement { ContentSecurityPolicyEnforcement::EnforceConnectSrcDirective };
-        String initiator; // This cannot be an AtomicString, as isolatedCopy() wouldn't create an object that's safe for passing to another thread.
-        ResponseFilteringPolicy filteringPolicy { ResponseFilteringPolicy::Disable };
-    };
+    PreflightPolicy preflightPolicy { ConsiderPreflight };
+    ContentSecurityPolicyEnforcement contentSecurityPolicyEnforcement { ContentSecurityPolicyEnforcement::EnforceConnectSrcDirective };
+    String initiator; // This cannot be an AtomicString, as isolatedCopy() wouldn't create an object that's safe for passing to another thread.
+    ResponseFilteringPolicy filteringPolicy { ResponseFilteringPolicy::Disable };
+};
 
-    // Useful for doing loader operations from any thread (not threadsafe,
-    // just able to run on threads other than the main thread).
-    class ThreadableLoader {
-        WTF_MAKE_NONCOPYABLE(ThreadableLoader);
-    public:
-        static void loadResourceSynchronously(ScriptExecutionContext&, ResourceRequest&&, ThreadableLoaderClient&, const ThreadableLoaderOptions&);
-        static RefPtr<ThreadableLoader> create(ScriptExecutionContext&, ThreadableLoaderClient&, ResourceRequest&&, const ThreadableLoaderOptions&, String&& referrer = String());
+// Useful for doing loader operations from any thread (not threadsafe,
+// just able to run on threads other than the main thread).
+class ThreadableLoader {
+    WTF_MAKE_NONCOPYABLE(ThreadableLoader);
+public:
+    static void loadResourceSynchronously(ScriptExecutionContext&, ResourceRequest&&, ThreadableLoaderClient&, const ThreadableLoaderOptions&);
+    static RefPtr<ThreadableLoader> create(ScriptExecutionContext&, ThreadableLoaderClient&, ResourceRequest&&, const ThreadableLoaderOptions&, String&& referrer = String());
 
-        virtual void cancel() = 0;
-        void ref() { refThreadableLoader(); }
-        void deref() { derefThreadableLoader(); }
+    virtual void cancel() = 0;
+    void ref() { refThreadableLoader(); }
+    void deref() { derefThreadableLoader(); }
 
-        static void logError(ScriptExecutionContext&, const ResourceError&, const String&);
+    static void logError(ScriptExecutionContext&, const ResourceError&, const String&);
 
-    protected:
-        ThreadableLoader() { }
-        virtual ~ThreadableLoader() { }
-        virtual void refThreadableLoader() = 0;
-        virtual void derefThreadableLoader() = 0;
-    };
+protected:
+    ThreadableLoader() { }
+    virtual ~ThreadableLoader() { }
+    virtual void refThreadableLoader() = 0;
+    virtual void derefThreadableLoader() = 0;
+};
 
 } // namespace WebCore
index 2d58c92..af6a85f 100644 (file)
 
 namespace WebCore {
 
-    class ResourceError;
-    class ResourceResponse;
-    class ResourceTiming;
+class ResourceError;
+class ResourceResponse;
+class ResourceTiming;
 
-    class ThreadableLoaderClient {
-        WTF_MAKE_NONCOPYABLE(ThreadableLoaderClient); WTF_MAKE_FAST_ALLOCATED;
-    public:
-        virtual void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/) { }
+class ThreadableLoaderClient {
+    WTF_MAKE_NONCOPYABLE(ThreadableLoaderClient);
+public:
+    virtual void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/) { }
 
-        virtual void didReceiveResponse(unsigned long /*identifier*/, const ResourceResponse&) { }
-        virtual void didReceiveData(const char*, int /*dataLength*/) { }
-        virtual void didFinishLoading(unsigned long /*identifier*/) { }
-        virtual void didFail(const ResourceError&) { }
-        virtual void didFinishTiming(const ResourceTiming&) { }
+    virtual void didReceiveResponse(unsigned long /*identifier*/, const ResourceResponse&) { }
+    virtual void didReceiveData(const char*, int /*dataLength*/) { }
+    virtual void didFinishLoading(unsigned long /*identifier*/) { }
+    virtual void didFail(const ResourceError&) { }
+    virtual void didFinishTiming(const ResourceTiming&) { }
 
-    protected:
-        ThreadableLoaderClient() { }
-        virtual ~ThreadableLoaderClient() { }
-    };
+protected:
+    ThreadableLoaderClient() { }
+    virtual ~ThreadableLoaderClient() { }
+};
 
 } // namespace WebCore
index b41eaa0..98c38bd 100644 (file)
@@ -82,23 +82,19 @@ void ServiceWorkerJob::fetchScriptWithContext(ScriptExecutionContext& context)
     ASSERT(currentThread() == m_creationThread);
     ASSERT(!m_completed);
 
-    m_fetchLoader = std::make_unique<FetchLoader>(*this, nullptr);
-
     // FIXME: This Fetch request is set up incorrectly and without proper care.
     // The ServiceWorkers spec specifics many details to apply here.
 
-    auto fetchHeaders = FetchHeaders::create();
+    auto request = ResourceRequest { m_jobData.scriptURL };
     auto referrer = m_jobData.clientCreationURL.string();
-    auto fetchRequest = FetchRequest::create(context, std::nullopt, WTFMove(fetchHeaders), { m_jobData.scriptURL }, { }, WTFMove(referrer));
-
-    m_fetchLoader->start(context, fetchRequest);
+    m_loader = ThreadableLoader::create(context, *this, WTFMove(request), { }, WTFMove(referrer));
 }
 
-void ServiceWorkerJob::didReceiveResponse(const ResourceResponse& response)
+void ServiceWorkerJob::didReceiveResponse(unsigned long, const ResourceResponse& response)
 {
     ASSERT(currentThread() == m_creationThread);
     ASSERT(!m_completed);
-    ASSERT(m_fetchLoader);
+    ASSERT(m_loader);
     ASSERT(!m_scriptData);
 
     m_lastResponse = response;
@@ -109,11 +105,11 @@ void ServiceWorkerJob::didReceiveResponse(const ResourceResponse& response)
     }
 }
 
-void ServiceWorkerJob::didReceiveData(const char* data, size_t size)
+void ServiceWorkerJob::didReceiveData(const char* data, int size)
 {
     ASSERT(currentThread() == m_creationThread);
     ASSERT(!m_completed);
-    ASSERT(m_fetchLoader);
+    ASSERT(m_loader);
 
     if (!m_scriptData)
         m_scriptData = SharedBuffer::create();
@@ -121,26 +117,26 @@ void ServiceWorkerJob::didReceiveData(const char* data, size_t size)
     m_scriptData->get().append(data, size);
 }
 
-void ServiceWorkerJob::didSucceed()
+void ServiceWorkerJob::didFinishLoading(unsigned long)
 {
     ASSERT(currentThread() == m_creationThread);
     ASSERT(!m_completed);
-    ASSERT(m_fetchLoader);
+    ASSERT(m_loader);
 
     if (!m_scriptData)
         m_scriptData = SharedBuffer::create();
     m_client->jobFinishedLoadingScript(*this, WTFMove(*m_scriptData));
-    m_fetchLoader = nullptr;
+    m_loader = nullptr;
 }
 
 void ServiceWorkerJob::didFail(const ResourceError& error)
 {
     ASSERT(currentThread() == m_creationThread);
     ASSERT(!m_completed);
-    ASSERT(m_fetchLoader);
+    ASSERT(m_loader);
 
     m_client->jobFailedLoadingScript(*this, error);
-    m_fetchLoader = nullptr;
+    m_loader = nullptr;
 }
 
 } // namespace WebCore
index 71f6779..fb5b09c 100644 (file)
 
 #if ENABLE(SERVICE_WORKER)
 
-#include "FetchLoader.h"
-#include "FetchLoaderClient.h"
 #include "ResourceResponse.h"
 #include "ServiceWorkerJobClient.h"
 #include "ServiceWorkerJobData.h"
+#include "ThreadableLoader.h"
+#include "ThreadableLoaderClient.h"
 #include <wtf/RefPtr.h>
 #include <wtf/RunLoop.h>
 #include <wtf/ThreadSafeRefCounted.h>
@@ -45,7 +45,7 @@ class ScriptExecutionContext;
 enum class ServiceWorkerJobType;
 struct ServiceWorkerRegistrationData;
 
-class ServiceWorkerJob : public ThreadSafeRefCounted<ServiceWorkerJob>, public FetchLoaderClient {
+class ServiceWorkerJob : public ThreadSafeRefCounted<ServiceWorkerJob>, public ThreadableLoaderClient {
 public:
     static Ref<ServiceWorkerJob> create(ServiceWorkerJobClient& client, Ref<DeferredPromise>&& promise, ServiceWorkerJobData&& jobData)
     {
@@ -66,10 +66,10 @@ public:
 private:
     ServiceWorkerJob(ServiceWorkerJobClient&, Ref<DeferredPromise>&&, ServiceWorkerJobData&&);
 
-    // FetchLoaderClient
-    void didReceiveResponse(const ResourceResponse&) final;
-    void didReceiveData(const char*, size_t) final;
-    void didSucceed() final;
+    // ThreadableLoaderClient
+    void didReceiveResponse(unsigned long identifier, const ResourceResponse&) final;
+    void didReceiveData(const char* data, int length) final;
+    void didFinishLoading(unsigned long identifier) final;
     void didFail(const ResourceError&) final;
 
     Ref<ServiceWorkerJobClient> m_client;
@@ -79,7 +79,7 @@ private:
     bool m_completed { false };
 
     Ref<RunLoop> m_runLoop { RunLoop::current() };
-    std::unique_ptr<FetchLoader> m_fetchLoader;
+    RefPtr<ThreadableLoader> m_loader;
     ResourceResponse m_lastResponse;
     std::optional<Ref<SharedBuffer>> m_scriptData;
 
index 8d94477..01fccd1 100644 (file)
@@ -31,6 +31,7 @@
 #include "ExceptionData.h"
 #include "ServiceWorkerFetchResult.h"
 #include "ServiceWorkerJobData.h"
+#include "SharedBuffer.h"
 
 namespace WebCore {