Index: content/browser/service_worker/embedded_worker_instance.cc |
diff --git a/content/browser/service_worker/embedded_worker_instance.cc b/content/browser/service_worker/embedded_worker_instance.cc |
index b607f52ec83c6e86ce3e129c92efd8c63c41a931..1a83733050d068fd9d4796a89e7154fe3ae9ea43 100644 |
--- a/content/browser/service_worker/embedded_worker_instance.cc |
+++ b/content/browser/service_worker/embedded_worker_instance.cc |
@@ -457,8 +457,11 @@ void EmbeddedWorkerInstance::Start( |
params->settings.v8_cache_options = GetV8CacheOptions(); |
mojom::EmbeddedWorkerInstanceClientRequest request; |
- if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) |
+ if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { |
request = mojo::GetProxy(&client_); |
+ client_.set_connection_error_handler( |
+ base::Bind(&EmbeddedWorkerInstance::Detach, AsWeakPtr())); |
+ } |
inflight_start_task_.reset( |
new StartTask(this, params->script_url, std::move(request))); |
@@ -473,8 +476,19 @@ ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { |
// Abort an inflight start task. |
inflight_start_task_.reset(); |
- ServiceWorkerStatusCode status = |
- registry_->StopWorker(process_id(), embedded_worker_id_); |
+ ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_IPC_FAILED; |
+ if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { |
+ if (!client_) { |
horo
2016/09/13 08:25:32
How this happens?
shimazu
2016/09/20 04:56:20
This will happen when calling Stop before Start, b
|
+ registry_->OnWorkerStopped(process_id(), embedded_worker_id()); |
+ return SERVICE_WORKER_ERROR_IPC_FAILED; |
+ } |
+ status = SERVICE_WORKER_OK; |
+ client_->StopWorker(base::Bind(&EmbeddedWorkerRegistry::OnWorkerStopped, |
+ base::Unretained(registry_.get()), |
+ process_id(), embedded_worker_id())); |
+ } else { |
+ status = registry_->StopWorker(process_id(), embedded_worker_id_); |
+ } |
UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status", status, |
SERVICE_WORKER_ERROR_MAX_VALUE); |
// StopWorker could fail if we were starting up and don't have a process yet, |
@@ -753,7 +767,7 @@ void EmbeddedWorkerInstance::OnDetached() { |
} |
void EmbeddedWorkerInstance::Detach() { |
- registry_->RemoveWorker(process_id(), embedded_worker_id_); |
+ registry_->DetachWorker(process_id(), embedded_worker_id()); |
OnDetached(); |
} |
@@ -833,6 +847,7 @@ void EmbeddedWorkerInstance::ReleaseProcess() { |
// Abort an inflight start task. |
inflight_start_task_.reset(); |
+ client_.reset(); |
devtools_proxy_.reset(); |
process_handle_.reset(); |
status_ = EmbeddedWorkerStatus::STOPPED; |