Commit 44a78b2c authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Simplify WorkerFetchContext's controller state.

It was using two data members to determine if there was a controller.
It only needs one.

Minor cleanup for the linked bug.

Bug: 850839
Change-Id: I1d816453047721d79503d47defc8f8cb3e25c7d9
Reviewed-on: https://chromium-review.googlesource.com/1103981
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarTsuyoshi Horo <horo@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567976}
parent 7b7f92c0
......@@ -58,17 +58,14 @@ struct ServiceWorkerProviderHostInfo {
// ServiceWorkerWorkerClient represents a service worker client that is a worker
// (i.e., a shared worker or dedicated worker). We use this interface to let the
// WorkerFetchContextImpl in the worker thread know about the change of
// controlling service worker by calling SetControllerServiceWorker() from the
// controlling service worker by calling OnControllerChanged() from the
// ServiceWorkerProviderContext in the main thread of the renderer process.
//
// TODO(horo): We should implement ServiceWorkerProvider in the worker thread
// instead of using this interface to support WorkerNavigator.serviceWorker
// when we can make the worker thread totally independent from the main thread.
// Currently we handle synchronous resource loading such as importScripts() and
// synchronous XHR in the main thread. So we need to know whether the worker is
// controlled by a service worker or not both in the main thread and in the
// worker thread.
// instead of using this interface to support WorkerNavigator.serviceWorker.
interface ServiceWorkerWorkerClient {
// Called when the worker is controlled by a new service worker.
SetControllerServiceWorker(int64 controller_version_id);
// Called when the worker is controlled by a new service worker. This is only
// used to let the worker know that we now have a service worker (while there
// may or may not have been one previously), but not the other way around.
OnControllerChanged();
};
......@@ -302,7 +302,7 @@ void ServiceWorkerProviderContext::SetController(
for (const auto& worker : state->worker_clients) {
// This is a Mojo interface call to the (dedicated or shared) worker
// thread.
worker->SetControllerServiceWorker(state->controller->version_id);
worker->OnControllerChanged();
}
}
for (blink::mojom::WebFeature feature : used_features)
......
......@@ -260,9 +260,7 @@ void WorkerFetchContextImpl::WillSendRequest(blink::WebURLRequest& request) {
}
bool WorkerFetchContextImpl::IsControlledByServiceWorker() const {
return is_controlled_by_service_worker_ ||
(controller_version_id_ !=
blink::mojom::kInvalidServiceWorkerVersionId);
return is_controlled_by_service_worker_;
}
void WorkerFetchContextImpl::SetIsOnSubframe(bool is_on_sub_frame) {
......@@ -351,9 +349,11 @@ int WorkerFetchContextImpl::ApplicationCacheHostID() const {
return appcache_host_id_;
}
void WorkerFetchContextImpl::SetControllerServiceWorker(
int64_t controller_version_id) {
controller_version_id_ = controller_version_id;
void WorkerFetchContextImpl::OnControllerChanged() {
// This function is called if we transition from (no controller) to
// (controller), or if the controller changed.
set_is_controlled_by_service_worker(true);
if (ServiceWorkerUtils::IsServicificationEnabled())
ResetServiceWorkerURLLoaderFactory();
}
......
......@@ -93,7 +93,7 @@ class CONTENT_EXPORT WorkerFetchContextImpl
CreateWebSocketHandshakeThrottle() override;
// mojom::ServiceWorkerWorkerClient implementation:
void SetControllerServiceWorker(int64_t controller_version_id) override;
void OnControllerChanged() override;
// Sets the fetch context status copied from the frame; the parent frame for a
// dedicated worker, the main frame of the shadow page for a shared worker.
......@@ -165,10 +165,6 @@ class CONTENT_EXPORT WorkerFetchContextImpl
scoped_refptr<base::RefCountedData<blink::mojom::BlobRegistryPtr>>
blob_registry_;
// Updated when mojom::ServiceWorkerWorkerClient::SetControllerServiceWorker()
// is called from the browser process via mojo IPC.
int controller_version_id_ = blink::mojom::kInvalidServiceWorkerVersionId;
scoped_refptr<ThreadSafeSender> thread_safe_sender_;
std::unique_ptr<blink::WebDocumentSubresourceFilter::Builder>
subresource_filter_builder_;
......
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