Title: [252300] trunk/Source/WebCore
Revision
252300
Author
[email protected]
Date
2019-11-08 19:02:59 -0800 (Fri, 08 Nov 2019)

Log Message

SWServerWorker in redundant state do not need to process messages from the context process
https://bugs.webkit.org/show_bug.cgi?id=204019

Reviewed by Chris Dumez.

When a service worker is marked as redundant in network process, it might still receive some messages like didFinishActivation or didFinishInstall.
In that state, we do not need to process these messages.
Did some refactoring to directly pass the service worker to the job queue.
This makes it clear the registration and service worker are the correct ones.

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::didFinishInstall):
Pass the worker instead of its identifier.
* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::didFinishInstall):
Now that we are given the service worker, get its registration directly.
* workers/service/server/SWServerJobQueue.h:
* workers/service/server/SWServerWorker.cpp:
(WebCore::SWServerWorker::didFinishInstall):
Exit early in redundant state.
(WebCore::SWServerWorker::didFinishActivation):
Exit early in redundant state.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (252299 => 252300)


--- trunk/Source/WebCore/ChangeLog	2019-11-09 02:44:57 UTC (rev 252299)
+++ trunk/Source/WebCore/ChangeLog	2019-11-09 03:02:59 UTC (rev 252300)
@@ -1,3 +1,28 @@
+2019-11-08  Youenn Fablet  <[email protected]>
+
+        SWServerWorker in redundant state do not need to process messages from the context process
+        https://bugs.webkit.org/show_bug.cgi?id=204019
+
+        Reviewed by Chris Dumez.
+
+        When a service worker is marked as redundant in network process, it might still receive some messages like didFinishActivation or didFinishInstall.
+        In that state, we do not need to process these messages.
+        Did some refactoring to directly pass the service worker to the job queue.
+        This makes it clear the registration and service worker are the correct ones.
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::didFinishInstall):
+        Pass the worker instead of its identifier.
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::didFinishInstall):
+        Now that we are given the service worker, get its registration directly.
+        * workers/service/server/SWServerJobQueue.h:
+        * workers/service/server/SWServerWorker.cpp:
+        (WebCore::SWServerWorker::didFinishInstall):
+        Exit early in redundant state.
+        (WebCore::SWServerWorker::didFinishActivation):
+        Exit early in redundant state.
+
 2019-11-08  youenn fablet  <[email protected]>
 
         XMLHttpRequestUpload should be exposed in dedicated workers

Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (252299 => 252300)


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2019-11-09 02:44:57 UTC (rev 252299)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2019-11-09 03:02:59 UTC (rev 252300)
@@ -445,7 +445,7 @@
         RELEASE_LOG_ERROR(ServiceWorker, "%p - SWServer::didFinishInstall: Failed SW install for job %s", this, jobDataIdentifier->loggingString().utf8().data());
 
     if (auto* jobQueue = m_jobQueues.get(worker.registrationKey()))
-        jobQueue->didFinishInstall(*jobDataIdentifier, worker.identifier(), wasSuccessful);
+        jobQueue->didFinishInstall(*jobDataIdentifier, worker, wasSuccessful);
 }
 
 void SWServer::didFinishActivation(SWServerWorker& worker)

Modified: trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp (252299 => 252300)


--- trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp	2019-11-09 02:44:57 UTC (rev 252299)
+++ trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp	2019-11-09 03:02:59 UTC (rev 252300)
@@ -177,25 +177,21 @@
 }
 
 // https://w3c.github.io/ServiceWorker/#install
