Changeset 252300 in webkit


Ignore:
Timestamp:
Nov 8, 2019 7:02:59 PM (5 years ago)
Author:
youenn@apple.com
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.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252299 r252300  
     12019-11-08  Youenn Fablet  <youenn@apple.com>
     2
     3        SWServerWorker in redundant state do not need to process messages from the context process
     4        https://bugs.webkit.org/show_bug.cgi?id=204019
     5
     6        Reviewed by Chris Dumez.
     7
     8        When a service worker is marked as redundant in network process, it might still receive some messages like didFinishActivation or didFinishInstall.
     9        In that state, we do not need to process these messages.
     10        Did some refactoring to directly pass the service worker to the job queue.
     11        This makes it clear the registration and service worker are the correct ones.
     12
     13        * workers/service/server/SWServer.cpp:
     14        (WebCore::SWServer::didFinishInstall):
     15        Pass the worker instead of its identifier.
     16        * workers/service/server/SWServerJobQueue.cpp:
     17        (WebCore::SWServerJobQueue::didFinishInstall):
     18        Now that we are given the service worker, get its registration directly.
     19        * workers/service/server/SWServerJobQueue.h:
     20        * workers/service/server/SWServerWorker.cpp:
     21        (WebCore::SWServerWorker::didFinishInstall):
     22        Exit early in redundant state.
     23        (WebCore::SWServerWorker::didFinishActivation):
     24        Exit early in redundant state.
     25
    1262019-11-08  youenn fablet  <youenn@apple.com>
    227
  • trunk/Source/WebCore/workers/service/server/SWServer.cpp

    r251409 r252300  
    446446
    447447    if (auto* jobQueue = m_jobQueues.get(worker.registrationKey()))
    448         jobQueue->didFinishInstall(*jobDataIdentifier, worker.identifier(), wasSuccessful);
     448        jobQueue->didFinishInstall(*jobDataIdentifier, worker, wasSuccessful);
    449449}
    450450
  • trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp

    r251124 r252300  
    178178
    179179// https://w3c.github.io/ServiceWorker/#install
    180 void SWServerJobQueue::didFinishInstall(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, ServiceWorkerIdentifier identifier, bool wasSuccessful)
     180void SWServerJobQueue::didFinishInstall(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerWorker& worker, bool wasSuccessful)
    181181{
    182182    if (!isCurrentlyProcessingJob(jobDataIdentifier))
    183183        return;
    184184
    185     auto* registration = m_server.getRegistration(m_registrationKey);
     185    auto* registration = worker.registration();
    186186    ASSERT(registration);
    187     ASSERT(registration->installingWorker());
    188     ASSERT(registration->installingWorker()->identifier() == identifier);
     187    ASSERT(registration->installingWorker() == &worker);
    189188
    190189    if (!wasSuccessful) {
    191         RefPtr<SWServerWorker> worker = m_server.workerByID(identifier);
    192         RELEASE_ASSERT(worker);
    193 
    194         worker->terminate();
     190        worker.terminate();
    195191        // Run the Update Registration State algorithm passing registration, "installing" and null as the arguments.
    196192        registration->updateRegistrationState(ServiceWorkerRegistrationState::Installing, nullptr);
    197193        // Run the Update Worker State algorithm passing registration's installing worker and redundant as the arguments.
    198         registration->updateWorkerState(*worker, ServiceWorkerState::Redundant);
     194        registration->updateWorkerState(worker, ServiceWorkerState::Redundant);
    199195
    200196        // If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
     
    212208    }
    213209
    214     auto* installing = registration->installingWorker();
    215     ASSERT(installing);
    216 
    217     registration->updateRegistrationState(ServiceWorkerRegistrationState::Waiting, installing);
     210    registration->updateRegistrationState(ServiceWorkerRegistrationState::Waiting, &worker);
    218211    registration->updateRegistrationState(ServiceWorkerRegistrationState::Installing, nullptr);
    219     registration->updateWorkerState(*installing, ServiceWorkerState::Installed);
     212    registration->updateWorkerState(worker, ServiceWorkerState::Installed);
    220213
    221214    finishCurrentJob();
  • trunk/Source/WebCore/workers/service/server/SWServerJobQueue.h

    r228101 r252300  
    3535namespace WebCore {
    3636
     37class SWServerWorker;
     38
    3739class SWServerJobQueue {
    3840    WTF_MAKE_FAST_ALLOCATED;
     
    5254    void scriptContextFailedToStart(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier, const String& message);
    5355    void scriptContextStarted(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier);
    54     void didFinishInstall(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier, bool wasSuccessful);
     56    void didFinishInstall(const ServiceWorkerJobDataIdentifier&, SWServerWorker&, bool wasSuccessful);
    5557    void didResolveRegistrationPromise();
    5658    void cancelJobsFromConnection(SWServerConnectionIdentifier);
  • trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp

    r250195 r252300  
    119119void SWServerWorker::didFinishInstall(const Optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, bool wasSuccessful)
    120120{
    121     ASSERT(m_server);
     121    auto state = this->state();
     122    if (state == ServiceWorkerState::Redundant)
     123        return;
     124
     125    ASSERT(m_server);
     126    RELEASE_ASSERT(state == ServiceWorkerState::Installing);
    122127    if (m_server)
    123128        m_server->didFinishInstall(jobDataIdentifier, *this, wasSuccessful);
     
    126131void SWServerWorker::didFinishActivation()
    127132{
    128     ASSERT(m_server);
     133    auto state = this->state();
     134    if (state == ServiceWorkerState::Redundant)
     135        return;
     136
     137    ASSERT(m_server);
     138    RELEASE_ASSERT(state == ServiceWorkerState::Activating);
    129139    if (m_server)
    130140        m_server->didFinishActivation(*this);
Note: See TracChangeset for help on using the changeset viewer.