Diff
Modified: trunk/Source/WebCore/ChangeLog (225456 => 225457)
--- trunk/Source/WebCore/ChangeLog 2017-12-03 04:17:12 UTC (rev 225456)
+++ trunk/Source/WebCore/ChangeLog 2017-12-03 05:32:33 UTC (rev 225457)
@@ -1,3 +1,38 @@
+2017-12-02 Youenn Fablet <[email protected]>
+
+ Move registration activation and clearing from SWServerJobQueue to SWServerRegistration
+ https://bugs.webkit.org/show_bug.cgi?id=180325
+
+ Reviewed by Chris Dumez.
+
+ No change of behavior.
+
+ These algorithms fit naturally in SWServerRegistration and will be used as part of clients.claim.
+
+ * workers/service/server/SWServer.cpp:
+ (WebCore::SWServer::clearAll):
+ (WebCore::SWServer::didFinishActivation):
+ * workers/service/server/SWServerJobQueue.cpp:
+ (WebCore::SWServerJobQueue::scriptFetchFinished):
+ (WebCore::SWServerJobQueue::scriptContextFailedToStart):
+ (WebCore::SWServerJobQueue::didFinishInstall):
+ (WebCore::SWServerJobQueue::runUnregisterJob):
+ (WebCore::SWServerJobQueue::tryActivate): Deleted.
+ (WebCore::SWServerJobQueue::activate): Deleted.
+ (WebCore::SWServerJobQueue::didFinishActivation): Deleted.
+ (WebCore::SWServerJobQueue::tryClearRegistration): Deleted.
+ (WebCore::clearRegistrationWorker): Deleted.
+ (WebCore::SWServerJobQueue::clearRegistration): Deleted.
+ * workers/service/server/SWServerJobQueue.h:
+ * workers/service/server/SWServerRegistration.cpp:
+ (WebCore::SWServerRegistration::tryClear):
+ (WebCore::clearRegistrationWorker):
+ (WebCore::SWServerRegistration::clear):
+ (WebCore::SWServerRegistration::tryActivate):
+ (WebCore::SWServerRegistration::activate):
+ (WebCore::SWServerRegistration::didFinishActivation):
+ * workers/service/server/SWServerRegistration.h:
+
2017-12-02 Chris Dumez <[email protected]>
Support container.register() / registration.unregister() / inside service workers
Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (225456 => 225457)
--- trunk/Source/WebCore/workers/service/server/SWServer.cpp 2017-12-03 04:17:12 UTC (rev 225456)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp 2017-12-03 05:32:33 UTC (rev 225457)
@@ -146,7 +146,7 @@
{
m_jobQueues.clear();
while (!m_registrations.isEmpty())
- SWServerJobQueue::clearRegistration(*this, *m_registrations.begin()->value);
+ m_registrations.begin()->value->clear();
ASSERT(m_registrationsByID.isEmpty());
m_originStore->clearAll();
}
@@ -310,7 +310,7 @@
void SWServer::didFinishActivation(SWServerWorker& worker)
{
if (auto* registration = getRegistration(worker.registrationKey()))
- SWServerJobQueue::didFinishActivation(*registration, worker.identifier());
+ registration->didFinishActivation(worker.identifier());
}
// https://w3c.github.io/ServiceWorker/#clients-get
Modified: trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp (225456 => 225457)
--- trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp 2017-12-03 04:17:12 UTC (rev 225456)
+++ trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp 2017-12-03 05:32:33 UTC (rev 225457)
@@ -73,7 +73,7 @@
// If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
if (!newestWorker)
- clearRegistration(m_server, *registration);
+ registration->clear();
// Invoke Finish Job with job and abort these steps.
finishCurrentJob();
@@ -105,7 +105,7 @@
// If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
if (!registration->getNewestWorker())
- clearRegistration(m_server, *registration);
+ registration->clear();
// Invoke Finish Job with job and abort these steps.
finishCurrentJob();
@@ -175,7 +175,8 @@
// If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
if (!registration->getNewestWorker())
- clearRegistration(m_server, *registration);
+ registration->clear();
+
// Invoke Finish Job with job and abort these steps.
finishCurrentJob();
return;
@@ -196,72 +197,9 @@
finishCurrentJob();
// FIXME: Wait for all the tasks queued by Update Worker State invoked in this algorithm have executed.
- tryActivate(m_server, *registration);
+ registration->tryActivate();
}
-// https://w3c.github.io/ServiceWorker/#try-activate-algorithm
-void SWServerJobQueue::tryActivate(SWServer& server, SWServerRegistration& registration)
-{
- // If registration's waiting worker is null, return.
- if (!registration.waitingWorker())
- return;
- // If registration's active worker is not null and registration's active worker's state is activating, return.
- if (registration.activeWorker() && registration.activeWorker()->state() == ServiceWorkerState::Activating)
- return;
-
- // Invoke Activate with registration if either of the following is true:
- // - registration's active worker is null.
- // - The result of running Service Worker Has No Pending Events with registration's active worker is true,
- // and no service worker client is using registration
- // FIXME: Check for the skip waiting flag.
- if (!registration.activeWorker() || !registration.activeWorker()->hasPendingEvents())
- activate(server, registration);
-}
-
-// https://w3c.github.io/ServiceWorker/#activate
-void SWServerJobQueue::activate(SWServer& server, SWServerRegistration& registration)
-{
- // If registration's waiting worker is null, abort these steps.
- if (!registration.waitingWorker())
- return;
-
- // If registration's active worker is not null, then:
- if (auto* activeWorker = registration.activeWorker()) {
- // Terminate registration's active worker.
- activeWorker->terminate();
- // Run the Update Worker State algorithm passing registration's active worker and redundant as the arguments.
- registration.updateWorkerState(*activeWorker, ServiceWorkerState::Redundant);
- }
- // Run the Update Registration State algorithm passing registration, "active" and registration's waiting worker as the arguments.
- registration.updateRegistrationState(ServiceWorkerRegistrationState::Active, registration.waitingWorker());
- // Run the Update Registration State algorithm passing registration, "waiting" and null as the arguments.
- registration.updateRegistrationState(ServiceWorkerRegistrationState::Waiting, nullptr);
- // Run the Update Worker State algorithm passing registration's active worker and activating as the arguments.
- registration.updateWorkerState(*registration.activeWorker(), ServiceWorkerState::Activating);
- // FIXME: For each service worker client client whose creation URL matches registration's scope url...
-
- // For each service worker client client who is using registration:
- // - Set client's active worker to registration's active worker.
- // - Invoke Notify Controller Change algorithm with client as the argument.
- registration.notifyClientsOfControllerChange();
-
- // FIXME: Invoke Run Service Worker algorithm with activeWorker as the argument.
-
- // Queue a task to fire the activate event.
- ASSERT(registration.activeWorker());
- server.fireActivateEvent(*registration.activeWorker());
-}
-
-// https://w3c.github.io/ServiceWorker/#activate (post activate event steps).
-void SWServerJobQueue::didFinishActivation(SWServerRegistration& registration, ServiceWorkerIdentifier serviceWorkerIdentifier)
-{
- if (!registration.activeWorker() || registration.activeWorker()->identifier() != serviceWorkerIdentifier)
- return;
-
- // Run the Update Worker State algorithm passing registration's active worker and activated as the arguments.
- registration.updateWorkerState(*registration.activeWorker(), ServiceWorkerState::Activated);
-}
-
// https://w3c.github.io/ServiceWorker/#run-job
void SWServerJobQueue::runNextJob()
{
@@ -346,48 +284,10 @@
m_server.resolveUnregistrationJob(job, m_registrationKey, true);
// Invoke Try Clear Registration with registration.
- tryClearRegistration(*registration);
+ registration->tryClear();
finishCurrentJob();
}
-// https://w3c.github.io/ServiceWorker/#try-clear-registration-algorithm
-void SWServerJobQueue::tryClearRegistration(SWServerRegistration& registration)
-{
- if (registration.hasClientsUsingRegistration())
- return;
-
- if (registration.installingWorker() && registration.installingWorker()->hasPendingEvents())
- return;
- if (registration.waitingWorker() && registration.waitingWorker()->hasPendingEvents())
- return;
- if (registration.activeWorker() && registration.activeWorker()->hasPendingEvents())
- return;
-
- clearRegistration(m_server, registration);
-}
-
-// https://w3c.github.io/ServiceWorker/#clear-registration
-static void clearRegistrationWorker(SWServerRegistration& registration, SWServerWorker* worker, ServiceWorkerRegistrationState state)
-{
- if (!worker)
- return;
-
- worker->terminate();
- registration.updateWorkerState(*worker, ServiceWorkerState::Redundant);
- registration.updateRegistrationState(state, nullptr);
-}
-
-// https://w3c.github.io/ServiceWorker/#clear-registration
-void SWServerJobQueue::clearRegistration(SWServer& server, SWServerRegistration& registration)
-{
- clearRegistrationWorker(registration, registration.installingWorker(), ServiceWorkerRegistrationState::Installing);
- clearRegistrationWorker(registration, registration.waitingWorker(), ServiceWorkerRegistrationState::Waiting);
- clearRegistrationWorker(registration, registration.activeWorker(), ServiceWorkerRegistrationState::Active);
-
- // Remove scope to registration map[scopeString].
- server.removeRegistration(registration.key());
-}
-
// https://w3c.github.io/ServiceWorker/#update-algorithm
void SWServerJobQueue::runUpdateJob(const ServiceWorkerJobData& job)
{
Modified: trunk/Source/WebCore/workers/service/server/SWServerJobQueue.h (225456 => 225457)
--- trunk/Source/WebCore/workers/service/server/SWServerJobQueue.h 2017-12-03 04:17:12 UTC (rev 225456)
+++ trunk/Source/WebCore/workers/service/server/SWServerJobQueue.h 2017-12-03 05:32:33 UTC (rev 225457)
@@ -52,11 +52,8 @@
void scriptContextFailedToStart(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier, const String& message);
void scriptContextStarted(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier);
void didFinishInstall(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier, bool wasSuccessful);
- static void didFinishActivation(SWServerRegistration&, ServiceWorkerIdentifier);
void didResolveRegistrationPromise();
- static void clearRegistration(SWServer&, SWServerRegistration&);
-
private:
void jobTimerFired();
void runNextJobSynchronously();
@@ -67,10 +64,7 @@
void runUnregisterJob(const ServiceWorkerJobData&);
void runUpdateJob(const ServiceWorkerJobData&);
- void tryClearRegistration(SWServerRegistration&);
void install(SWServerRegistration&, ServiceWorkerIdentifier);
- static void tryActivate(SWServer&, SWServerRegistration&);
- static void activate(SWServer&, SWServerRegistration&);
bool isCurrentlyProcessingJob(const ServiceWorkerJobDataIdentifier&) const;
Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp (225456 => 225457)
--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp 2017-12-03 04:17:12 UTC (rev 225456)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp 2017-12-03 05:32:33 UTC (rev 225457)
@@ -180,6 +180,108 @@
m_clientsUsingRegistration.remove(serverConnectionIdentifier);
}
+// https://w3c.github.io/ServiceWorker/#try-clear-registration-algorithm
+bool SWServerRegistration::tryClear()
+{
+ if (hasClientsUsingRegistration())
+ return false;
+
+ if (installingWorker() && installingWorker()->hasPendingEvents())
+ return false;
+ if (waitingWorker() && waitingWorker()->hasPendingEvents())
+ return false;
+ if (activeWorker() && activeWorker()->hasPendingEvents())
+ return false;
+
+ clear();
+ return true;
+}
+
+// https://w3c.github.io/ServiceWorker/#clear-registration
+static void clearRegistrationWorker(SWServerRegistration& registration, SWServerWorker* worker, ServiceWorkerRegistrationState state)
+{
+ if (!worker)
+ return;
+
+ worker->terminate();
+ registration.updateWorkerState(*worker, ServiceWorkerState::Redundant);
+ registration.updateRegistrationState(state, nullptr);
+}
+
+// https://w3c.github.io/ServiceWorker/#clear-registration
+void SWServerRegistration::clear()
+{
+ clearRegistrationWorker(*this, installingWorker(), ServiceWorkerRegistrationState::Installing);
+ clearRegistrationWorker(*this, waitingWorker(), ServiceWorkerRegistrationState::Waiting);
+ clearRegistrationWorker(*this, activeWorker(), ServiceWorkerRegistrationState::Active);
+
+ // Remove scope to registration map[scopeString].
+ m_server.removeRegistration(key());
+}
+
+// https://w3c.github.io/ServiceWorker/#try-activate-algorithm
+void SWServerRegistration::tryActivate()
+{
+ // If registration's waiting worker is null, return.
+ if (!waitingWorker())
+ return;
+ // If registration's active worker is not null and registration's active worker's state is activating, return.
+ if (activeWorker() && activeWorker()->state() == ServiceWorkerState::Activating)
+ return;
+
+ // Invoke Activate with registration if either of the following is true:
+ // - registration's active worker is null.
+ // - The result of running Service Worker Has No Pending Events with registration's active worker is true,
+ // and no service worker client is using registration
+ // FIXME: Check for the skip waiting flag.
+ if (!activeWorker() || !activeWorker()->hasPendingEvents())
+ activate();
+}
+
+// https://w3c.github.io/ServiceWorker/#activate
+void SWServerRegistration::activate()
+{
+ // If registration's waiting worker is null, abort these steps.
+ if (!waitingWorker())
+ return;
+
+ // If registration's active worker is not null, then:
+ if (auto* worker = activeWorker()) {
+ // Terminate registration's active worker.
+ worker->terminate();
+ // Run the Update Worker State algorithm passing registration's active worker and redundant as the arguments.
+ updateWorkerState(*worker, ServiceWorkerState::Redundant);
+ }
+ // Run the Update Registration State algorithm passing registration, "active" and registration's waiting worker as the arguments.
+ updateRegistrationState(ServiceWorkerRegistrationState::Active, waitingWorker());
+ // Run the Update Registration State algorithm passing registration, "waiting" and null as the arguments.
+ updateRegistrationState(ServiceWorkerRegistrationState::Waiting, nullptr);
+ // Run the Update Worker State algorithm passing registration's active worker and activating as the arguments.
+ updateWorkerState(*activeWorker(), ServiceWorkerState::Activating);
+ // FIXME: For each service worker client client whose creation URL matches registration's scope url...
+
+ // For each service worker client client who is using registration:
+ // - Set client's active worker to registration's active worker.
+ // - Invoke Notify Controller Change algorithm with client as the argument.
+ notifyClientsOfControllerChange();
+
+ // FIXME: Invoke Run Service Worker algorithm with activeWorker as the argument.
+
+ // Queue a task to fire the activate event.
+ ASSERT(activeWorker());
+ m_server.fireActivateEvent(*activeWorker());
+}
+
+// https://w3c.github.io/ServiceWorker/#activate (post activate event steps).
+void SWServerRegistration::didFinishActivation(ServiceWorkerIdentifier serviceWorkerIdentifier)
+{
+ if (!activeWorker() || activeWorker()->identifier() != serviceWorkerIdentifier)
+ return;
+
+ // Run the Update Worker State algorithm passing registration's active worker and activated as the arguments.
+ updateWorkerState(*activeWorker(), ServiceWorkerState::Activated);
+}
+
} // namespace WebCore
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.h (225456 => 225457)
--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.h 2017-12-03 04:17:12 UTC (rev 225456)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.h 2017-12-03 05:32:33 UTC (rev 225457)
@@ -81,9 +81,16 @@
void notifyClientsOfControllerChange();
+ void clear();
+ bool tryClear();
+ void tryActivate();
+ void didFinishActivation(ServiceWorkerIdentifier);
+
private:
void forEachConnection(const WTF::Function<void(SWServer::Connection&)>&);
+ void activate();
+
ServiceWorkerRegistrationIdentifier m_identifier;
ServiceWorkerRegistrationKey m_registrationKey;
ServiceWorkerUpdateViaCache m_updateViaCache;