When managing context startups, make ServiceWorkerJobDataIdentifier's optional.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 23:16:03 +0000 (23:16 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 23:16:03 +0000 (23:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180166

Reviewed by Chris Dumez.

Source/WebCore:

No new tests (No behavior change).

We'll sometimes be starting SW contexts without an associated job, so ServiceWorkerContextData
should not required actually having a job identifier.

* workers/service/ServiceWorkerContextData.h:
(WebCore::ServiceWorkerContextData::decode):

* workers/service/context/SWContextManager.h:

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::scriptContextFailedToStart):
(WebCore::SWServer::scriptContextStarted):
(WebCore::SWServer::didFinishInstall):
* workers/service/server/SWServer.h:

* workers/service/server/SWServerToContextConnection.cpp:
(WebCore::SWServerToContextConnection::scriptContextFailedToStart):
(WebCore::SWServerToContextConnection::scriptContextStarted):
(WebCore::SWServerToContextConnection::didFinishInstall):
* workers/service/server/SWServerToContextConnection.h:

* workers/service/server/SWServerWorker.cpp:
(WebCore::SWServerWorker::scriptContextFailedToStart):
(WebCore::SWServerWorker::scriptContextStarted):
(WebCore::SWServerWorker::didFinishInstall):
* workers/service/server/SWServerWorker.h:

Source/WebKit:

* StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in:

* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::serviceWorkerStartedWithMessage):
(WebKit::WebSWContextManagerConnection::didFinishInstall):
* WebProcess/Storage/WebSWContextManagerConnection.h:

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

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/workers/service/ServiceWorkerContextData.h
Source/WebCore/workers/service/context/SWContextManager.h
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServer.h
Source/WebCore/workers/service/server/SWServerToContextConnection.cpp
Source/WebCore/workers/service/server/SWServerToContextConnection.h
Source/WebCore/workers/service/server/SWServerWorker.cpp
Source/WebCore/workers/service/server/SWServerWorker.h
Source/WebKit/ChangeLog
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h

index 4ba3a2f..34143fe 100644 (file)
@@ -1,3 +1,38 @@
+2017-11-29  Brady Eidson  <beidson@apple.com>
+
+        When managing context startups, make ServiceWorkerJobDataIdentifier's optional.
+        https://bugs.webkit.org/show_bug.cgi?id=180166
+
+        Reviewed by Chris Dumez.
+
+        No new tests (No behavior change).
+
+        We'll sometimes be starting SW contexts without an associated job, so ServiceWorkerContextData
+        should not required actually having a job identifier.
+
+        * workers/service/ServiceWorkerContextData.h:
+        (WebCore::ServiceWorkerContextData::decode):
+
+        * workers/service/context/SWContextManager.h:
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::scriptContextFailedToStart):
+        (WebCore::SWServer::scriptContextStarted):
+        (WebCore::SWServer::didFinishInstall):
+        * workers/service/server/SWServer.h:
+
+        * workers/service/server/SWServerToContextConnection.cpp:
+        (WebCore::SWServerToContextConnection::scriptContextFailedToStart):
+        (WebCore::SWServerToContextConnection::scriptContextStarted):
+        (WebCore::SWServerToContextConnection::didFinishInstall):
+        * workers/service/server/SWServerToContextConnection.h:
+
+        * workers/service/server/SWServerWorker.cpp:
+        (WebCore::SWServerWorker::scriptContextFailedToStart):
+        (WebCore::SWServerWorker::scriptContextStarted):
+        (WebCore::SWServerWorker::didFinishInstall):
+        * workers/service/server/SWServerWorker.h:
+
 2017-11-29  Youenn Fablet  <youenn@apple.com>
 
         Add support for service worker generated redirections
