Commit b1cf19a0 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Remove ServiceWorkerMainResourceHandleCore.

Now that the core thread is the UI thread, it's not needed.

Bug: 1138155
Change-Id: Iaf115e152c403650b3fce99a77c0673d1cdfed37
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536575
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828570}
parent a15346bc
...@@ -1624,8 +1624,6 @@ source_set("browser") { ...@@ -1624,8 +1624,6 @@ source_set("browser") {
"service_worker/service_worker_loader_helpers.h", "service_worker/service_worker_loader_helpers.h",
"service_worker/service_worker_main_resource_handle.cc", "service_worker/service_worker_main_resource_handle.cc",
"service_worker/service_worker_main_resource_handle.h", "service_worker/service_worker_main_resource_handle.h",
"service_worker/service_worker_main_resource_handle_core.cc",
"service_worker/service_worker_main_resource_handle_core.h",
"service_worker/service_worker_main_resource_loader.cc", "service_worker/service_worker_main_resource_loader.cc",
"service_worker/service_worker_main_resource_loader.h", "service_worker/service_worker_main_resource_loader.h",
"service_worker/service_worker_main_resource_loader_interceptor.cc", "service_worker/service_worker_main_resource_loader_interceptor.cc",
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "content/browser/renderer_host/navigation_request_info.h" #include "content/browser/renderer_host/navigation_request_info.h"
#include "content/browser/service_worker/service_worker_container_host.h" #include "content/browser/service_worker/service_worker_container_host.h"
#include "content/browser/service_worker/service_worker_main_resource_handle.h" #include "content/browser/service_worker/service_worker_main_resource_handle.h"
#include "content/browser/service_worker/service_worker_main_resource_handle_core.h"
#include "content/browser/service_worker/service_worker_main_resource_loader_interceptor.h" #include "content/browser/service_worker/service_worker_main_resource_loader_interceptor.h"
#include "content/browser/storage_partition_impl.h" #include "content/browser/storage_partition_impl.h"
#include "content/browser/url_loader_factory_getter.h" #include "content/browser/url_loader_factory_getter.h"
...@@ -978,23 +977,14 @@ bool NavigationURLLoaderImpl::MaybeCreateLoaderForResponse( ...@@ -978,23 +977,14 @@ bool NavigationURLLoaderImpl::MaybeCreateLoaderForResponse(
// TODO(crbug/898733): Support SignedExchange loading and Service // TODO(crbug/898733): Support SignedExchange loading and Service
// Worker integration. // Worker integration.
if (service_worker_handle_) { if (service_worker_handle_) {
RunOrPostTaskOnThread( base::WeakPtr<ServiceWorkerContainerHost> container_host =
FROM_HERE, ServiceWorkerContext::GetCoreThreadId(), service_worker_handle_->container_host();
base::BindOnce( if (container_host) {
[](ServiceWorkerMainResourceHandleCore* core) { container_host->SetControllerRegistration(
base::WeakPtr<ServiceWorkerContainerHost> container_host = nullptr, false /* notify_controllerchange */);
core->container_host(); container_host->UpdateUrls(GURL(), net::SiteForCookies(),
if (container_host) { base::nullopt);
container_host->SetControllerRegistration( }
nullptr, false /* notify_controllerchange */);
container_host->UpdateUrls(GURL(), net::SiteForCookies(),
base::nullopt);
}
},
// Unretained() is safe because the handle owns the core,
// and core gets deleted on the core thread in a task that
// must occur after this task.
base::Unretained(service_worker_handle_->core())));
} }
} }
return true; return true;
......
...@@ -378,7 +378,7 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper ...@@ -378,7 +378,7 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
friend class FakeServiceWorkerContextWrapper; friend class FakeServiceWorkerContextWrapper;
friend class ServiceWorkerClientsApiBrowserTest; friend class ServiceWorkerClientsApiBrowserTest;
friend class ServiceWorkerInternalsUI; friend class ServiceWorkerInternalsUI;
friend class ServiceWorkerMainResourceHandleCore; friend class ServiceWorkerMainResourceHandle;
friend class ServiceWorkerProcessManager; friend class ServiceWorkerProcessManager;
friend class ServiceWorkerVersionBrowserTest; friend class ServiceWorkerVersionBrowserTest;
friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "content/browser/service_worker/service_worker_container_host.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_main_resource_handle_core.h"
#include "content/common/service_worker/service_worker_utils.h" #include "content/common/service_worker/service_worker_utils.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -18,21 +18,14 @@ ...@@ -18,21 +18,14 @@
namespace content { namespace content {
ServiceWorkerMainResourceHandle::ServiceWorkerMainResourceHandle( ServiceWorkerMainResourceHandle::ServiceWorkerMainResourceHandle(
ServiceWorkerContextWrapper* context_wrapper, scoped_refptr<ServiceWorkerContextWrapper> context_wrapper,
ServiceWorkerAccessedCallback on_service_worker_accessed) ServiceWorkerAccessedCallback on_service_worker_accessed)
: context_wrapper_(context_wrapper) { : service_worker_accessed_callback_(std::move(on_service_worker_accessed)),
context_wrapper_(std::move(context_wrapper)) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
core_ = new ServiceWorkerMainResourceHandleCore(
weak_factory_.GetWeakPtr(), context_wrapper,
std::move(on_service_worker_accessed));
} }
ServiceWorkerMainResourceHandle::~ServiceWorkerMainResourceHandle() { ServiceWorkerMainResourceHandle::~ServiceWorkerMainResourceHandle() = default;
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Delete the ServiceWorkerMainResourceHandleCore on the core thread.
BrowserThread::DeleteSoon(ServiceWorkerContext::GetCoreThreadId(), FROM_HERE,
core_);
}
void ServiceWorkerMainResourceHandle::OnCreatedContainerHost( void ServiceWorkerMainResourceHandle::OnCreatedContainerHost(
blink::mojom::ServiceWorkerContainerInfoForClientPtr container_info) { blink::mojom::ServiceWorkerContainerInfoForClientPtr container_info) {
...@@ -55,34 +48,29 @@ void ServiceWorkerMainResourceHandle::OnBeginNavigationCommit( ...@@ -55,34 +48,29 @@ void ServiceWorkerMainResourceHandle::OnBeginNavigationCommit(
// We may have failed to pre-create the container host. // We may have failed to pre-create the container host.
if (!container_info_) if (!container_info_)
return; return;
ServiceWorkerContextWrapper::RunOrPostTaskOnCoreThread(
FROM_HERE,
base::BindOnce(
&ServiceWorkerMainResourceHandleCore::OnBeginNavigationCommit,
base::Unretained(core_), render_process_id, render_frame_id,
cross_origin_embedder_policy, std::move(coep_reporter),
document_ukm_source_id));
*out_container_info = std::move(container_info_); *out_container_info = std::move(container_info_);
if (container_host_) {
container_host_->OnBeginNavigationCommit(
render_process_id, render_frame_id, cross_origin_embedder_policy,
std::move(coep_reporter), document_ukm_source_id);
}
} }
void ServiceWorkerMainResourceHandle::OnEndNavigationCommit() { void ServiceWorkerMainResourceHandle::OnEndNavigationCommit() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
ServiceWorkerContextWrapper::RunOrPostTaskOnCoreThread( if (container_host_)
FROM_HERE, container_host_->OnEndNavigationCommit();
base::BindOnce(
&ServiceWorkerMainResourceHandleCore::OnEndNavigationCommit,
base::Unretained(core_)));
} }
void ServiceWorkerMainResourceHandle::OnBeginWorkerCommit( void ServiceWorkerMainResourceHandle::OnBeginWorkerCommit(
const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy, const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy,
ukm::SourceId worker_ukm_source_id) { ukm::SourceId worker_ukm_source_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
ServiceWorkerContextWrapper::RunOrPostTaskOnCoreThread( if (container_host_) {
FROM_HERE, container_host_->CompleteWebWorkerPreparation(cross_origin_embedder_policy,
base::BindOnce(&ServiceWorkerMainResourceHandleCore::OnBeginWorkerCommit, worker_ukm_source_id);
base::Unretained(core_), cross_origin_embedder_policy, }
worker_ukm_source_id));
} }
} // namespace content } // namespace content
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "content/browser/service_worker/service_worker_accessed_callback.h" #include "content/browser/service_worker/service_worker_accessed_callback.h"
#include "content/browser/service_worker/service_worker_main_resource_handle_core.h" #include "content/browser/service_worker/service_worker_container_host.h"
#include "content/browser/service_worker/service_worker_controllee_request_handler.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "services/metrics/public/cpp/ukm_source_id.h" #include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/network/public/mojom/network_context.mojom.h" #include "services/network/public/mojom/network_context.mojom.h"
...@@ -28,42 +29,31 @@ namespace content { ...@@ -28,42 +29,31 @@ namespace content {
class ServiceWorkerContextWrapper; class ServiceWorkerContextWrapper;
// This class is used to manage the lifetime of ServiceWorkerContainerHosts // This class is used to manage the lifetime of ServiceWorkerContainerHosts
// created for main resource requests (navigations and web workers). This is a // created for main resource requests (navigations and web workers).
// UI thread class, with a pendant class on the core thread, the
// ServiceWorkerMainResourceHandleCore.
// //
// The lifetime of the ServiceWorkerMainResourceHandle, the // The lifetime of the ServiceWorkerMainResourceHandle and the
// ServiceWorkerMainResourceHandleCore and the ServiceWorkerContainerHost are // ServiceWorkerContainerHost are the following:
// the following: // 1) We create a ServiceWorkerMainResourceHandle without populating the
// 1) We create a ServiceWorkerMainResourceHandle on the UI thread without // member service worker container info.
// populating the member service worker container info. This also leads to the
// creation of a ServiceWorkerMainResourceHandleCore.
// //
// 2) When the navigation request is sent to the core thread, we include a // 2) If we pre-create a ServiceWorkerContainerHost for this navigation, it
// pointer to the ServiceWorkerMainResourceHandleCore.
//
// 3) If we pre-create a ServiceWorkerContainerHost for this navigation, it
// is added to ServiceWorkerContextCore and its container info is passed to // is added to ServiceWorkerContextCore and its container info is passed to
// ServiceWorkerMainResourceHandle on the UI thread via // ServiceWorkerMainResourceHandle::OnCreatedContainerHost().
// ServiceWorkerMainResourceHandleCore. See
// ServiceWorkerMainResourceHandleCore::OnCreatedContainerHost() and
// ServiceWorkerMainResourceHandle::OnCreatedContainerHost() for details.
// //
// 4) When the navigation is ready to commit, the NavigationRequest will // 3) When the navigation is ready to commit, the NavigationRequest will
// call ServiceWorkerMainResourceHandle::OnBeginNavigationCommit() to // call ServiceWorkerMainResourceHandle::OnBeginNavigationCommit() to
// - complete the initialization for the ServiceWorkerContainerHost. // - complete the initialization for the ServiceWorkerContainerHost.
// - take out the container info to be sent as part of navigation commit // - take out the container info to be sent as part of navigation commit
// IPC. // IPC.
// //
// 5) When the navigation finishes, the ServiceWorkerMainResourceHandle is // 4) When the navigation finishes, the ServiceWorkerMainResourceHandle is
// destroyed. The destructor of the ServiceWorkerMainResourceHandle destroys // destroyed. The destructor of the ServiceWorkerMainResourceHandle destroys
// the container info which in turn leads to the destruction of an unclaimed // the container info which in turn leads to the destruction of an unclaimed
// ServiceWorkerContainerHost, and posts a task to destroy the // ServiceWorkerContainerHost.
// ServiceWorkerMainResourceHandleCore on the core thread.
class CONTENT_EXPORT ServiceWorkerMainResourceHandle { class CONTENT_EXPORT ServiceWorkerMainResourceHandle {
public: public:
ServiceWorkerMainResourceHandle( ServiceWorkerMainResourceHandle(
ServiceWorkerContextWrapper* context_wrapper, scoped_refptr<ServiceWorkerContextWrapper> context_wrapper,
ServiceWorkerAccessedCallback on_service_worker_accessed); ServiceWorkerAccessedCallback on_service_worker_accessed);
~ServiceWorkerMainResourceHandle(); ~ServiceWorkerMainResourceHandle();
...@@ -106,7 +96,37 @@ class CONTENT_EXPORT ServiceWorkerMainResourceHandle { ...@@ -106,7 +96,37 @@ class CONTENT_EXPORT ServiceWorkerMainResourceHandle {
bool has_container_info() const { return !!container_info_; } bool has_container_info() const { return !!container_info_; }
ServiceWorkerMainResourceHandleCore* core() { return core_; } void set_container_host(
base::WeakPtr<ServiceWorkerContainerHost> container_host) {
container_host_ = std::move(container_host);
}
base::WeakPtr<ServiceWorkerContainerHost> container_host() {
return container_host_;
}
void set_parent_container_host(
base::WeakPtr<ServiceWorkerContainerHost> container_host) {
DCHECK(!parent_container_host_);
parent_container_host_ = std::move(container_host);
}
base::WeakPtr<ServiceWorkerContainerHost> parent_container_host() {
return parent_container_host_;
}
void set_interceptor(
std::unique_ptr<ServiceWorkerControlleeRequestHandler> interceptor) {
interceptor_ = std::move(interceptor);
}
ServiceWorkerControlleeRequestHandler* interceptor() {
return interceptor_.get();
}
const ServiceWorkerAccessedCallback& service_worker_accessed_callback() {
return service_worker_accessed_callback_;
}
ServiceWorkerContextWrapper* context_wrapper() { ServiceWorkerContextWrapper* context_wrapper() {
return context_wrapper_.get(); return context_wrapper_.get();
...@@ -119,9 +139,19 @@ class CONTENT_EXPORT ServiceWorkerMainResourceHandle { ...@@ -119,9 +139,19 @@ class CONTENT_EXPORT ServiceWorkerMainResourceHandle {
private: private:
blink::mojom::ServiceWorkerContainerInfoForClientPtr container_info_; blink::mojom::ServiceWorkerContainerInfoForClientPtr container_info_;
ServiceWorkerMainResourceHandleCore* core_; base::WeakPtr<ServiceWorkerContainerHost> container_host_;
// Only used for workers with a blob URL.
base::WeakPtr<ServiceWorkerContainerHost> parent_container_host_;
std::unique_ptr<ServiceWorkerControlleeRequestHandler> interceptor_;
ServiceWorkerAccessedCallback service_worker_accessed_callback_;
scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_; scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
base::WeakPtrFactory<ServiceWorkerMainResourceHandle> weak_factory_{this}; base::WeakPtrFactory<ServiceWorkerMainResourceHandle> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerMainResourceHandle); DISALLOW_COPY_AND_ASSIGN(ServiceWorkerMainResourceHandle);
}; };
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/service_worker/service_worker_main_resource_handle_core.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_main_resource_handle.h"
#include "content/common/service_worker/service_worker_utils.h"
namespace content {
ServiceWorkerMainResourceHandleCore::ServiceWorkerMainResourceHandleCore(
base::WeakPtr<ServiceWorkerMainResourceHandle> ui_handle,
ServiceWorkerContextWrapper* context_wrapper,
ServiceWorkerAccessedCallback service_worker_accessed_callback)
: context_wrapper_(context_wrapper),
ui_handle_(ui_handle),
service_worker_accessed_callback_(
std::move(service_worker_accessed_callback)) {
// The ServiceWorkerMainResourceHandleCore is created on the UI thread but
// should only be accessed from the core thread afterwards.
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
ServiceWorkerMainResourceHandleCore::~ServiceWorkerMainResourceHandleCore() {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
}
void ServiceWorkerMainResourceHandleCore::OnBeginNavigationCommit(
int render_process_id,
int render_frame_id,
const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy,
mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter>
coep_reporter,
ukm::SourceId document_ukm_source_id) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
if (container_host_) {
container_host_->OnBeginNavigationCommit(
render_process_id, render_frame_id, cross_origin_embedder_policy,
std::move(coep_reporter), document_ukm_source_id);
}
}
void ServiceWorkerMainResourceHandleCore::OnEndNavigationCommit() {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
if (container_host_)
container_host_->OnEndNavigationCommit();
}
void ServiceWorkerMainResourceHandleCore::OnBeginWorkerCommit(
const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy,
ukm::SourceId worker_ukm_source_id) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
if (container_host_) {
container_host_->CompleteWebWorkerPreparation(cross_origin_embedder_policy,
worker_ukm_source_id);
}
}
} // namespace content
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_MAIN_RESOURCE_HANDLE_CORE_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_MAIN_RESOURCE_HANDLE_CORE_H_
#include <memory>
#include <utility>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "content/browser/service_worker/service_worker_accessed_callback.h"
#include "content/browser/service_worker/service_worker_container_host.h"
#include "content/browser/service_worker/service_worker_controllee_request_handler.h"
#include "content/common/content_export.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/network/public/mojom/network_context.mojom.h"
namespace network {
struct CrossOriginEmbedderPolicy;
}
namespace content {
class ServiceWorkerContextWrapper;
class ServiceWorkerMainResourceHandle;
// This class is created on the UI thread, but should only be accessed from the
// service worker core thread afterwards. It is the core thread pendant of
// ServiceWorkerMainResourceHandle. See the ServiceWorkerMainResourceHandle
// header for more details about the lifetime of both classes.
//
// TODO(crbug.com/824858): Merge this class into ServiceWorkerMainResourceHandle
// when the core thread moves to the UI thread.
class CONTENT_EXPORT ServiceWorkerMainResourceHandleCore {
public:
ServiceWorkerMainResourceHandleCore(
base::WeakPtr<ServiceWorkerMainResourceHandle> ui_handle,
ServiceWorkerContextWrapper* context_wrapper,
ServiceWorkerAccessedCallback on_service_worker_accessed);
~ServiceWorkerMainResourceHandleCore();
// Called by corresponding methods in ServiceWorkerMainResourceHandle. See
// comments in the header of ServiceWorkerMainResourceHandle for details.
void OnBeginNavigationCommit(
int render_process_id,
int render_frame_id,
const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy,
mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter>
coep_reporter,
ukm::SourceId document_ukm_source_id);
void OnEndNavigationCommit();
void OnBeginWorkerCommit(
const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy,
ukm::SourceId worker_ukm_source_id);
ServiceWorkerContextWrapper* context_wrapper() const {
return context_wrapper_.get();
}
void set_container_host(
base::WeakPtr<ServiceWorkerContainerHost> container_host) {
container_host_ = std::move(container_host);
}
base::WeakPtr<ServiceWorkerContainerHost> container_host() {
return container_host_;
}
void set_parent_container_host(
base::WeakPtr<ServiceWorkerContainerHost> container_host) {
DCHECK(!parent_container_host_);
parent_container_host_ = std::move(container_host);
}
base::WeakPtr<ServiceWorkerContainerHost> parent_container_host() {
return parent_container_host_;
}
void set_interceptor(
std::unique_ptr<ServiceWorkerControlleeRequestHandler> interceptor) {
interceptor_ = std::move(interceptor);
}
ServiceWorkerControlleeRequestHandler* interceptor() {
return interceptor_.get();
}
const ServiceWorkerAccessedCallback& service_worker_accessed_callback() {
return service_worker_accessed_callback_;
}
base::WeakPtr<ServiceWorkerMainResourceHandleCore> AsWeakPtr() {
return weak_factory_.GetWeakPtr();
}
private:
scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
base::WeakPtr<ServiceWorkerMainResourceHandle> ui_handle_;
base::WeakPtr<ServiceWorkerContainerHost> container_host_;
// Only used for workers with a blob URL.
base::WeakPtr<ServiceWorkerContainerHost> parent_container_host_;
std::unique_ptr<ServiceWorkerControlleeRequestHandler> interceptor_;
ServiceWorkerAccessedCallback service_worker_accessed_callback_;
base::WeakPtrFactory<ServiceWorkerMainResourceHandleCore> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerMainResourceHandleCore);
};
} // namespace content
#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_MAIN_RESOURCE_HANDLE_CORE_H_
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_controllee_request_handler.h" #include "content/browser/service_worker/service_worker_controllee_request_handler.h"
#include "content/browser/service_worker/service_worker_main_resource_handle.h" #include "content/browser/service_worker/service_worker_main_resource_handle.h"
#include "content/browser/service_worker/service_worker_main_resource_handle_core.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/origin_util.h" #include "content/public/common/origin_util.h"
...@@ -33,16 +32,16 @@ namespace { ...@@ -33,16 +32,16 @@ namespace {
// Core thread helpers // Core thread helpers
void LoaderCallbackWrapperOnCoreThread( void LoaderCallbackWrapperOnCoreThread(
ServiceWorkerMainResourceHandleCore* handle_core, ServiceWorkerMainResourceHandle* handle,
base::WeakPtr<ServiceWorkerMainResourceLoaderInterceptor> interceptor_on_ui, base::WeakPtr<ServiceWorkerMainResourceLoaderInterceptor> interceptor_on_ui,
NavigationLoaderInterceptor::LoaderCallback loader_callback, NavigationLoaderInterceptor::LoaderCallback loader_callback,
SingleRequestURLLoaderFactory::RequestHandler handler) { SingleRequestURLLoaderFactory::RequestHandler handler) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
base::Optional<SubresourceLoaderParams> subresource_loader_params; base::Optional<SubresourceLoaderParams> subresource_loader_params;
if (handle_core->interceptor()) { if (handle->interceptor()) {
subresource_loader_params = subresource_loader_params =
handle_core->interceptor()->MaybeCreateSubresourceLoaderParams(); handle->interceptor()->MaybeCreateSubresourceLoaderParams();
} }
RunOrPostTaskOnThread( RunOrPostTaskOnThread(
...@@ -81,7 +80,7 @@ void InvokeRequestHandlerOnCoreThread( ...@@ -81,7 +80,7 @@ void InvokeRequestHandlerOnCoreThread(
// |interceptor_on_ui->LoaderCallbackWrapper()| on the UI thread. // |interceptor_on_ui->LoaderCallbackWrapper()| on the UI thread.
void MaybeCreateLoaderOnCoreThread( void MaybeCreateLoaderOnCoreThread(
base::WeakPtr<ServiceWorkerMainResourceLoaderInterceptor> interceptor_on_ui, base::WeakPtr<ServiceWorkerMainResourceLoaderInterceptor> interceptor_on_ui,
ServiceWorkerMainResourceHandleCore* handle_core, ServiceWorkerMainResourceHandle* handle,
network::mojom::RequestDestination request_destination, network::mojom::RequestDestination request_destination,
bool skip_service_worker, bool skip_service_worker,
bool are_ancestors_secure, bool are_ancestors_secure,
...@@ -99,16 +98,15 @@ void MaybeCreateLoaderOnCoreThread( ...@@ -99,16 +98,15 @@ void MaybeCreateLoaderOnCoreThread(
bool initialize_container_host_only) { bool initialize_container_host_only) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
ServiceWorkerContextCore* context_core = ServiceWorkerContextCore* context_core = handle->context_wrapper()->context();
handle_core->context_wrapper()->context();
if (!context_core || !browser_context) { if (!context_core || !browser_context) {
LoaderCallbackWrapperOnCoreThread(handle_core, std::move(interceptor_on_ui), LoaderCallbackWrapperOnCoreThread(handle, std::move(interceptor_on_ui),
std::move(loader_callback), std::move(loader_callback),
/*handler=*/{}); /*handler=*/{});
return; return;
} }
if (!handle_core->container_host()) { if (!handle->container_host()) {
// This is the initial request before redirects, so make the container host. // This is the initial request before redirects, so make the container host.
// Its lifetime is tied to the |container_info| in the // Its lifetime is tied to the |container_info| in the
// ServiceWorkerMainResourceHandle on the UI thread and which will be passed // ServiceWorkerMainResourceHandle on the UI thread and which will be passed
...@@ -141,7 +139,7 @@ void MaybeCreateLoaderOnCoreThread( ...@@ -141,7 +139,7 @@ void MaybeCreateLoaderOnCoreThread(
// parent. See // parent. See
// https://w3c.github.io/ServiceWorker/#control-and-use-worker-client // https://w3c.github.io/ServiceWorker/#control-and-use-worker-client
base::WeakPtr<ServiceWorkerContainerHost> parent_container_host = base::WeakPtr<ServiceWorkerContainerHost> parent_container_host =
handle_core->parent_container_host(); handle->parent_container_host();
if (parent_container_host && if (parent_container_host &&
tentative_resource_request.url.SchemeIsBlob()) { tentative_resource_request.url.SchemeIsBlob()) {
container_host->InheritControllerFrom(*parent_container_host, container_host->InheritControllerFrom(*parent_container_host,
...@@ -150,15 +148,14 @@ void MaybeCreateLoaderOnCoreThread( ...@@ -150,15 +148,14 @@ void MaybeCreateLoaderOnCoreThread(
} }
} }
DCHECK(container_host); DCHECK(container_host);
handle_core->set_container_host(container_host); handle->set_container_host(container_host);
// Also make the inner interceptor. // Also make the inner interceptor.
DCHECK(!handle_core->interceptor()); DCHECK(!handle->interceptor());
handle_core->set_interceptor( handle->set_interceptor(
std::make_unique<ServiceWorkerControlleeRequestHandler>( std::make_unique<ServiceWorkerControlleeRequestHandler>(
context_core->AsWeakPtr(), container_host, request_destination, context_core->AsWeakPtr(), container_host, request_destination,
skip_service_worker, skip_service_worker, handle->service_worker_accessed_callback()));
handle_core->service_worker_accessed_callback()));
// For the blob worker case, we only inherit the controller and do not // For the blob worker case, we only inherit the controller and do not
// let it intercept the requests. Blob URLs are not eligible to go through // let it intercept the requests. Blob URLs are not eligible to go through
...@@ -167,9 +164,9 @@ void MaybeCreateLoaderOnCoreThread( ...@@ -167,9 +164,9 @@ void MaybeCreateLoaderOnCoreThread(
// ControllerServiceWorkerInfoPtr and ServiceWorkerObjectHost from the // ControllerServiceWorkerInfoPtr and ServiceWorkerObjectHost from the
// subresource loader params which is created by the interceptor. // subresource loader params which is created by the interceptor.
if (inherit_container_host_only) { if (inherit_container_host_only) {
LoaderCallbackWrapperOnCoreThread( LoaderCallbackWrapperOnCoreThread(handle, std::move(interceptor_on_ui),
handle_core, std::move(interceptor_on_ui), std::move(loader_callback), std::move(loader_callback),
/*handler=*/{}); /*handler=*/{});
return; return;
} }
} }
...@@ -178,9 +175,8 @@ void MaybeCreateLoaderOnCoreThread( ...@@ -178,9 +175,8 @@ void MaybeCreateLoaderOnCoreThread(
// there is no registered service worker on the UI thread, so just initialize // there is no registered service worker on the UI thread, so just initialize
// the container host for this request. // the container host for this request.
if (initialize_container_host_only) { if (initialize_container_host_only) {
handle_core->interceptor()->InitializeContainerHost( handle->interceptor()->InitializeContainerHost(tentative_resource_request);
tentative_resource_request); LoaderCallbackWrapperOnCoreThread(handle, interceptor_on_ui,
LoaderCallbackWrapperOnCoreThread(handle_core, interceptor_on_ui,
std::move(loader_callback), std::move(loader_callback),
/*handler=*/{}); /*handler=*/{});
return; return;
...@@ -189,11 +185,11 @@ void MaybeCreateLoaderOnCoreThread( ...@@ -189,11 +185,11 @@ void MaybeCreateLoaderOnCoreThread(
// Start the inner interceptor. We continue in // Start the inner interceptor. We continue in
// LoaderCallbackWrapperOnCoreThread(). // LoaderCallbackWrapperOnCoreThread().
// //
// It's safe to bind the raw |handle_core| to the callback because it owns the // It's safe to bind the raw |handle| to the callback because it owns the
// interceptor, which invokes the callback. // interceptor, which invokes the callback.
handle_core->interceptor()->MaybeCreateLoader( handle->interceptor()->MaybeCreateLoader(
tentative_resource_request, browser_context, tentative_resource_request, browser_context,
base::BindOnce(&LoaderCallbackWrapperOnCoreThread, handle_core, base::BindOnce(&LoaderCallbackWrapperOnCoreThread, handle,
interceptor_on_ui, std::move(loader_callback)), interceptor_on_ui, std::move(loader_callback)),
base::BindOnce(&FallbackCallbackWrapperOnCoreThread, interceptor_on_ui, base::BindOnce(&FallbackCallbackWrapperOnCoreThread, interceptor_on_ui,
std::move(fallback_callback))); std::move(fallback_callback)));
...@@ -270,9 +266,8 @@ ServiceWorkerMainResourceLoaderInterceptor::CreateForWorker( ...@@ -270,9 +266,8 @@ ServiceWorkerMainResourceLoaderInterceptor::CreateForWorker(
network::mojom::RequestDestination::kSharedWorker) network::mojom::RequestDestination::kSharedWorker)
<< resource_request.destination; << resource_request.destination;
if (!ShouldCreateForWorker( if (!ShouldCreateForWorker(resource_request.url,
resource_request.url, navigation_handle->parent_container_host()))
navigation_handle->core()->parent_container_host()))
return nullptr; return nullptr;
return base::WrapUnique(new ServiceWorkerMainResourceLoaderInterceptor( return base::WrapUnique(new ServiceWorkerMainResourceLoaderInterceptor(
...@@ -328,16 +323,13 @@ void ServiceWorkerMainResourceLoaderInterceptor::MaybeCreateLoader( ...@@ -328,16 +323,13 @@ void ServiceWorkerMainResourceLoaderInterceptor::MaybeCreateLoader(
// Start the inner interceptor on the core thread. It will call back to // Start the inner interceptor on the core thread. It will call back to
// LoaderCallbackWrapper() on the UI thread. // LoaderCallbackWrapper() on the UI thread.
ServiceWorkerContextWrapper::RunOrPostTaskOnCoreThread( MaybeCreateLoaderOnCoreThread(
FROM_HERE, GetWeakPtr(), handle_.get(), request_destination_, skip_service_worker_,
base::BindOnce( are_ancestors_secure_, frame_tree_node_id_, process_id_,
&MaybeCreateLoaderOnCoreThread, GetWeakPtr(), handle_->core(), base::OptionalOrNullptr(worker_token_), std::move(host_receiver),
request_destination_, skip_service_worker_, are_ancestors_secure_, std::move(client_remote), tentative_resource_request, browser_context,
frame_tree_node_id_, process_id_, std::move(loader_callback), std::move(fallback_callback),
base::OptionalOrNullptr(worker_token_), std::move(host_receiver), initialize_container_host_only);
std::move(client_remote), tentative_resource_request, browser_context,
std::move(loader_callback), std::move(fallback_callback),
initialize_container_host_only));
if (original_callback) if (original_callback)
std::move(original_callback).Run({}); std::move(original_callback).Run({});
......
...@@ -193,8 +193,7 @@ void DedicatedWorkerHost::StartScriptLoad( ...@@ -193,8 +193,7 @@ void DedicatedWorkerHost::StartScriptLoad(
RenderFrameHostImpl::FromID(creator_render_frame_host_id_.value()) RenderFrameHostImpl::FromID(creator_render_frame_host_id_.value())
->GetLastCommittedServiceWorkerHost(); ->GetLastCommittedServiceWorkerHost();
service_worker_handle_->core()->set_parent_container_host( service_worker_handle_->set_parent_container_host(creator_container_host);
creator_container_host);
} else { } else {
// TODO(https://crbug.com/1017034): When this worker is nested, the worker // TODO(https://crbug.com/1017034): When this worker is nested, the worker
// should inherit the active service worker from the parent worker host. // should inherit the active service worker from the parent worker host.
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "content/browser/navigation_subresource_loader_params.h" #include "content/browser/navigation_subresource_loader_params.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_main_resource_handle.h" #include "content/browser/service_worker/service_worker_main_resource_handle.h"
#include "content/browser/service_worker/service_worker_main_resource_handle_core.h"
#include "content/browser/storage_partition_impl.h" #include "content/browser/storage_partition_impl.h"
#include "content/browser/url_loader_factory_params_helper.h" #include "content/browser/url_loader_factory_params_helper.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "content/browser/appcache/appcache_request_handler.h" #include "content/browser/appcache/appcache_request_handler.h"
#include "content/browser/loader/navigation_loader_interceptor.h" #include "content/browser/loader/navigation_loader_interceptor.h"
#include "content/browser/service_worker/service_worker_main_resource_handle.h" #include "content/browser/service_worker/service_worker_main_resource_handle.h"
#include "content/browser/service_worker/service_worker_main_resource_handle_core.h"
#include "content/browser/service_worker/service_worker_main_resource_loader_interceptor.h" #include "content/browser/service_worker/service_worker_main_resource_loader_interceptor.h"
#include "content/browser/worker_host/worker_script_fetch_initiator.h" #include "content/browser/worker_host/worker_script_fetch_initiator.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "content/browser/service_worker/service_worker_host.h" #include "content/browser/service_worker/service_worker_host.h"
#include "content/browser/service_worker/service_worker_main_resource_handle.h" #include "content/browser/service_worker/service_worker_main_resource_handle.h"
#include "content/browser/service_worker/service_worker_main_resource_handle_core.h"
#include "content/browser/service_worker/service_worker_version.h" #include "content/browser/service_worker/service_worker_version.h"
#include "content/browser/worker_host/worker_script_fetch_initiator.h" #include "content/browser/worker_host/worker_script_fetch_initiator.h"
#include "content/browser/worker_host/worker_script_loader.h" #include "content/browser/worker_host/worker_script_loader.h"
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "content/browser/service_worker/service_worker_context_core.h" #include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_main_resource_handle.h" #include "content/browser/service_worker/service_worker_main_resource_handle.h"
#include "content/browser/service_worker/service_worker_main_resource_handle_core.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "content/test/fake_network_url_loader_factory.h" #include "content/test/fake_network_url_loader_factory.h"
#include "net/base/isolation_info.h" #include "net/base/isolation_info.h"
...@@ -111,7 +110,7 @@ TEST_F(WorkerScriptLoaderFactoryTest, ServiceWorkerContainerHost) { ...@@ -111,7 +110,7 @@ TEST_F(WorkerScriptLoaderFactoryTest, ServiceWorkerContainerHost) {
// The container host should be set up. // The container host should be set up.
base::WeakPtr<ServiceWorkerContainerHost> container_host = base::WeakPtr<ServiceWorkerContainerHost> container_host =
service_worker_handle_->core()->container_host(); service_worker_handle_->container_host();
EXPECT_TRUE(container_host->is_response_committed()); EXPECT_TRUE(container_host->is_response_committed());
EXPECT_TRUE(container_host->is_execution_ready()); EXPECT_TRUE(container_host->is_execution_ready());
EXPECT_EQ(url, container_host->url()); EXPECT_EQ(url, container_host->url());
......
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