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 { ...@@ -58,17 +58,14 @@ struct ServiceWorkerProviderHostInfo {
// ServiceWorkerWorkerClient represents a service worker client that is a worker // 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 // (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 // 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. // ServiceWorkerProviderContext in the main thread of the renderer process.
// //
// TODO(horo): We should implement ServiceWorkerProvider in the worker thread // TODO(horo): We should implement ServiceWorkerProvider in the worker thread
// instead of using this interface to support WorkerNavigator.serviceWorker // 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.
interface ServiceWorkerWorkerClient { interface ServiceWorkerWorkerClient {
// Called when the worker is controlled by a new service worker. // Called when the worker is controlled by a new service worker. This is only
SetControllerServiceWorker(int64 controller_version_id); // 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( ...@@ -302,7 +302,7 @@ void ServiceWorkerProviderContext::SetController(
for (const auto& worker : state->worker_clients) { for (const auto& worker : state->worker_clients) {
// This is a Mojo interface call to the (dedicated or shared) worker // This is a Mojo interface call to the (dedicated or shared) worker
// thread. // thread.
worker->SetControllerServiceWorker(state->controller->version_id); worker->OnControllerChanged();
} }
} }
for (blink::mojom::WebFeature feature : used_features) for (blink::mojom::WebFeature feature : used_features)
......
...@@ -260,9 +260,7 @@ void WorkerFetchContextImpl::WillSendRequest(blink::WebURLRequest& request) { ...@@ -260,9 +260,7 @@ void WorkerFetchContextImpl::WillSendRequest(blink::WebURLRequest& request) {
} }
bool WorkerFetchContextImpl::IsControlledByServiceWorker() const { bool WorkerFetchContextImpl::IsControlledByServiceWorker() const {
return is_controlled_by_service_worker_ || return is_controlled_by_service_worker_;
(controller_version_id_ !=
blink::mojom::kInvalidServiceWorkerVersionId);
} }
void WorkerFetchContextImpl::SetIsOnSubframe(bool is_on_sub_frame) { void WorkerFetchContextImpl::SetIsOnSubframe(bool is_on_sub_frame) {
...@@ -351,9 +349,11 @@ int WorkerFetchContextImpl::ApplicationCacheHostID() const { ...@@ -351,9 +349,11 @@ int WorkerFetchContextImpl::ApplicationCacheHostID() const {
return appcache_host_id_; return appcache_host_id_;
} }
void WorkerFetchContextImpl::SetControllerServiceWorker( void WorkerFetchContextImpl::OnControllerChanged() {
int64_t controller_version_id) { // This function is called if we transition from (no controller) to
controller_version_id_ = controller_version_id; // (controller), or if the controller changed.
set_is_controlled_by_service_worker(true);
if (ServiceWorkerUtils::IsServicificationEnabled()) if (ServiceWorkerUtils::IsServicificationEnabled())
ResetServiceWorkerURLLoaderFactory(); ResetServiceWorkerURLLoaderFactory();
} }
......
...@@ -93,7 +93,7 @@ class CONTENT_EXPORT WorkerFetchContextImpl ...@@ -93,7 +93,7 @@ class CONTENT_EXPORT WorkerFetchContextImpl
CreateWebSocketHandshakeThrottle() override; CreateWebSocketHandshakeThrottle() override;
// mojom::ServiceWorkerWorkerClient implementation: // 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 // 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. // dedicated worker, the main frame of the shadow page for a shared worker.
...@@ -165,10 +165,6 @@ class CONTENT_EXPORT WorkerFetchContextImpl ...@@ -165,10 +165,6 @@ class CONTENT_EXPORT WorkerFetchContextImpl
scoped_refptr<base::RefCountedData<blink::mojom::BlobRegistryPtr>> scoped_refptr<base::RefCountedData<blink::mojom::BlobRegistryPtr>>
blob_registry_; 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_; scoped_refptr<ThreadSafeSender> thread_safe_sender_;
std::unique_ptr<blink::WebDocumentSubresourceFilter::Builder> std::unique_ptr<blink::WebDocumentSubresourceFilter::Builder>
subresource_filter_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