Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/service_worker/embedded_worker_instance.h" | 5 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { | 495 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { |
| 496 DCHECK(status_ == EmbeddedWorkerStatus::STARTING || | 496 DCHECK(status_ == EmbeddedWorkerStatus::STARTING || |
| 497 status_ == EmbeddedWorkerStatus::RUNNING) | 497 status_ == EmbeddedWorkerStatus::RUNNING) |
| 498 << static_cast<int>(status_); | 498 << static_cast<int>(status_); |
| 499 | 499 |
| 500 // Abort an inflight start task. | 500 // Abort an inflight start task. |
| 501 inflight_start_task_.reset(); | 501 inflight_start_task_.reset(); |
| 502 | 502 |
| 503 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_IPC_FAILED; | 503 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_IPC_FAILED; |
| 504 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { | 504 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { |
| 505 if (status_ == EmbeddedWorkerStatus::STARTING) { | |
| 506 // Clear internal states and return immediately when the connection hasn't | |
| 507 // been established yet. | |
|
falken
2016/12/20 09:12:07
More than "connection established", I think this i
shimazu
2017/01/05 06:02:41
Done.
| |
| 508 switch (starting_phase()) { | |
| 509 case NOT_STARTING: | |
| 510 NOTREACHED(); | |
| 511 case ALLOCATING_PROCESS: | |
| 512 case REGISTERING_TO_DEVTOOLS: | |
| 513 OnDetached(); | |
| 514 return SERVICE_WORKER_ERROR_FAILED; | |
|
falken
2016/12/20 09:12:06
It doesn't seem right to return error here and hav
shimazu
2017/01/05 06:02:41
That sounds good, but I'd like to create another p
| |
| 515 case SENT_START_WORKER: | |
| 516 case SCRIPT_DOWNLOADING: | |
| 517 case SCRIPT_READ_STARTED: | |
| 518 case SCRIPT_READ_FINISHED: | |
| 519 case SCRIPT_LOADED: | |
| 520 case SCRIPT_EVALUATED: | |
| 521 case THREAD_STARTED: | |
| 522 break; | |
| 523 case STARTING_PHASE_MAX_VALUE: | |
| 524 NOTREACHED(); | |
| 525 OnDetached(); | |
|
falken
2016/12/20 09:12:06
nit: remove OnDetached(). we shouldn't handle the
shimazu
2017/01/05 06:02:41
Done.
| |
| 526 return SERVICE_WORKER_ERROR_ABORT; | |
| 527 } | |
| 528 } | |
| 505 status = SERVICE_WORKER_OK; | 529 status = SERVICE_WORKER_OK; |
| 506 client_->StopWorker(base::Bind(&EmbeddedWorkerRegistry::OnWorkerStopped, | 530 client_->StopWorker(base::Bind(&EmbeddedWorkerRegistry::OnWorkerStopped, |
| 507 base::Unretained(registry_.get()), | 531 base::Unretained(registry_.get()), |
| 508 process_id(), embedded_worker_id())); | 532 process_id(), embedded_worker_id())); |
| 509 } else { | 533 } else { |
| 510 status = registry_->StopWorker(process_id(), embedded_worker_id_); | 534 status = registry_->StopWorker(process_id(), embedded_worker_id_); |
| 511 } | 535 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status", status, |
|
falken
2016/12/20 09:12:06
We should update histograms.xml that it's only use
shimazu
2017/01/05 06:02:41
Done.
| |
| 512 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status", status, | 536 SERVICE_WORKER_ERROR_MAX_VALUE); |
| 513 SERVICE_WORKER_ERROR_MAX_VALUE); | 537 // StopWorker could fail if we were starting up and don't have a process |
| 514 // StopWorker could fail if we were starting up and don't have a process yet, | 538 // yet, or we can no longer communicate with the process. So just detach. |
| 515 // or we can no longer communicate with the process. So just detach. | 539 if (status != SERVICE_WORKER_OK) { |
| 516 if (status != SERVICE_WORKER_OK) { | 540 OnDetached(); |
| 517 OnDetached(); | 541 return status; |
| 518 return status; | 542 } |
| 519 } | 543 } |
| 520 | 544 |
| 521 status_ = EmbeddedWorkerStatus::STOPPING; | 545 status_ = EmbeddedWorkerStatus::STOPPING; |
| 522 for (auto& observer : listener_list_) | 546 for (auto& observer : listener_list_) |
| 523 observer.OnStopping(); | 547 observer.OnStopping(); |
| 524 return status; | 548 return status; |
| 525 } | 549 } |
| 526 | 550 |
| 527 void EmbeddedWorkerInstance::StopIfIdle() { | 551 void EmbeddedWorkerInstance::StopIfIdle() { |
| 528 if (devtools_attached_) { | 552 if (devtools_attached_) { |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 case SCRIPT_READ_FINISHED: | 966 case SCRIPT_READ_FINISHED: |
| 943 return "Script read finished"; | 967 return "Script read finished"; |
| 944 case STARTING_PHASE_MAX_VALUE: | 968 case STARTING_PHASE_MAX_VALUE: |
| 945 NOTREACHED(); | 969 NOTREACHED(); |
| 946 } | 970 } |
| 947 NOTREACHED() << phase; | 971 NOTREACHED() << phase; |
| 948 return std::string(); | 972 return std::string(); |
| 949 } | 973 } |
| 950 | 974 |
| 951 } // namespace content | 975 } // namespace content |
| OLD | NEW |