Commit 312a5fae authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

service worker: Replace OnMainThread suffix with OnInitiatorThread

This is a follow-up CL of https://crrev.com/c/1743227. We plan to
start service worker threads on the IO thread so use main thread
orthogonal suffix. We use "the initiator thread" instead of "the
main thread."

Bug: 692909
Change-Id: I624df28773807677c830cd385c82b8b78440e26b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1745685
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686400}
parent a88626f1
...@@ -28,18 +28,18 @@ namespace content { ...@@ -28,18 +28,18 @@ namespace content {
// static // static
void EmbeddedWorkerInstanceClientImpl::Create( void EmbeddedWorkerInstanceClientImpl::Create(
blink::mojom::EmbeddedWorkerInstanceClientRequest request, blink::mojom::EmbeddedWorkerInstanceClientRequest request,
scoped_refptr<base::SingleThreadTaskRunner> starter_thread_task_runner) { scoped_refptr<base::SingleThreadTaskRunner> initiator_thread_task_runner) {
// This won't be leaked because the lifetime will be managed internally. // This won't be leaked because the lifetime will be managed internally.
// See the class documentation for detail. // See the class documentation for detail.
// We can't use MakeStrongBinding because must give the worker thread // We can't use MakeStrongBinding because must give the worker thread
// a chance to stop by calling TerminateWorkerContext() and waiting // a chance to stop by calling TerminateWorkerContext() and waiting
// before destructing. // before destructing.
new EmbeddedWorkerInstanceClientImpl(std::move(request), new EmbeddedWorkerInstanceClientImpl(std::move(request),
std::move(starter_thread_task_runner)); std::move(initiator_thread_task_runner));
} }
void EmbeddedWorkerInstanceClientImpl::WorkerContextDestroyed() { void EmbeddedWorkerInstanceClientImpl::WorkerContextDestroyed() {
DCHECK(starter_thread_task_runner_->BelongsToCurrentThread()); DCHECK(initiator_thread_task_runner_->BelongsToCurrentThread());
TRACE_EVENT0("ServiceWorker", TRACE_EVENT0("ServiceWorker",
"EmbeddedWorkerInstanceClientImpl::WorkerContextDestroyed"); "EmbeddedWorkerInstanceClientImpl::WorkerContextDestroyed");
delete this; delete this;
...@@ -47,7 +47,7 @@ void EmbeddedWorkerInstanceClientImpl::WorkerContextDestroyed() { ...@@ -47,7 +47,7 @@ void EmbeddedWorkerInstanceClientImpl::WorkerContextDestroyed() {
void EmbeddedWorkerInstanceClientImpl::StartWorker( void EmbeddedWorkerInstanceClientImpl::StartWorker(
blink::mojom::EmbeddedWorkerStartParamsPtr params) { blink::mojom::EmbeddedWorkerStartParamsPtr params) {
DCHECK(starter_thread_task_runner_->BelongsToCurrentThread()); DCHECK(initiator_thread_task_runner_->BelongsToCurrentThread());
DCHECK(!service_worker_context_client_); DCHECK(!service_worker_context_client_);
TRACE_EVENT0("ServiceWorker", TRACE_EVENT0("ServiceWorker",
"EmbeddedWorkerInstanceClientImpl::StartWorker"); "EmbeddedWorkerInstanceClientImpl::StartWorker");
...@@ -73,7 +73,7 @@ void EmbeddedWorkerInstanceClientImpl::StartWorker( ...@@ -73,7 +73,7 @@ void EmbeddedWorkerInstanceClientImpl::StartWorker(
std::move(params->preference_watcher_request), std::move(params->preference_watcher_request),
std::move(params->subresource_loader_factories), std::move(params->subresource_loader_factories),
std::move(params->subresource_loader_updater), std::move(params->subresource_loader_updater),
starter_thread_task_runner_); initiator_thread_task_runner_);
// Record UMA to indicate StartWorker is received on renderer. // Record UMA to indicate StartWorker is received on renderer.
StartWorkerHistogramEnum metric = StartWorkerHistogramEnum metric =
params->is_installed ? StartWorkerHistogramEnum::RECEIVED_ON_INSTALLED params->is_installed ? StartWorkerHistogramEnum::RECEIVED_ON_INSTALLED
...@@ -105,12 +105,12 @@ void EmbeddedWorkerInstanceClientImpl::StartWorker( ...@@ -105,12 +105,12 @@ void EmbeddedWorkerInstanceClientImpl::StartWorker(
std::move(installed_scripts_manager_params), std::move(installed_scripts_manager_params),
params->content_settings_proxy.PassHandle(), cache_storage.PassHandle(), params->content_settings_proxy.PassHandle(), cache_storage.PassHandle(),
interface_provider.PassHandle()); interface_provider.PassHandle());
service_worker_context_client_->StartWorkerContextOnStarterThread( service_worker_context_client_->StartWorkerContextOnInitiatorThread(
std::move(worker), start_data); std::move(worker), start_data);
} }
void EmbeddedWorkerInstanceClientImpl::StopWorker() { void EmbeddedWorkerInstanceClientImpl::StopWorker() {
DCHECK(starter_thread_task_runner_->BelongsToCurrentThread()); DCHECK(initiator_thread_task_runner_->BelongsToCurrentThread());
TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstanceClientImpl::StopWorker"); TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstanceClientImpl::StopWorker");
// StopWorker must be called after StartWorker is called. // StopWorker must be called after StartWorker is called.
service_worker_context_client_->worker().TerminateWorkerContext(); service_worker_context_client_->worker().TerminateWorkerContext();
...@@ -118,34 +118,34 @@ void EmbeddedWorkerInstanceClientImpl::StopWorker() { ...@@ -118,34 +118,34 @@ void EmbeddedWorkerInstanceClientImpl::StopWorker() {
} }
void EmbeddedWorkerInstanceClientImpl::ResumeAfterDownload() { void EmbeddedWorkerInstanceClientImpl::ResumeAfterDownload() {
DCHECK(starter_thread_task_runner_->BelongsToCurrentThread()); DCHECK(initiator_thread_task_runner_->BelongsToCurrentThread());
service_worker_context_client_->worker().ResumeAfterDownload(); service_worker_context_client_->worker().ResumeAfterDownload();
} }
void EmbeddedWorkerInstanceClientImpl::AddMessageToConsole( void EmbeddedWorkerInstanceClientImpl::AddMessageToConsole(
blink::mojom::ConsoleMessageLevel level, blink::mojom::ConsoleMessageLevel level,
const std::string& message) { const std::string& message) {
DCHECK(starter_thread_task_runner_->BelongsToCurrentThread()); DCHECK(initiator_thread_task_runner_->BelongsToCurrentThread());
service_worker_context_client_->worker().AddMessageToConsole( service_worker_context_client_->worker().AddMessageToConsole(
blink::WebConsoleMessage(level, blink::WebString::FromUTF8(message))); blink::WebConsoleMessage(level, blink::WebString::FromUTF8(message)));
} }
EmbeddedWorkerInstanceClientImpl::EmbeddedWorkerInstanceClientImpl( EmbeddedWorkerInstanceClientImpl::EmbeddedWorkerInstanceClientImpl(
blink::mojom::EmbeddedWorkerInstanceClientRequest request, blink::mojom::EmbeddedWorkerInstanceClientRequest request,
scoped_refptr<base::SingleThreadTaskRunner> starter_thread_task_runner) scoped_refptr<base::SingleThreadTaskRunner> initiator_thread_task_runner)
: binding_(this, std::move(request)), : binding_(this, std::move(request)),
starter_thread_task_runner_(std::move(starter_thread_task_runner)) { initiator_thread_task_runner_(std::move(initiator_thread_task_runner)) {
DCHECK(starter_thread_task_runner_->BelongsToCurrentThread()); DCHECK(initiator_thread_task_runner_->BelongsToCurrentThread());
binding_.set_connection_error_handler(base::BindOnce( binding_.set_connection_error_handler(base::BindOnce(
&EmbeddedWorkerInstanceClientImpl::OnError, base::Unretained(this))); &EmbeddedWorkerInstanceClientImpl::OnError, base::Unretained(this)));
} }
EmbeddedWorkerInstanceClientImpl::~EmbeddedWorkerInstanceClientImpl() { EmbeddedWorkerInstanceClientImpl::~EmbeddedWorkerInstanceClientImpl() {
DCHECK(starter_thread_task_runner_->BelongsToCurrentThread()); DCHECK(initiator_thread_task_runner_->BelongsToCurrentThread());
} }
void EmbeddedWorkerInstanceClientImpl::OnError() { void EmbeddedWorkerInstanceClientImpl::OnError() {
DCHECK(starter_thread_task_runner_->BelongsToCurrentThread()); DCHECK(initiator_thread_task_runner_->BelongsToCurrentThread());
// The connection to the browser process broke. // The connection to the browser process broke.
if (service_worker_context_client_) { if (service_worker_context_client_) {
// The worker is running, so tell it to stop. We continue in // The worker is running, so tell it to stop. We continue in
...@@ -161,7 +161,7 @@ void EmbeddedWorkerInstanceClientImpl::OnError() { ...@@ -161,7 +161,7 @@ void EmbeddedWorkerInstanceClientImpl::OnError() {
blink::WebEmbeddedWorkerStartData blink::WebEmbeddedWorkerStartData
EmbeddedWorkerInstanceClientImpl::BuildStartData( EmbeddedWorkerInstanceClientImpl::BuildStartData(
const blink::mojom::EmbeddedWorkerStartParams& params) { const blink::mojom::EmbeddedWorkerStartParams& params) {
DCHECK(starter_thread_task_runner_->BelongsToCurrentThread()); DCHECK(initiator_thread_task_runner_->BelongsToCurrentThread());
blink::WebEmbeddedWorkerStartData start_data; blink::WebEmbeddedWorkerStartData start_data;
start_data.script_url = params.script_url; start_data.script_url = params.script_url;
start_data.user_agent = blink::WebString::FromUTF8(params.user_agent); start_data.user_agent = blink::WebString::FromUTF8(params.user_agent);
......
...@@ -46,7 +46,7 @@ class CONTENT_EXPORT EmbeddedWorkerInstanceClientImpl ...@@ -46,7 +46,7 @@ class CONTENT_EXPORT EmbeddedWorkerInstanceClientImpl
// instead of just creating an instance of EmbeddedWorkerInstanceClient. // instead of just creating an instance of EmbeddedWorkerInstanceClient.
static void Create( static void Create(
blink::mojom::EmbeddedWorkerInstanceClientRequest request, blink::mojom::EmbeddedWorkerInstanceClientRequest request,
scoped_refptr<base::SingleThreadTaskRunner> starter_task_runner); scoped_refptr<base::SingleThreadTaskRunner> initiator_task_runner);
~EmbeddedWorkerInstanceClientImpl() override; ~EmbeddedWorkerInstanceClientImpl() override;
...@@ -62,7 +62,7 @@ class CONTENT_EXPORT EmbeddedWorkerInstanceClientImpl ...@@ -62,7 +62,7 @@ class CONTENT_EXPORT EmbeddedWorkerInstanceClientImpl
EmbeddedWorkerInstanceClientImpl( EmbeddedWorkerInstanceClientImpl(
blink::mojom::EmbeddedWorkerInstanceClientRequest request, blink::mojom::EmbeddedWorkerInstanceClientRequest request,
scoped_refptr<base::SingleThreadTaskRunner> starter_thread_task_runner); scoped_refptr<base::SingleThreadTaskRunner> initiator_thread_task_runner);
// blink::mojom::EmbeddedWorkerInstanceClient implementation // blink::mojom::EmbeddedWorkerInstanceClient implementation
void StartWorker(blink::mojom::EmbeddedWorkerStartParamsPtr params) override; void StartWorker(blink::mojom::EmbeddedWorkerStartParamsPtr params) override;
...@@ -80,7 +80,7 @@ class CONTENT_EXPORT EmbeddedWorkerInstanceClientImpl ...@@ -80,7 +80,7 @@ class CONTENT_EXPORT EmbeddedWorkerInstanceClientImpl
// A copy of this runner is also passed to ServiceWorkerContextClient in // A copy of this runner is also passed to ServiceWorkerContextClient in
// StartWorker(). // StartWorker().
scoped_refptr<base::SingleThreadTaskRunner> starter_thread_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> initiator_thread_task_runner_;
// nullptr means worker is not running. // nullptr means worker is not running.
std::unique_ptr<ServiceWorkerContextClient> service_worker_context_client_; std::unique_ptr<ServiceWorkerContextClient> service_worker_context_client_;
......
...@@ -107,14 +107,14 @@ ServiceWorkerContextClient::ServiceWorkerContextClient( ...@@ -107,14 +107,14 @@ ServiceWorkerContextClient::ServiceWorkerContextClient(
std::unique_ptr<blink::URLLoaderFactoryBundleInfo> subresource_loaders, std::unique_ptr<blink::URLLoaderFactoryBundleInfo> subresource_loaders,
mojo::PendingReceiver<blink::mojom::ServiceWorkerSubresourceLoaderUpdater> mojo::PendingReceiver<blink::mojom::ServiceWorkerSubresourceLoaderUpdater>
subresource_loader_updater, subresource_loader_updater,
scoped_refptr<base::SingleThreadTaskRunner> starter_thread_task_runner) scoped_refptr<base::SingleThreadTaskRunner> initiator_thread_task_runner)
: service_worker_version_id_(service_worker_version_id), : service_worker_version_id_(service_worker_version_id),
service_worker_scope_(service_worker_scope), service_worker_scope_(service_worker_scope),
script_url_(script_url), script_url_(script_url),
is_starting_installed_worker_(is_starting_installed_worker), is_starting_installed_worker_(is_starting_installed_worker),
renderer_preferences_(std::move(renderer_preferences)), renderer_preferences_(std::move(renderer_preferences)),
preference_watcher_request_(std::move(preference_watcher_request)), preference_watcher_request_(std::move(preference_watcher_request)),
starter_thread_task_runner_(std::move(starter_thread_task_runner)), initiator_thread_task_runner_(std::move(initiator_thread_task_runner)),
proxy_(nullptr), proxy_(nullptr),
pending_service_worker_request_(std::move(service_worker_request)), pending_service_worker_request_(std::move(service_worker_request)),
controller_receiver_(std::move(controller_receiver)), controller_receiver_(std::move(controller_receiver)),
...@@ -122,12 +122,12 @@ ServiceWorkerContextClient::ServiceWorkerContextClient( ...@@ -122,12 +122,12 @@ ServiceWorkerContextClient::ServiceWorkerContextClient(
std::move(subresource_loader_updater)), std::move(subresource_loader_updater)),
owner_(owner), owner_(owner),
start_timing_(std::move(start_timing)) { start_timing_(std::move(start_timing)) {
DCHECK(starter_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(initiator_thread_task_runner_->RunsTasksInCurrentSequence());
DCHECK(owner_); DCHECK(owner_);
DCHECK(subresource_loaders); DCHECK(subresource_loaders);
instance_host_ = instance_host_ =
blink::mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr::Create( blink::mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr::Create(
std::move(instance_host), starter_thread_task_runner_); std::move(instance_host), initiator_thread_task_runner_);
if (IsOutOfProcessNetworkService()) { if (IsOutOfProcessNetworkService()) {
// If the network service crashes, this worker self-terminates, so it can // If the network service crashes, this worker self-terminates, so it can
...@@ -142,7 +142,7 @@ ServiceWorkerContextClient::ServiceWorkerContextClient( ...@@ -142,7 +142,7 @@ ServiceWorkerContextClient::ServiceWorkerContextClient(
.InitWithNewPipeAndPassReceiver()); .InitWithNewPipeAndPassReceiver());
network_service_connection_error_handler_holder_ network_service_connection_error_handler_holder_
.set_connection_error_handler(base::BindOnce( .set_connection_error_handler(base::BindOnce(
&ServiceWorkerContextClient::StopWorkerOnStarterThread, &ServiceWorkerContextClient::StopWorkerOnInitiatorThread,
base::Unretained(this))); base::Unretained(this)));
} }
...@@ -162,26 +162,26 @@ ServiceWorkerContextClient::ServiceWorkerContextClient( ...@@ -162,26 +162,26 @@ ServiceWorkerContextClient::ServiceWorkerContextClient(
} }
ServiceWorkerContextClient::~ServiceWorkerContextClient() { ServiceWorkerContextClient::~ServiceWorkerContextClient() {
DCHECK(starter_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(initiator_thread_task_runner_->RunsTasksInCurrentSequence());
} }
void ServiceWorkerContextClient::StartWorkerContextOnStarterThread( void ServiceWorkerContextClient::StartWorkerContextOnInitiatorThread(
std::unique_ptr<blink::WebEmbeddedWorker> worker, std::unique_ptr<blink::WebEmbeddedWorker> worker,
const blink::WebEmbeddedWorkerStartData& start_data) { const blink::WebEmbeddedWorkerStartData& start_data) {
DCHECK(starter_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(initiator_thread_task_runner_->RunsTasksInCurrentSequence());
worker_ = std::move(worker); worker_ = std::move(worker);
worker_->StartWorkerContext(start_data); worker_->StartWorkerContext(start_data);
} }
blink::WebEmbeddedWorker& ServiceWorkerContextClient::worker() { blink::WebEmbeddedWorker& ServiceWorkerContextClient::worker() {
DCHECK(starter_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(initiator_thread_task_runner_->RunsTasksInCurrentSequence());
return *worker_; return *worker_;
} }
void ServiceWorkerContextClient::WorkerReadyForInspectionOnMainThread( void ServiceWorkerContextClient::WorkerReadyForInspectionOnInitiatorThread(
mojo::ScopedMessagePipeHandle devtools_agent_remote, mojo::ScopedMessagePipeHandle devtools_agent_remote,
mojo::ScopedMessagePipeHandle devtools_agent_host_receiver) { mojo::ScopedMessagePipeHandle devtools_agent_host_receiver) {
DCHECK(starter_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(initiator_thread_task_runner_->RunsTasksInCurrentSequence());
mojo::PendingRemote<blink::mojom::DevToolsAgent> agent_remote( mojo::PendingRemote<blink::mojom::DevToolsAgent> agent_remote(
std::move(devtools_agent_remote), blink::mojom::DevToolsAgent::Version_); std::move(devtools_agent_remote), blink::mojom::DevToolsAgent::Version_);
mojo::PendingReceiver<blink::mojom::DevToolsAgentHost> receiver( mojo::PendingReceiver<blink::mojom::DevToolsAgentHost> receiver(
...@@ -190,15 +190,15 @@ void ServiceWorkerContextClient::WorkerReadyForInspectionOnMainThread( ...@@ -190,15 +190,15 @@ void ServiceWorkerContextClient::WorkerReadyForInspectionOnMainThread(
->OnReadyForInspection(std::move(agent_remote), std::move(receiver)); ->OnReadyForInspection(std::move(agent_remote), std::move(receiver));
} }
void ServiceWorkerContextClient::WorkerContextFailedToStartOnMainThread() { void ServiceWorkerContextClient::WorkerContextFailedToStartOnInitiatorThread() {
DCHECK(starter_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(initiator_thread_task_runner_->RunsTasksInCurrentSequence());
DCHECK(!proxy_); DCHECK(!proxy_);
(*instance_host_)->OnStopped(); (*instance_host_)->OnStopped();
TRACE_EVENT_NESTABLE_ASYNC_END1("ServiceWorker", "ServiceWorkerContextClient", TRACE_EVENT_NESTABLE_ASYNC_END1(
this, "Status", "ServiceWorker", "ServiceWorkerContextClient", this, "Status",
"WorkerContextFailedToStartOnMainThread"); "WorkerContextFailedToStartOnInitiatorThread");
owner_->WorkerContextDestroyed(); owner_->WorkerContextDestroyed();
} }
...@@ -229,8 +229,8 @@ void ServiceWorkerContextClient::FailedToFetchModuleScript() { ...@@ -229,8 +229,8 @@ void ServiceWorkerContextClient::FailedToFetchModuleScript() {
// eventually destroys |this|. // eventually destroys |this|.
} }
void ServiceWorkerContextClient::WorkerScriptLoadedOnMainThread() { void ServiceWorkerContextClient::WorkerScriptLoadedOnInitiatorThread() {
DCHECK(starter_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(initiator_thread_task_runner_->RunsTasksInCurrentSequence());
DCHECK(!is_starting_installed_worker_); DCHECK(!is_starting_installed_worker_);
(*instance_host_)->OnScriptLoaded(); (*instance_host_)->OnScriptLoaded();
TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "LOAD_SCRIPT", this); TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "LOAD_SCRIPT", this);
...@@ -245,8 +245,8 @@ void ServiceWorkerContextClient::WorkerScriptLoadedOnWorkerThread() { ...@@ -245,8 +245,8 @@ void ServiceWorkerContextClient::WorkerScriptLoadedOnWorkerThread() {
void ServiceWorkerContextClient::WorkerContextStarted( void ServiceWorkerContextClient::WorkerContextStarted(
blink::WebServiceWorkerContextProxy* proxy, blink::WebServiceWorkerContextProxy* proxy,
scoped_refptr<base::SequencedTaskRunner> worker_task_runner) { scoped_refptr<base::SequencedTaskRunner> worker_task_runner) {
DCHECK(!starter_thread_task_runner_->RunsTasksInCurrentSequence()) DCHECK(!initiator_thread_task_runner_->RunsTasksInCurrentSequence())
<< "service worker started on the starter thread instead of a worker " << "service worker started on the initiator thread instead of a worker "
"thread"; "thread";
DCHECK(worker_task_runner->RunsTasksInCurrentSequence()); DCHECK(worker_task_runner->RunsTasksInCurrentSequence());
DCHECK(!worker_task_runner_); DCHECK(!worker_task_runner_);
...@@ -350,7 +350,7 @@ void ServiceWorkerContextClient::WorkerContextDestroyed() { ...@@ -350,7 +350,7 @@ void ServiceWorkerContextClient::WorkerContextDestroyed() {
// base::Unretained is safe because |owner_| does not destroy itself until // base::Unretained is safe because |owner_| does not destroy itself until
// WorkerContextDestroyed is called. // WorkerContextDestroyed is called.
starter_thread_task_runner_->PostTask( initiator_thread_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&EmbeddedWorkerInstanceClientImpl::WorkerContextDestroyed, base::BindOnce(&EmbeddedWorkerInstanceClientImpl::WorkerContextDestroyed,
base::Unretained(owner_))); base::Unretained(owner_)));
...@@ -383,8 +383,8 @@ void ServiceWorkerContextClient::ReportConsoleMessage( ...@@ -383,8 +383,8 @@ void ServiceWorkerContextClient::ReportConsoleMessage(
} }
scoped_refptr<blink::WebWorkerFetchContext> scoped_refptr<blink::WebWorkerFetchContext>
ServiceWorkerContextClient::CreateWorkerFetchContextOnMainThread() { ServiceWorkerContextClient::CreateWorkerFetchContextOnInitiatorThread() {
DCHECK(starter_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(initiator_thread_task_runner_->RunsTasksInCurrentSequence());
DCHECK(preference_watcher_request_.is_pending()); DCHECK(preference_watcher_request_.is_pending());
// TODO(bashi): Consider changing ServiceWorkerFetchContextImpl to take // TODO(bashi): Consider changing ServiceWorkerFetchContextImpl to take
...@@ -514,8 +514,8 @@ void ServiceWorkerContextClient::RequestTermination( ...@@ -514,8 +514,8 @@ void ServiceWorkerContextClient::RequestTermination(
(*instance_host_)->RequestTermination(std::move(callback)); (*instance_host_)->RequestTermination(std::move(callback));
} }
void ServiceWorkerContextClient::StopWorkerOnStarterThread() { void ServiceWorkerContextClient::StopWorkerOnInitiatorThread() {
DCHECK(starter_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(initiator_thread_task_runner_->RunsTasksInCurrentSequence());
owner_->StopWorker(); owner_->StopWorker();
} }
......
...@@ -61,7 +61,7 @@ class WebWorkerFetchContext; ...@@ -61,7 +61,7 @@ class WebWorkerFetchContext;
// starting up, and destroyed when the service worker stops. It is owned by // starting up, and destroyed when the service worker stops. It is owned by
// WebEmbeddedWorkerImpl (which is owned by EmbeddedWorkerInstanceClientImpl). // WebEmbeddedWorkerImpl (which is owned by EmbeddedWorkerInstanceClientImpl).
// //
// This class is created and destroyed on the "starter" thread. The starter // This class is created and destroyed on the "initiator" thread. The initiator
// thread is the thread that constructs this class. Currently it's the main // thread is the thread that constructs this class. Currently it's the main
// thread but could be the IO thread in the future. https://crbug.com/692909 // thread but could be the IO thread in the future. https://crbug.com/692909
// //
...@@ -70,7 +70,7 @@ class WebWorkerFetchContext; ...@@ -70,7 +70,7 @@ class WebWorkerFetchContext;
class CONTENT_EXPORT ServiceWorkerContextClient class CONTENT_EXPORT ServiceWorkerContextClient
: public blink::WebServiceWorkerContextClient { : public blink::WebServiceWorkerContextClient {
public: public:
// Called on the starter thread. // Called on the initiator thread.
// - |is_starting_installed_worker| is true if the script is already installed // - |is_starting_installed_worker| is true if the script is already installed
// and will be streamed from the browser process. // and will be streamed from the browser process.
// - |owner| must outlive this new instance. // - |owner| must outlive this new instance.
...@@ -97,26 +97,25 @@ class CONTENT_EXPORT ServiceWorkerContextClient ...@@ -97,26 +97,25 @@ class CONTENT_EXPORT ServiceWorkerContextClient
std::unique_ptr<blink::URLLoaderFactoryBundleInfo> subresource_loaders, std::unique_ptr<blink::URLLoaderFactoryBundleInfo> subresource_loaders,
mojo::PendingReceiver<blink::mojom::ServiceWorkerSubresourceLoaderUpdater> mojo::PendingReceiver<blink::mojom::ServiceWorkerSubresourceLoaderUpdater>
subresource_loader_updater, subresource_loader_updater,
scoped_refptr<base::SingleThreadTaskRunner> starter_thread_task_runner); scoped_refptr<base::SingleThreadTaskRunner> initiator_thread_task_runner);
// Called on the starter thread. // Called on the initiator thread.
~ServiceWorkerContextClient() override; ~ServiceWorkerContextClient() override;
// Called on the starter thread. // Called on the initiator thread.
void StartWorkerContextOnStarterThread( void StartWorkerContextOnInitiatorThread(
std::unique_ptr<blink::WebEmbeddedWorker> worker, std::unique_ptr<blink::WebEmbeddedWorker> worker,
const blink::WebEmbeddedWorkerStartData& start_data); const blink::WebEmbeddedWorkerStartData& start_data);
// Called on the starter thread. // Called on the initiator thread.
blink::WebEmbeddedWorker& worker(); blink::WebEmbeddedWorker& worker();
// WebServiceWorkerContextClient overrides. // WebServiceWorkerContextClient overrides.
// TODO(bashi): Rename OnMainThread() methods. void WorkerReadyForInspectionOnInitiatorThread(
void WorkerReadyForInspectionOnMainThread( mojo::ScopedMessagePipeHandle devtools_agent_ptr_info,
mojo::ScopedMessagePipeHandle devtools_agent_remote, mojo::ScopedMessagePipeHandle devtools_agent_host_request) override;
mojo::ScopedMessagePipeHandle devtools_agent_host_receiver) override; void WorkerContextFailedToStartOnInitiatorThread() override;
void WorkerContextFailedToStartOnMainThread() override;
void FailedToLoadClassicScript() override; void FailedToLoadClassicScript() override;
void FailedToFetchModuleScript() override; void FailedToFetchModuleScript() override;
void WorkerScriptLoadedOnMainThread() override; void WorkerScriptLoadedOnInitiatorThread() override;
void WorkerScriptLoadedOnWorkerThread() override; void WorkerScriptLoadedOnWorkerThread() override;
void WorkerContextStarted( void WorkerContextStarted(
blink::WebServiceWorkerContextProxy* proxy, blink::WebServiceWorkerContextProxy* proxy,
...@@ -145,7 +144,7 @@ class CONTENT_EXPORT ServiceWorkerContextClient ...@@ -145,7 +144,7 @@ class CONTENT_EXPORT ServiceWorkerContextClient
preload_handle) override; preload_handle) override;
void RequestTermination(RequestTerminationCallback callback) override; void RequestTermination(RequestTerminationCallback callback) override;
scoped_refptr<blink::WebWorkerFetchContext> scoped_refptr<blink::WebWorkerFetchContext>
CreateWorkerFetchContextOnMainThread() override; CreateWorkerFetchContextOnInitiatorThread() override;
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// The following are for use by NavigationPreloadRequest. // The following are for use by NavigationPreloadRequest.
...@@ -188,8 +187,8 @@ class CONTENT_EXPORT ServiceWorkerContextClient ...@@ -188,8 +187,8 @@ class CONTENT_EXPORT ServiceWorkerContextClient
void SendWorkerStarted(blink::mojom::ServiceWorkerStartStatus status); void SendWorkerStarted(blink::mojom::ServiceWorkerStartStatus status);
// Stops the worker context. Called on the starter thread. // Stops the worker context. Called on the initiator thread.
void StopWorkerOnStarterThread(); void StopWorkerOnInitiatorThread();
base::WeakPtr<ServiceWorkerContextClient> GetWeakPtr(); base::WeakPtr<ServiceWorkerContextClient> GetWeakPtr();
...@@ -204,7 +203,7 @@ class CONTENT_EXPORT ServiceWorkerContextClient ...@@ -204,7 +203,7 @@ class CONTENT_EXPORT ServiceWorkerContextClient
// Passed on creation of ServiceWorkerFetchContext. // Passed on creation of ServiceWorkerFetchContext.
blink::mojom::RendererPreferenceWatcherRequest preference_watcher_request_; blink::mojom::RendererPreferenceWatcherRequest preference_watcher_request_;
scoped_refptr<base::SingleThreadTaskRunner> starter_thread_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> initiator_thread_task_runner_;
scoped_refptr<base::SequencedTaskRunner> worker_task_runner_; scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
// Not owned; |this| is destroyed when |proxy_| becomes invalid. // Not owned; |this| is destroyed when |proxy_| becomes invalid.
...@@ -217,7 +216,7 @@ class CONTENT_EXPORT ServiceWorkerContextClient ...@@ -217,7 +216,7 @@ class CONTENT_EXPORT ServiceWorkerContextClient
mojo::PendingReceiver<blink::mojom::ServiceWorkerSubresourceLoaderUpdater> mojo::PendingReceiver<blink::mojom::ServiceWorkerSubresourceLoaderUpdater>
pending_subresource_loader_updater_; pending_subresource_loader_updater_;
// This is bound on the starter thread. // This is bound on the initiator thread.
scoped_refptr<blink::mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr> scoped_refptr<blink::mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr>
instance_host_; instance_host_;
...@@ -229,7 +228,7 @@ class CONTENT_EXPORT ServiceWorkerContextClient ...@@ -229,7 +228,7 @@ class CONTENT_EXPORT ServiceWorkerContextClient
blink::mojom::ServiceWorkerProviderInfoForStartWorkerPtr blink::mojom::ServiceWorkerProviderInfoForStartWorkerPtr
service_worker_provider_info_; service_worker_provider_info_;
// Must be accessed on the starter thread only. // Must be accessed on the initiator thread only.
EmbeddedWorkerInstanceClientImpl* owner_; EmbeddedWorkerInstanceClientImpl* owner_;
blink::mojom::BlobRegistryPtr blob_registry_; blink::mojom::BlobRegistryPtr blob_registry_;
......
...@@ -64,8 +64,8 @@ struct WebFetchEventPreloadHandle { ...@@ -64,8 +64,8 @@ struct WebFetchEventPreloadHandle {
// WebServiceWorkerContextClient is a "client" of a service worker execution // WebServiceWorkerContextClient is a "client" of a service worker execution
// context. This interface is implemented by the embedder and allows the // context. This interface is implemented by the embedder and allows the
// embedder to communicate with the service worker execution context. It is // embedder to communicate with the service worker execution context. It is
// created on the main thread and then passed on to the worker thread by a newly // created on the initiator thread (the main thread or the IO thread) and then
// created ServiceWorkerGlobalScope. // passed on to the worker thread by a newly created ServiceWorkerGlobalScope.
// //
// Unless otherwise noted, all methods of this class are called on the worker // Unless otherwise noted, all methods of this class are called on the worker
// thread. // thread.
...@@ -76,15 +76,15 @@ class WebServiceWorkerContextClient { ...@@ -76,15 +76,15 @@ class WebServiceWorkerContextClient {
virtual ~WebServiceWorkerContextClient() = default; virtual ~WebServiceWorkerContextClient() = default;
// ServiceWorker has prepared everything for script loading and is now ready // ServiceWorker has prepared everything for script loading and is now ready
// for DevTools inspection. Called on the main thread. // for DevTools inspection. Called on the initiator thread.
virtual void WorkerReadyForInspectionOnMainThread( virtual void WorkerReadyForInspectionOnInitiatorThread(
mojo::ScopedMessagePipeHandle devtools_agent_ptr_info, mojo::ScopedMessagePipeHandle devtools_agent_ptr_info,
mojo::ScopedMessagePipeHandle devtools_agent_host_request) {} mojo::ScopedMessagePipeHandle devtools_agent_host_request) {}
// Starting the worker failed. This could happen when loading the worker // Starting the worker failed. This could happen when loading the worker
// script failed, or the worker was asked to terminate before startup // script failed, or the worker was asked to terminate before startup
// completed. Called on the main thread. // completed. Called on the initiator thread.
virtual void WorkerContextFailedToStartOnMainThread() {} virtual void WorkerContextFailedToStartOnInitiatorThread() {}
// The worker started but it could not execute because loading the classic // The worker started but it could not execute because loading the classic
// script failed on the worker thread. This is called only for installed // script failed on the worker thread. This is called only for installed
...@@ -96,11 +96,11 @@ class WebServiceWorkerContextClient { ...@@ -96,11 +96,11 @@ class WebServiceWorkerContextClient {
virtual void FailedToFetchModuleScript() {} virtual void FailedToFetchModuleScript() {}
// The worker script was successfully loaded by ResourceLoader. Called on the // The worker script was successfully loaded by ResourceLoader. Called on the
// main thread. // initiator thread.
// //
// This is called before WorkerContextStarted(). Script evaluation does not // This is called before WorkerContextStarted(). Script evaluation does not
// start until WillEvaluateScript(). // start until WillEvaluateScript().
virtual void WorkerScriptLoadedOnMainThread() {} virtual void WorkerScriptLoadedOnInitiatorThread() {}
// The worker script was successfully loaded on the worker thread. // The worker script was successfully loaded on the worker thread.
// When off-the-main-thread script fetch is on, this is called for both // When off-the-main-thread script fetch is on, this is called for both
...@@ -125,7 +125,7 @@ class WebServiceWorkerContextClient { ...@@ -125,7 +125,7 @@ class WebServiceWorkerContextClient {
// WorkerScriptLoadedOnWorkerThread(). // WorkerScriptLoadedOnWorkerThread().
// //
// For installed workers, this is called before // For installed workers, this is called before
// WorkerScriptLoadedOnMainThread(). // WorkerScriptLoadedOnInitiatorThread().
// //
// Script evaluation does not start until WillEvaluateScript(). // Script evaluation does not start until WillEvaluateScript().
virtual void WorkerContextStarted( virtual void WorkerContextStarted(
...@@ -199,9 +199,9 @@ class WebServiceWorkerContextClient { ...@@ -199,9 +199,9 @@ class WebServiceWorkerContextClient {
// Off-main-thread start up: // Off-main-thread start up:
// Creates a WebWorkerFetchContext for subresource fetches on a service // Creates a WebWorkerFetchContext for subresource fetches on a service
// worker. This is called on the main thread. // worker. This is called on the initiator thread.
virtual scoped_refptr<blink::WebWorkerFetchContext> virtual scoped_refptr<blink::WebWorkerFetchContext>
CreateWorkerFetchContextOnMainThread() = 0; CreateWorkerFetchContextOnInitiatorThread() = 0;
}; };
} // namespace blink } // namespace blink
......
...@@ -190,7 +190,7 @@ void WebEmbeddedWorkerImpl::TerminateWorkerContext() { ...@@ -190,7 +190,7 @@ void WebEmbeddedWorkerImpl::TerminateWorkerContext() {
asked_to_terminate_ = true; asked_to_terminate_ = true;
if (!shadow_page_->WasInitialized()) { if (!shadow_page_->WasInitialized()) {
// This deletes 'this'. // This deletes 'this'.
worker_context_client_->WorkerContextFailedToStartOnMainThread(); worker_context_client_->WorkerContextFailedToStartOnInitiatorThread();
return; return;
} }
if (!worker_thread_) { if (!worker_thread_) {
...@@ -200,7 +200,7 @@ void WebEmbeddedWorkerImpl::TerminateWorkerContext() { ...@@ -200,7 +200,7 @@ void WebEmbeddedWorkerImpl::TerminateWorkerContext() {
WebEmbeddedWorkerStartData::kWaitForDebugger || WebEmbeddedWorkerStartData::kWaitForDebugger ||
pause_after_download_state_ == kIsPausedAfterDownload); pause_after_download_state_ == kIsPausedAfterDownload);
// This deletes 'this'. // This deletes 'this'.
worker_context_client_->WorkerContextFailedToStartOnMainThread(); worker_context_client_->WorkerContextFailedToStartOnInitiatorThread();
return; return;
} }
worker_thread_->Terminate(); worker_thread_->Terminate();
...@@ -252,7 +252,7 @@ void WebEmbeddedWorkerImpl::StartWorkerThread() { ...@@ -252,7 +252,7 @@ void WebEmbeddedWorkerImpl::StartWorkerThread() {
CalculateHttpsState(starter_origin.get()); CalculateHttpsState(starter_origin.get());
scoped_refptr<WebWorkerFetchContext> web_worker_fetch_context = scoped_refptr<WebWorkerFetchContext> web_worker_fetch_context =
worker_context_client_->CreateWorkerFetchContextOnMainThread(); worker_context_client_->CreateWorkerFetchContextOnInitiatorThread();
// Create WorkerSettings. Currently we block all mixed-content requests from // Create WorkerSettings. Currently we block all mixed-content requests from
// a ServiceWorker. // a ServiceWorker.
...@@ -368,7 +368,7 @@ void WebEmbeddedWorkerImpl::StartWorkerThread() { ...@@ -368,7 +368,7 @@ void WebEmbeddedWorkerImpl::StartWorkerThread() {
} }
} }
// We are now ready to inspect worker thread. // We are now ready to inspect worker thread.
worker_context_client_->WorkerReadyForInspectionOnMainThread( worker_context_client_->WorkerReadyForInspectionOnInitiatorThread(
devtools_agent_remote.PassPipe(), devtools_agent_remote.PassPipe(),
devtools_agent_host_receiver.PassPipe()); devtools_agent_host_receiver.PassPipe());
} }
......
...@@ -152,11 +152,11 @@ class MockServiceWorkerContextClient final ...@@ -152,11 +152,11 @@ class MockServiceWorkerContextClient final
MockServiceWorkerContextClient() = default; MockServiceWorkerContextClient() = default;
~MockServiceWorkerContextClient() override = default; ~MockServiceWorkerContextClient() override = default;
MOCK_METHOD2(WorkerReadyForInspectionOnMainThread, MOCK_METHOD2(WorkerReadyForInspectionOnInitiatorThread,
void(mojo::ScopedMessagePipeHandle, void(mojo::ScopedMessagePipeHandle,
mojo::ScopedMessagePipeHandle)); mojo::ScopedMessagePipeHandle));
MOCK_METHOD0(WorkerContextFailedToStartOnMainThread, void()); MOCK_METHOD0(WorkerContextFailedToStartOnInitiatorThread, void());
MOCK_METHOD0(WorkerScriptLoadedOnMainThread, void()); MOCK_METHOD0(WorkerScriptLoadedOnInitiatorThread, void());
void WorkerContextStarted(WebServiceWorkerContextProxy* proxy, void WorkerContextStarted(WebServiceWorkerContextProxy* proxy,
scoped_refptr<base::SequencedTaskRunner>) override { scoped_refptr<base::SequencedTaskRunner>) override {
...@@ -202,8 +202,8 @@ class MockServiceWorkerContextClient final ...@@ -202,8 +202,8 @@ class MockServiceWorkerContextClient final
script_evaluated_event_.Signal(); script_evaluated_event_.Signal();
} }
scoped_refptr<WebWorkerFetchContext> CreateWorkerFetchContextOnMainThread() scoped_refptr<WebWorkerFetchContext>
override { CreateWorkerFetchContextOnInitiatorThread() override {
return base::MakeRefCounted<FakeWebWorkerFetchContext>(); return base::MakeRefCounted<FakeWebWorkerFetchContext>();
} }
......
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