Chromium Code Reviews| 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 17246a1f1bc6c450541f893130461e1b9bffd0ef..3ed84e5308548cd87575f2546d8ef386a7beb2b6 100644 |
| --- a/content/browser/service_worker/embedded_worker_instance.cc |
| +++ b/content/browser/service_worker/embedded_worker_instance.cc |
| @@ -500,28 +500,47 @@ ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { |
| // Abort an inflight start task. |
| inflight_start_task_.reset(); |
| - ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_IPC_FAILED; |
| if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { |
| - status = SERVICE_WORKER_OK; |
| client_->StopWorker(base::Bind(&EmbeddedWorkerRegistry::OnWorkerStopped, |
| base::Unretained(registry_.get()), |
| process_id(), embedded_worker_id())); |
| + UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status", |
| + SERVICE_WORKER_OK, |
|
nhiroki
2016/12/15 09:53:15
Does StopWorker() always succeed? If so, do we sti
shimazu
2016/12/19 08:25:12
Oops, I forgot to change that. Fixed it.
|
| + SERVICE_WORKER_ERROR_MAX_VALUE); |
| + if (status_ == EmbeddedWorkerStatus::STARTING) { |
| + // Handles like detach when connection hasn't been established yet. |
| + switch (starting_phase()) { |
| + case NOT_STARTING: |
|
nhiroki
2016/12/15 09:53:15
Is this case really possible?
shimazu
2016/12/19 08:25:12
No actually. Stop should be called when status_ ==
|
| + case ALLOCATING_PROCESS: |
| + OnDetached(); |
| + return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; |
|
nhiroki
2016/12/15 09:53:15
Why do we handle this case as an error? I wonder i
shimazu
2016/12/19 08:25:12
This is because it's the same with legacy IPC.
|
| + case REGISTERING_TO_DEVTOOLS: |
| + OnDetached(); |
| + return SERVICE_WORKER_ERROR_IPC_FAILED; |
|
nhiroki
2016/12/15 09:53:15
ditto.
shimazu
2016/12/19 08:25:12
Acknowledged.
|
| + default: |
|
nhiroki
2016/12/15 09:53:15
I'd prefer to avoid 'default' because this could s
shimazu
2016/12/19 08:25:12
Done.
|
| + break; |
| + } |
| + } |
| + status_ = EmbeddedWorkerStatus::STOPPING; |
| + for (auto& observer : listener_list_) |
| + observer.OnStopping(); |
| + return SERVICE_WORKER_OK; |
| } 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, |
| - // or we can no longer communicate with the process. So just detach. |
| - if (status != SERVICE_WORKER_OK) { |
| - OnDetached(); |
| + ServiceWorkerStatusCode 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, or we can no longer communicate with the process. So just detach. |
| + if (status != SERVICE_WORKER_OK) { |
| + OnDetached(); |
| + return status; |
| + } |
| + status_ = EmbeddedWorkerStatus::STOPPING; |
| + for (auto& observer : listener_list_) |
| + observer.OnStopping(); |
| return status; |
| } |
| - |
| - status_ = EmbeddedWorkerStatus::STOPPING; |
| - for (auto& observer : listener_list_) |
| - observer.OnStopping(); |
| - return status; |
| } |
| void EmbeddedWorkerInstance::StopIfIdle() { |