index ee90bf3..8050741 100644 (file)
@@ -36,7 +36,7 @@
 namespace WebCore {
 
 struct ServiceWorkerContextData {
-    ServiceWorkerJobDataIdentifier jobDataIdentifier;
+    std::optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier;
     ServiceWorkerRegistrationData registration;
     ServiceWorkerIdentifier serviceWorkerIdentifier;
     String script;
@@ -58,7 +58,7 @@ void ServiceWorkerContextData::encode(Encoder& encoder) const
 template<class Decoder>
 std::optional<ServiceWorkerContextData> ServiceWorkerContextData::decode(Decoder& decoder)
 {
-    std::optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier;
+    std::optional<std::optional<ServiceWorkerJobDataIdentifier>> jobDataIdentifier;
     decoder >> jobDataIdentifier;
     if (!jobDataIdentifier)
         return std::nullopt;
index 60fff94..2cf8ab3 100644 (file)
@@ -46,8 +46,8 @@ public:
         virtual ~Connection() { }
 
         virtual void postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, Ref<SerializedScriptValue>&& message, ServiceWorkerIdentifier source, const String& sourceOrigin) = 0;
-        virtual void serviceWorkerStartedWithMessage(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier, const String& exceptionMessage) = 0;
-        virtual void didFinishInstall(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier, bool wasSuccessful) = 0;
+        virtual void serviceWorkerStartedWithMessage(std::optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, const String& exceptionMessage) = 0;
+        virtual void didFinishInstall(std::optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, bool wasSuccessful) = 0;
         virtual void didFinishActivation(ServiceWorkerIdentifier) = 0;
         virtual void setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier, bool) = 0;
         virtual void workerTerminated(ServiceWorkerIdentifier) = 0;
index b74fbd2..6d56488 100644 (file)
@@ -266,22 +266,31 @@ void SWServer::scriptFetchFinished(Connection& connection, const ServiceWorkerFe
     jobQueue->scriptFetchFinished(connection, result);
 }
 
-void SWServer::scriptContextFailedToStart(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerWorker& worker, const String& message)
+void SWServer::scriptContextFailedToStart(const std::optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, SWServerWorker& worker, const String& message)
 {
+    if (!jobDataIdentifier)
+        return;
+
     if (auto* jobQueue = m_jobQueues.get(worker.registrationKey()))
-        jobQueue->scriptContextFailedToStart(jobDataIdentifier, worker.identifier(), message);
+        jobQueue->scriptContextFailedToStart(*jobDataIdentifier, worker.identifier(), message);
 }
 
-void SWServer::scriptContextStarted(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerWorker& worker)
+void SWServer::scriptContextStarted(const std::optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, SWServerWorker& worker)
 {
+    if (!jobDataIdentifier)
+        return;
+
     if (auto* jobQueue = m_jobQueues.get(worker.registrationKey()))
-        jobQueue->scriptContextStarted(jobDataIdentifier, worker.identifier());
+        jobQueue->scriptContextStarted(*jobDataIdentifier, worker.identifier());
 }
 
-void SWServer::didFinishInstall(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerWorker& worker, bool wasSuccessful)
+void SWServer::didFinishInstall(const std::optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, SWServerWorker& worker, bool wasSuccessful)
 {
+    if (!jobDataIdentifier)
+        return;
+
     if (auto* jobQueue = m_jobQueues.get(worker.registrationKey()))
-        jobQueue->didFinishInstall(jobDataIdentifier, worker.identifier(), wasSuccessful);
+        jobQueue->didFinishInstall(*jobDataIdentifier, worker.identifier(), wasSuccessful);
 }
 
 void SWServer::didFinishActivation(SWServerWorker& worker)
index 5f3eff5..5f338f6 100644 (file)
@@ -130,9 +130,9 @@ public:
     Connection* getConnection(SWServerConnectionIdentifier identifier) { return m_connections.get(identifier); }
     SWOriginStore& originStore() { return m_originStore; }
 
-    void scriptContextFailedToStart(const ServiceWorkerJobDataIdentifier&, SWServerWorker&, const String& message);
-    void scriptContextStarted(const ServiceWorkerJobDataIdentifier&, SWServerWorker&);
-    void didFinishInstall(const ServiceWorkerJobDataIdentifier&, SWServerWorker&, bool wasSuccessful);
+    void scriptContextFailedToStart(const std::optional<ServiceWorkerJobDataIdentifier>&, SWServerWorker&, const String& message);
+    void scriptContextStarted(const std::optional<ServiceWorkerJobDataIdentifier>&, SWServerWorker&);
+    void didFinishInstall(const std::optional<ServiceWorkerJobDataIdentifier>&, SWServerWorker&, bool wasSuccessful);
     void didFinishActivation(SWServerWorker&);
     void workerContextTerminated(SWServerWorker&);
 
index c3ebee9..be85b39 100644 (file)
@@ -72,19 +72,19 @@ SWServerToContextConnection* SWServerToContextConnection::globalServerToContextC
     return allConnections().begin()->value;
 }
 
