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 fb363187fd6025eb3ab42b8b37c010d254d11037..eec62c5f447bacf8394d48cc991e0f128b88574d 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" |
@@ -77,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 { |
@@ -471,6 +462,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), |
@@ -481,6 +473,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); |
@@ -568,14 +563,16 @@ void ServiceWorkerContextClient::clearCachedMetadata( |
} |
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_); |
@@ -585,7 +582,7 @@ void ServiceWorkerContextClient::workerScriptLoaded() { |
DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
DCHECK(!proxy_); |
- Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded(embedded_worker_id_)); |
+ (*instance_host_)->OnScriptLoaded(); |
} |
bool ServiceWorkerContextClient::hasAssociatedRegistration() { |
@@ -623,9 +620,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", |
@@ -635,8 +632,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 |
@@ -689,22 +686,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::StopWorkerCompleted, |
+ base::Passed(&embedded_worker_client_))); |
+ return; |
} |
void ServiceWorkerContextClient::countFeature(uint32_t feature) { |
@@ -717,9 +712,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( |
@@ -728,15 +723,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( |
@@ -1072,7 +1061,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( |