| Index: content/renderer/service_worker/service_worker_context_client.cc
|
| diff --git a/content/renderer/service_worker/service_worker_context_client.cc b/content/renderer/service_worker/service_worker_context_client.cc
|
| index 51c812a9cd41db7c787b5e4b77bf1f07a92e11ea..6fde3a48beb1b90a2dc056f98380fc3fb7c9b5d9 100644
|
| --- a/content/renderer/service_worker/service_worker_context_client.cc
|
| +++ b/content/renderer/service_worker/service_worker_context_client.cc
|
| @@ -37,7 +37,6 @@
|
| #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h"
|
| #include "content/common/service_worker/service_worker_messages.h"
|
| #include "content/common/service_worker/service_worker_status_code.h"
|
| -#include "content/common/service_worker/service_worker_utils.h"
|
| #include "content/public/common/push_event_payload.h"
|
| #include "content/public/common/referrer.h"
|
| #include "content/public/renderer/content_renderer_client.h"
|
| @@ -45,7 +44,6 @@
|
| #include "content/renderer/devtools/devtools_agent.h"
|
| #include "content/renderer/render_thread_impl.h"
|
| #include "content/renderer/service_worker/embedded_worker_devtools_agent.h"
|
| -#include "content/renderer/service_worker/embedded_worker_dispatcher.h"
|
| #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h"
|
| #include "content/renderer/service_worker/service_worker_type_converters.h"
|
| #include "content/renderer/service_worker/service_worker_type_util.h"
|
| @@ -78,14 +76,6 @@ namespace {
|
| base::LazyInstance<base::ThreadLocalPointer<ServiceWorkerContextClient>>::
|
| Leaky g_worker_client_tls = LAZY_INSTANCE_INITIALIZER;
|
|
|
| -void CallWorkerContextDestroyedOnMainThread(int embedded_worker_id) {
|
| - if (!RenderThreadImpl::current() ||
|
| - !RenderThreadImpl::current()->embedded_worker_dispatcher())
|
| - return;
|
| - RenderThreadImpl::current()->embedded_worker_dispatcher()->
|
| - WorkerContextDestroyed(embedded_worker_id);
|
| -}
|
| -
|
| // Called on the main thread only and blink owns it.
|
| class WebServiceWorkerNetworkProviderImpl
|
| : public blink::WebServiceWorkerNetworkProvider {
|
| @@ -490,6 +480,7 @@ ServiceWorkerContextClient::ServiceWorkerContextClient(
|
| const GURL& service_worker_scope,
|
| const GURL& script_url,
|
| mojom::ServiceWorkerEventDispatcherRequest dispatcher_request,
|
| + mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host,
|
| std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client)
|
| : embedded_worker_id_(embedded_worker_id),
|
| service_worker_version_id_(service_worker_version_id),
|
| @@ -500,6 +491,9 @@ ServiceWorkerContextClient::ServiceWorkerContextClient(
|
| proxy_(nullptr),
|
| pending_dispatcher_request_(std::move(dispatcher_request)),
|
| embedded_worker_client_(std::move(embedded_worker_client)) {
|
| + instance_host_ =
|
| + mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr::Create(
|
| + std::move(instance_host), main_thread_task_runner_);
|
| TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker",
|
| "ServiceWorkerContextClient::StartingWorkerContext",
|
| this);
|
| @@ -586,24 +580,26 @@ void ServiceWorkerContextClient::ClearCachedMetadata(const blink::WebURL& url) {
|
| }
|
|
|
| void ServiceWorkerContextClient::WorkerReadyForInspection() {
|
| - Send(new EmbeddedWorkerHostMsg_WorkerReadyForInspection(embedded_worker_id_));
|
| + DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread());
|
| + (*instance_host_)->OnReadyForInspection();
|
| }
|
|
|
| void ServiceWorkerContextClient::WorkerContextFailedToStart() {
|
| DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread());
|
| DCHECK(!proxy_);
|
|
|
| - Send(new EmbeddedWorkerHostMsg_WorkerScriptLoadFailed(embedded_worker_id_));
|
| + (*instance_host_)->OnScriptLoadFailed();
|
| + (*instance_host_)->OnStopped();
|
|
|
| - RenderThreadImpl::current()->embedded_worker_dispatcher()->
|
| - WorkerContextDestroyed(embedded_worker_id_);
|
| + DCHECK(embedded_worker_client_);
|
| + embedded_worker_client_->WorkerContextDestroyed();
|
| }
|
|
|
| void ServiceWorkerContextClient::WorkerScriptLoaded() {
|
| DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread());
|
| DCHECK(!proxy_);
|
|
|
| - Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded(embedded_worker_id_));
|
| + (*instance_host_)->OnScriptLoaded();
|
| }
|
|
|
| bool ServiceWorkerContextClient::HasAssociatedRegistration() {
|
| @@ -641,9 +637,9 @@ void ServiceWorkerContextClient::WorkerContextStarted(
|
|
|
| SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs);
|
|
|
| - Send(new EmbeddedWorkerHostMsg_WorkerThreadStarted(
|
| - embedded_worker_id_, WorkerThread::GetCurrentId(),
|
| - provider_context_->provider_id()));
|
| + (*instance_host_)
|
| + ->OnThreadStarted(WorkerThread::GetCurrentId(),
|
| + provider_context_->provider_id());
|
|
|
| TRACE_EVENT_ASYNC_STEP_INTO0(
|
| "ServiceWorker",
|
| @@ -653,8 +649,8 @@ void ServiceWorkerContextClient::WorkerContextStarted(
|
| }
|
|
|
| void ServiceWorkerContextClient::DidEvaluateWorkerScript(bool success) {
|
| - Send(new EmbeddedWorkerHostMsg_WorkerScriptEvaluated(
|
| - embedded_worker_id_, success));
|
| + DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
|
| + (*instance_host_)->OnScriptEvaluated(success);
|
|
|
| // Schedule a task to send back WorkerStarted asynchronously,
|
| // so that at the time we send it we can be sure that the
|
| @@ -707,22 +703,20 @@ void ServiceWorkerContextClient::WillDestroyWorkerContext(
|
| void ServiceWorkerContextClient::WorkerContextDestroyed() {
|
| DCHECK(g_worker_client_tls.Pointer()->Get() == NULL);
|
|
|
| - // Check if mojo is enabled
|
| - if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) {
|
| - DCHECK(embedded_worker_client_);
|
| - main_thread_task_runner_->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&EmbeddedWorkerInstanceClientImpl::StopWorkerCompleted,
|
| - base::Passed(&embedded_worker_client_)));
|
| - return;
|
| - }
|
| + // TODO(falken): The signals to the browser should be in the order:
|
| + // (1) WorkerStopped (via OnStopped())
|
| + // (2) ProviderDestroyed (via following
|
| + // EmbeddedWorkerInstanceClientImpl::StopWorkerCompleted) But this ordering is
|
| + // currently not guaranteed since the Mojo pipes are different.
|
| + // https://crbug.com/676526
|
| + (*instance_host_)->OnStopped();
|
|
|
| - // Now we should be able to free the WebEmbeddedWorker container on the
|
| - // main thread.
|
| + DCHECK(embedded_worker_client_);
|
| main_thread_task_runner_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&CallWorkerContextDestroyedOnMainThread,
|
| - embedded_worker_id_));
|
| + base::Bind(&EmbeddedWorkerInstanceClientImpl::WorkerContextDestroyed,
|
| + base::Passed(&embedded_worker_client_)));
|
| + return;
|
| }
|
|
|
| void ServiceWorkerContextClient::CountFeature(uint32_t feature) {
|
| @@ -735,9 +729,9 @@ void ServiceWorkerContextClient::ReportException(
|
| int line_number,
|
| int column_number,
|
| const blink::WebString& source_url) {
|
| - Send(new EmbeddedWorkerHostMsg_ReportException(
|
| - embedded_worker_id_, error_message.Utf16(), line_number, column_number,
|
| - blink::WebStringToGURL(source_url)));
|
| + (*instance_host_)
|
| + ->OnReportException(error_message.Utf16(), line_number, column_number,
|
| + blink::WebStringToGURL(source_url));
|
| }
|
|
|
| void ServiceWorkerContextClient::ReportConsoleMessage(
|
| @@ -746,15 +740,9 @@ void ServiceWorkerContextClient::ReportConsoleMessage(
|
| const blink::WebString& message,
|
| int line_number,
|
| const blink::WebString& source_url) {
|
| - EmbeddedWorkerHostMsg_ReportConsoleMessage_Params params;
|
| - params.source_identifier = source;
|
| - params.message_level = level;
|
| - params.message = message.Utf16();
|
| - params.line_number = line_number;
|
| - params.source_url = blink::WebStringToGURL(source_url);
|
| -
|
| - Send(new EmbeddedWorkerHostMsg_ReportConsoleMessage(
|
| - embedded_worker_id_, params));
|
| + (*instance_host_)
|
| + ->OnReportConsoleMessage(source, level, message.Utf16(), line_number,
|
| + blink::WebStringToGURL(source_url));
|
| }
|
|
|
| void ServiceWorkerContextClient::SendDevToolsMessage(
|
| @@ -1090,7 +1078,7 @@ void ServiceWorkerContextClient::SendWorkerStarted() {
|
| TRACE_EVENT_ASYNC_END0("ServiceWorker",
|
| "ServiceWorkerContextClient::StartingWorkerContext",
|
| this);
|
| - Send(new EmbeddedWorkerHostMsg_WorkerStarted(embedded_worker_id_));
|
| + (*instance_host_)->OnStarted();
|
| }
|
|
|
| void ServiceWorkerContextClient::SetRegistrationInServiceWorkerGlobalScope(
|
|
|