-void SWServerJobQueue::didFinishInstall(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, ServiceWorkerIdentifier identifier, bool wasSuccessful)
+void SWServerJobQueue::didFinishInstall(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerWorker& worker, bool wasSuccessful)
 {
     if (!isCurrentlyProcessingJob(jobDataIdentifier))
         return;
 
-    auto* registration = m_server.getRegistration(m_registrationKey);
+    auto* registration = worker.registration();
     ASSERT(registration);
-    ASSERT(registration->installingWorker());
-    ASSERT(registration->installingWorker()->identifier() == identifier);
+    ASSERT(registration->installingWorker() == &worker);
 
     if (!wasSuccessful) {
-        RefPtr<SWServerWorker> worker = m_server.workerByID(identifier);
-        RELEASE_ASSERT(worker);
-
-        worker->terminate();
+        worker.terminate();
         // Run the Update Registration State algorithm passing registration, "installing" and null as the arguments.
         registration->updateRegistrationState(ServiceWorkerRegistrationState::Installing, nullptr);
         // Run the Update Worker State algorithm passing registration's installing worker and redundant as the arguments.
-        registration->updateWorkerState(*worker, ServiceWorkerState::Redundant);
+        registration->updateWorkerState(worker, ServiceWorkerState::Redundant);
 
         // If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
         if (!registration->getNewestWorker())
@@ -211,12 +207,9 @@
         registration->updateWorkerState(*waitingWorker, ServiceWorkerState::Redundant);
     }
 
-    auto* installing = registration->installingWorker();
-    ASSERT(installing);
-
-    registration->updateRegistrationState(ServiceWorkerRegistrationState::Waiting, installing);
+    registration->updateRegistrationState(ServiceWorkerRegistrationState::Waiting, &worker);
     registration->updateRegistrationState(ServiceWorkerRegistrationState::Installing, nullptr);
-    registration->updateWorkerState(*installing, ServiceWorkerState::Installed);
+    registration->updateWorkerState(worker, ServiceWorkerState::Installed);
 
     finishCurrentJob();
 

Modified: trunk/Source/WebCore/workers/service/server/SWServerJobQueue.h (252299 => 252300)


--- trunk/Source/WebCore/workers/service/server/SWServerJobQueue.h	2019-11-09 02:44:57 UTC (rev 252299)
+++ trunk/Source/WebCore/workers/service/server/SWServerJobQueue.h	2019-11-09 03:02:59 UTC (rev 252300)
@@ -34,6 +34,8 @@
 
 namespace WebCore {
 
+class SWServerWorker;
+
 class SWServerJobQueue {
     WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -51,7 +53,7 @@
     void scriptFetchFinished(SWServer::Connection&, const ServiceWorkerFetchResult&);
     void scriptContextFailedToStart(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier, const String& message);
     void scriptContextStarted(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier);
-    void didFinishInstall(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier, bool wasSuccessful);
+    void didFinishInstall(const ServiceWorkerJobDataIdentifier&, SWServerWorker&, bool wasSuccessful);
     void didResolveRegistrationPromise();
     void cancelJobsFromConnection(SWServerConnectionIdentifier);
     void cancelJobsFromServiceWorker(ServiceWorkerIdentifier);

Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp (252299 => 252300)


--- trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp	2019-11-09 02:44:57 UTC (rev 252299)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp	2019-11-09 03:02:59 UTC (rev 252300)
@@ -118,7 +118,12 @@
 
 void SWServerWorker::didFinishInstall(const Optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, bool wasSuccessful)
 {
+    auto state = this->state();
+    if (state == ServiceWorkerState::Redundant)
+        return;
+
     ASSERT(m_server);
+    RELEASE_ASSERT(state == ServiceWorkerState::Installing);
     if (m_server)
         m_server->didFinishInstall(jobDataIdentifier, *this, wasSuccessful);
 }
@@ -125,7 +130,12 @@
 
 void SWServerWorker::didFinishActivation()
 {
+    auto state = this->state();
+    if (state == ServiceWorkerState::Redundant)
+        return;
+
     ASSERT(m_server);
+    RELEASE_ASSERT(state == ServiceWorkerState::Activating);
     if (m_server)
         m_server->didFinishActivation(*this);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to