SWClientConnection should not double hop to fire some events
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Apr 2019 22:55:01 +0000 (22:55 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Apr 2019 22:55:01 +0000 (22:55 +0000)
commit7a965b314f08281825534e720f66e6599297d0b7
tree7b43d7fb93707108e21194a4814b3af605a40c3f
parenta5d6277e2f54eeada3b94adbf2c005cdbb01c46f
SWClientConnection should not double hop to fire some events
https://bugs.webkit.org/show_bug.cgi?id=196735

Reviewed by Alex Christensen.

Source/WebCore:

Some events, like postMessage in service workers is hopping from main thread to service worker thread to dispatch events.
Some other events, like service worker state update, are hopping from main thread to service worker thread, then posting a task to dispatch events.
This may create ordering problems.

To fix the issue, we now hop to the service worker thread and dispatch the events.
In addition, for documents, we post a task and do the whole service worker processing in it.
This ensures that some tests, like whether there is a service worker container,
or creation of a service worker are done consistently.

Covered by unflaked test.

* workers/service/SWClientConnection.cpp:
(WebCore::SWClientConnection::updateRegistrationState):
(WebCore::SWClientConnection::updateWorkerState):
(WebCore::SWClientConnection::fireUpdateFoundEvent):
(WebCore::SWClientConnection::notifyClientsOfControllerChange):
* workers/service/ServiceWorker.cpp:
(WebCore::ServiceWorker::updateState):
* workers/service/ServiceWorker.h:
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::updateRegistrationState):
(WebCore::ServiceWorkerContainer::fireUpdateFoundEvent):
(WebCore::ServiceWorkerContainer::fireControllerChangeEvent):
* workers/service/ServiceWorkerContainer.h:
* workers/service/ServiceWorkerJob.cpp:
(WebCore::ServiceWorkerJob::notifyFinished):
Notify of the script URL in the error message.
This will help diagnose flakiness issues.
* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::fireUpdateFoundEvent):
* workers/service/ServiceWorkerRegistration.h:

Source/WebKit:

Removed unnecessary method.

* WebProcess/Storage/WebSWClientConnection.cpp:
* WebProcess/Storage/WebSWClientConnection.h:

LayoutTests:

* platform/mac-wk2/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244160 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/workers/service/SWClientConnection.cpp
Source/WebCore/workers/service/SWClientConnection.h
Source/WebCore/workers/service/ServiceWorker.cpp
Source/WebCore/workers/service/ServiceWorker.h
Source/WebCore/workers/service/ServiceWorkerContainer.cpp
Source/WebCore/workers/service/ServiceWorkerContainer.h
Source/WebCore/workers/service/ServiceWorkerJob.cpp
Source/WebCore/workers/service/ServiceWorkerRegistration.cpp
Source/WebCore/workers/service/ServiceWorkerRegistration.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp
Source/WebKit/WebProcess/Storage/WebSWClientConnection.h