Commit b7661721 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

S13nSW: GetControllerServiceWorkerPtr() doesn't ensure the controller is running

The method is similar to EnsureControllerServiceWorker but in some cases we
can't make sure that the controller service worker is running (as existing
comment described). Update the description of the method to state that this
method doesn't guarantee that the controller is running.

The method will be called during navigation when S13nSW is enabled. During
navigation, we need to make sure that the controller is running before
calling this method. Currently we make sure this by calling
ServiceWorkerFetchDispatcher::StartWorker() in the following sequence:

ServiceWorkerControlleeRequestHandler::MaybeCreateLoader()
-> ServiceWorkerURLJobWrapper::ForwardToServiceWorker()
-> ServiceWorkerNavigationLoader::ForwardToServiceWorker()
-> ServiceWorkerFetchDispatcher::Run()
-> ServiceWorkerFetchDispatcher::StartWorker()

After creating a loader, we call GetControllerServiceWorkerPtr() in
ServiceWorkerControlleeReuqestHandler::MaybeCreateSubresourceLoaderParams().

Bug: 797222
Change-Id: If7ef6dbe2e59c15e2f737f16d68f0c851d889556
Reviewed-on: https://chromium-review.googlesource.com/987832Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547634}
parent a5bb8be7
...@@ -319,8 +319,6 @@ ServiceWorkerProviderHost::GetControllerServiceWorkerPtr() { ...@@ -319,8 +319,6 @@ ServiceWorkerProviderHost::GetControllerServiceWorkerPtr() {
ServiceWorkerVersion::FetchHandlerExistence::DOES_NOT_EXIST) { ServiceWorkerVersion::FetchHandlerExistence::DOES_NOT_EXIST) {
return nullptr; return nullptr;
} }
// TODO(bashi): Make sure the worker is running by calling
// controller_->RunAfterStartWorker().
mojom::ControllerServiceWorkerPtr controller_ptr; mojom::ControllerServiceWorkerPtr controller_ptr;
controller_->controller()->Clone(mojo::MakeRequest(&controller_ptr)); controller_->controller()->Clone(mojo::MakeRequest(&controller_ptr));
return controller_ptr; return controller_ptr;
......
...@@ -212,8 +212,8 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -212,8 +212,8 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
} }
// S13nServiceWorker: // S13nServiceWorker:
// For service worker clients. Similar to GetControllerServiceWorker, but this // For service worker clients. Similar to EnsureControllerServiceWorker, but
// returns a bound Mojo ptr which is supposed to be sent to clients. The // this returns a bound Mojo ptr which is supposed to be sent to clients. The
// controller ptr passed to the clients will be used to intercept requests // controller ptr passed to the clients will be used to intercept requests
// from them. // from them.
// It is invalid to call this when controller_ is null. // It is invalid to call this when controller_ is null.
...@@ -229,6 +229,21 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -229,6 +229,21 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// //
// This may return nullptr if the controller service worker does not have a // This may return nullptr if the controller service worker does not have a
// fetch handler, i.e. when the renderer does not need the controller ptr. // fetch handler, i.e. when the renderer does not need the controller ptr.
//
// WARNING:
// Unlike EnsureControllerServiceWorker, this method doesn't guarantee that
// the controller worker is running because this method can be called in some
// situations where the worker isn't running yet. When the returned ptr is
// stored somewhere and intended to use later, clients need to make sure
// that the worker is eventually started to use the ptr.
// Currently all the callsites do this, i.e. they start the worker before
// or after calling this, but there's no mechanism to prevent future breakage.
// TODO(crbug.com/827935): Figure out a way to prevent misuse of this method.
// TODO(crbug.com/827935): Make sure the connection error handler fires in
// ControllerServiceWorkerConnector (so that it can correctly call
// EnsureControllerServiceWorker later) if the worker gets killed before
// events are dispatched.
//
// TODO(kinuko): revisit this if we start to use the ControllerServiceWorker // TODO(kinuko): revisit this if we start to use the ControllerServiceWorker
// for posting messages. // for posting messages.
mojom::ControllerServiceWorkerPtr GetControllerServiceWorkerPtr(); mojom::ControllerServiceWorkerPtr GetControllerServiceWorkerPtr();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment