Skip to content

Commit e37b044

Browse files
Introduce ServiceWorkerContainer::ensureSWClientConnection()
https://bugs.webkit.org/show_bug.cgi?id=180146 Reviewed by Youenn Fablet. Introduce ServiceWorkerContainer::ensureSWClientConnection() to reduce code duplication. Also use callOnMainThread() in preparation for this getting called from a service worker thread (now that ServiceWorkerContainer is exposed to service workers). This is needed because constructing the SWClientConnection initializes the IPC connection from the WebProcess to the StorageProcess, which involves a synchronous IPC with the UIProcess. Doing a synchronous IPC from a background thread is unsupported. * workers/service/ServiceWorkerContainer.cpp: (WebCore::ServiceWorkerContainer::addRegistration): (WebCore::ServiceWorkerContainer::getRegistration): (WebCore::ServiceWorkerContainer::getRegistrations): (WebCore::ServiceWorkerContainer::ensureSWClientConnection): * workers/service/ServiceWorkerContainer.h: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@225283 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent a69f99f commit e37b044

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

Source/WebCore/ChangeLog

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2017-11-29 Chris Dumez <[email protected]>
2+
3+
Introduce ServiceWorkerContainer::ensureSWClientConnection()
4+
https://bugs.webkit.org/show_bug.cgi?id=180146
5+
6+
Reviewed by Youenn Fablet.
7+
8+
Introduce ServiceWorkerContainer::ensureSWClientConnection() to reduce
9+
code duplication. Also use callOnMainThread() in preparation for this
10+
getting called from a service worker thread (now that ServiceWorkerContainer
11+
is exposed to service workers). This is needed because constructing the
12+
SWClientConnection initializes the IPC connection from the WebProcess to
13+
the StorageProcess, which involves a synchronous IPC with the UIProcess.
14+
Doing a synchronous IPC from a background thread is unsupported.
15+
16+
* workers/service/ServiceWorkerContainer.cpp:
17+
(WebCore::ServiceWorkerContainer::addRegistration):
18+
(WebCore::ServiceWorkerContainer::getRegistration):
19+
(WebCore::ServiceWorkerContainer::getRegistrations):
20+
(WebCore::ServiceWorkerContainer::ensureSWClientConnection):
21+
* workers/service/ServiceWorkerContainer.h:
22+
123
2017-11-29 Antoine Quint <[email protected]>
224

325
[iOS] Media controls should stop updating while media is playing in fullscreen

Source/WebCore/workers/service/ServiceWorkerContainer.cpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ void ServiceWorkerContainer::addRegistration(const String& relativeScriptURL, co
102102
return;
103103
}
104104

105-
if (!m_swConnection)
106-
m_swConnection = &ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(scriptExecutionContext()->sessionID());
107-
108-
ServiceWorkerJobData jobData(m_swConnection->serverConnectionIdentifier());
105+
ServiceWorkerJobData jobData(ensureSWClientConnection().serverConnectionIdentifier());
109106

110107
jobData.scriptURL = context->completeURL(relativeScriptURL);
111108
if (!jobData.scriptURL.isValid()) {
@@ -231,10 +228,7 @@ void ServiceWorkerContainer::getRegistration(const String& clientURL, Ref<Deferr
231228
return;
232229
}
233230

234-
if (!m_swConnection)
235-
m_swConnection = &ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(context->sessionID());
236-
237-
return m_swConnection->matchRegistration(context->topOrigin(), parsedURL, [promise = WTFMove(promise), protectingThis = makePendingActivity(*this), this] (auto&& result) mutable {
231+
return ensureSWClientConnection().matchRegistration(context->topOrigin(), parsedURL, [promise = WTFMove(promise), protectingThis = makePendingActivity(*this), this] (auto&& result) mutable {
238232
if (m_isStopped)
239233
return;
240234

@@ -278,10 +272,7 @@ void ServiceWorkerContainer::getRegistrations(RegistrationsPromise&& promise)
278272
return;
279273
}
280274

281-
if (!m_swConnection)
282-
m_swConnection = &ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(context->sessionID());
283-
284-
return m_swConnection->getRegistrations(context->topOrigin(), context->url(), [this, pendingActivity = makePendingActivity(*this), promise = WTFMove(promise)] (auto&& registrationDatas) mutable {
275+
return ensureSWClientConnection().getRegistrations(context->topOrigin(), context->url(), [this, pendingActivity = makePendingActivity(*this), promise = WTFMove(promise)] (auto&& registrationDatas) mutable {
285276
if (m_isStopped)
286277
return;
287278

@@ -418,6 +409,17 @@ bool ServiceWorkerContainer::canSuspendForDocumentSuspension() const
418409
return !hasPendingActivity();
419410
}
420411

412+
SWClientConnection& ServiceWorkerContainer::ensureSWClientConnection()
413+
{
414+
if (!m_swConnection) {
415+
ASSERT(scriptExecutionContext());
416+
callOnMainThreadAndWait([this, sessionID = scriptExecutionContext()->sessionID()]() {
417+
m_swConnection = &ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(sessionID);
418+
});
419+
}
420+
return *m_swConnection;
421+
}
422+
421423
void ServiceWorkerContainer::addRegistration(ServiceWorkerRegistration& registration)
422424
{
423425
m_swConnection->addServiceWorkerRegistrationInServer(registration.identifier());

Source/WebCore/workers/service/ServiceWorkerContainer.h

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class ServiceWorkerContainer final : public EventTargetWithInlineData, public Ac
9797
void jobDidFinish(ServiceWorkerJob&);
9898

9999
SWServerConnectionIdentifier connectionIdentifier() final;
100+
SWClientConnection& ensureSWClientConnection();
100101

101102
const char* activeDOMObjectName() const final;
102103
bool canSuspendForDocumentSuspension() const final;

0 commit comments

Comments
 (0)