-void SWServerToContextConnection::scriptContextFailedToStart(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& message)
+void SWServerToContextConnection::scriptContextFailedToStart(const std::optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& message)
 {
     if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
         worker->scriptContextFailedToStart(jobDataIdentifier, message);
 }
 
-void SWServerToContextConnection::scriptContextStarted(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier)
+void SWServerToContextConnection::scriptContextStarted(const std::optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier)
 {
     if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
         worker->scriptContextStarted(jobDataIdentifier);
 }
     
-void SWServerToContextConnection::didFinishInstall(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful)
+void SWServerToContextConnection::didFinishInstall(const std::optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful)
 {
     if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
         worker->didFinishInstall(jobDataIdentifier, wasSuccessful);
index 7c1844d..4a152f2 100644 (file)
@@ -50,9 +50,9 @@ public:
     virtual void terminateWorker(ServiceWorkerIdentifier) = 0;
 
     // Messages back from the SW host process
-    WEBCORE_EXPORT void scriptContextFailedToStart(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier, const String& message);
-    WEBCORE_EXPORT void scriptContextStarted(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier);
-    WEBCORE_EXPORT void didFinishInstall(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier, bool wasSuccessful);
+    WEBCORE_EXPORT void scriptContextFailedToStart(const std::optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier, const String& message);
+    WEBCORE_EXPORT void scriptContextStarted(const std::optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier);
+    WEBCORE_EXPORT void didFinishInstall(const std::optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier, bool wasSuccessful);
     WEBCORE_EXPORT void didFinishActivation(ServiceWorkerIdentifier);
     WEBCORE_EXPORT void setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier, bool hasPendingEvents);
     WEBCORE_EXPORT void workerTerminated(ServiceWorkerIdentifier);
index 369607c..1f0b1dc 100644 (file)
@@ -65,17 +65,17 @@ void SWServerWorker::terminate()
     m_server.terminateWorker(*this);
 }
 
-void SWServerWorker::scriptContextFailedToStart(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, const String& message)
+void SWServerWorker::scriptContextFailedToStart(const std::optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, const String& message)
 {
     m_server.scriptContextFailedToStart(jobDataIdentifier, *this, message);
 }
 
-void SWServerWorker::scriptContextStarted(const ServiceWorkerJobDataIdentifier& jobDataIdentifier)
+void SWServerWorker::scriptContextStarted(const std::optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier)
 {
     m_server.scriptContextStarted(jobDataIdentifier, *this);
 }
 
-void SWServerWorker::didFinishInstall(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, bool wasSuccessful)
+void SWServerWorker::didFinishInstall(const std::optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, bool wasSuccessful)
 {
     m_server.didFinishInstall(jobDataIdentifier, *this, wasSuccessful);
 }
index 5c260e0..c30d459 100644 (file)
@@ -68,9 +68,9 @@ public:
     bool hasPendingEvents() const { return m_hasPendingEvents; }
     void setHasPendingEvents(bool value) { m_hasPendingEvents = value; }
 
-    void scriptContextFailedToStart(const ServiceWorkerJobDataIdentifier&, const String& message);
-    void scriptContextStarted(const ServiceWorkerJobDataIdentifier&);
-    void didFinishInstall(const ServiceWorkerJobDataIdentifier&, bool wasSuccessful);
+    void scriptContextFailedToStart(const std::optional<ServiceWorkerJobDataIdentifier>&, const String& message);
+    void scriptContextStarted(const std::optional<ServiceWorkerJobDataIdentifier>&);
+    void didFinishInstall(const std::optional<ServiceWorkerJobDataIdentifier>&, bool wasSuccessful);
     void didFinishActivation();
     void contextTerminated();
 
index 06f6230..3269329 100644 (file)
@@ -1,3 +1,17 @@
+2017-11-29  Brady Eidson  <beidson@apple.com>
+
+        When managing context startups, make ServiceWorkerJobDataIdentifier's optional.
+        https://bugs.webkit.org/show_bug.cgi?id=180166
+
+        Reviewed by Chris Dumez.
+
+        * StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in:
+
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+        (WebKit::WebSWContextManagerConnection::serviceWorkerStartedWithMessage):
+        (WebKit::WebSWContextManagerConnection::didFinishInstall):
+        * WebProcess/Storage/WebSWContextManagerConnection.h:
+
 2017-11-29  Youenn Fablet  <youenn@apple.com>
 
         Add support for service worker generated redirections
index 37f112f..8b23478 100644 (file)
@@ -25,9 +25,9 @@
 messages -> WebSWServerToContextConnection {
     # When possible, these messages can be implemented directly by WebCore::SWServerToContextConnection
 
-    ScriptContextFailedToStart(struct WebCore::ServiceWorkerJobDataIdentifier jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, String message);
-    ScriptContextStarted(struct WebCore::ServiceWorkerJobDataIdentifier jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier);
-    DidFinishInstall(struct WebCore::ServiceWorkerJobDataIdentifier jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful);
+    ScriptContextFailedToStart(std::optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, String message);
+    ScriptContextStarted(std::optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier);
+    DidFinishInstall(std::optional<WebCore::ServiceWorkerJobDataIdentifier> jobDataIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful);
     DidFinishActivation(WebCore::ServiceWorkerIdentifier identifier);
     SetServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier identifier, bool hasPendingEvents);
     WorkerTerminated(WebCore::ServiceWorkerIdentifier identifier);
index 3abf89a..c0ceda1 100644 (file)
@@ -124,7 +124,7 @@ void WebSWContextManagerConnection::installServiceWorker(const ServiceWorkerCont
     LOG(ServiceWorker, "Context process PID: %i created worker thread\n", getpid());
 }
 
-void WebSWContextManagerConnection::serviceWorkerStartedWithMessage(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage)
+void WebSWContextManagerConnection::serviceWorkerStartedWithMessage(std::optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage)
 {
     if (exceptionMessage.isEmpty())
         m_connectionToStorageProcess->send(Messages::WebSWServerToContextConnection::ScriptContextStarted(jobDataIdentifier, serviceWorkerIdentifier), 0);
@@ -174,7 +174,7 @@ void WebSWContextManagerConnection::postMessageToServiceWorkerClient(const Servi
     m_connectionToStorageProcess->send(Messages::StorageProcess::PostMessageToServiceWorkerClient(destinationIdentifier, IPC::DataReference { message->data() }, sourceIdentifier, sourceOrigin), 0);
 }
 
-void WebSWContextManagerConnection::didFinishInstall(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful)
+void WebSWContextManagerConnection::didFinishInstall(std::optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful)
 {
     m_connectionToStorageProcess->send(Messages::WebSWServerToContextConnection::DidFinishInstall(jobDataIdentifier, serviceWorkerIdentifier, wasSuccessful), 0);
 }
index d12ff44..c9e65a4 100644 (file)
@@ -57,13 +57,13 @@ private:
 
     // WebCore::SWContextManager::Connection.
     void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, Ref<WebCore::SerializedScriptValue>&& message, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin) final;
-    void didFinishInstall(const WebCore::ServiceWorkerJobDataIdentifier&, WebCore::ServiceWorkerIdentifier, bool wasSuccessful) final;
+    void didFinishInstall(std::optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, bool wasSuccessful) final;
     void didFinishActivation(WebCore::ServiceWorkerIdentifier) final;
     void setServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier, bool) final;
     void workerTerminated(WebCore::ServiceWorkerIdentifier) final;
 
     // IPC messages.
-    void serviceWorkerStartedWithMessage(const WebCore::ServiceWorkerJobDataIdentifier&, WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
+    void serviceWorkerStartedWithMessage(std::optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
     void installServiceWorker(const WebCore::ServiceWorkerContextData&);
     void startFetch(WebCore::SWServerConnectionIdentifier, uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier>, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&);
     void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerClientIdentifier sourceIdentifier, WebCore::ServiceWorkerClientData&& sourceData);