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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 pending_dispatcher_request_ = std::move(dispatcher_request); | 488 pending_dispatcher_request_ = std::move(dispatcher_request); |
489 | 489 |
490 inflight_start_task_.reset( | 490 inflight_start_task_.reset( |
491 new StartTask(this, params->script_url, std::move(request))); | 491 new StartTask(this, params->script_url, std::move(request))); |
492 inflight_start_task_->Start(std::move(params), callback); | 492 inflight_start_task_->Start(std::move(params), callback); |
493 } | 493 } |
494 | 494 |
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_); |
falken
2016/12/20 04:47:12
Also wouldn't this DCHECK fail if Stop() is called
shimazu
2016/12/20 07:55:01
Yes, I think so.
| |
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_OK; |
504 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { | 504 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { |
505 status = SERVICE_WORKER_OK; | 505 if (status_ == EmbeddedWorkerStatus::STARTING) { |
506 client_->StopWorker(base::Bind(&EmbeddedWorkerRegistry::OnWorkerStopped, | 506 // Abort sending StopWorker message when the connection hasn't been |
507 base::Unretained(registry_.get()), | 507 // established yet. |
508 process_id(), embedded_worker_id())); | 508 switch (starting_phase()) { |
509 case NOT_STARTING: | |
510 NOTREACHED(); | |
511 case ALLOCATING_PROCESS: | |
512 status = SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; | |
513 break; | |
514 case REGISTERING_TO_DEVTOOLS: | |
515 status = SERVICE_WORKER_ERROR_IPC_FAILED; | |
falken
2016/12/20 04:41:31
Hm I don't think we really need to log these as er
shimazu
2016/12/20 07:55:01
Removing the uma seems good. Removed.
| |
516 break; | |
517 case SENT_START_WORKER: | |
518 case SCRIPT_DOWNLOADING: | |
519 case SCRIPT_READ_STARTED: | |
520 case SCRIPT_READ_FINISHED: | |
521 case SCRIPT_LOADED: | |
522 case THREAD_STARTED: | |
523 case SCRIPT_EVALUATED: | |
524 status = SERVICE_WORKER_OK; | |
525 break; | |
526 case STARTING_PHASE_MAX_VALUE: | |
527 NOTREACHED(); | |
528 status = SERVICE_WORKER_ERROR_ABORT; | |
529 break; | |
530 } | |
531 } | |
509 } else { | 532 } else { |
510 status = registry_->StopWorker(process_id(), embedded_worker_id_); | 533 status = registry_->StopWorker(process_id(), embedded_worker_id_); |
511 } | 534 } |
535 | |
512 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status", status, | 536 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status", status, |
513 SERVICE_WORKER_ERROR_MAX_VALUE); | 537 SERVICE_WORKER_ERROR_MAX_VALUE); |
514 // StopWorker could fail if we were starting up and don't have a process yet, | 538 // StopWorker could fail if we were starting up and don't have a process |
515 // or we can no longer communicate with the process. So just detach. | 539 // yet, or we can no longer communicate with the process. So just detach. |
516 if (status != SERVICE_WORKER_OK) { | 540 if (status != SERVICE_WORKER_OK) { |
517 OnDetached(); | 541 OnDetached(); |
518 return status; | 542 return status; |
519 } | 543 } |
520 | 544 |
545 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { | |
546 client_->StopWorker(base::Bind(&EmbeddedWorkerRegistry::OnWorkerStopped, | |
547 base::Unretained(registry_.get()), | |
548 process_id(), embedded_worker_id())); | |
549 } | |
521 status_ = EmbeddedWorkerStatus::STOPPING; | 550 status_ = EmbeddedWorkerStatus::STOPPING; |
522 for (auto& observer : listener_list_) | 551 for (auto& observer : listener_list_) |
523 observer.OnStopping(); | 552 observer.OnStopping(); |
524 return status; | 553 return status; |
525 } | 554 } |
526 | 555 |
527 void EmbeddedWorkerInstance::StopIfIdle() { | 556 void EmbeddedWorkerInstance::StopIfIdle() { |
528 if (devtools_attached_) { | 557 if (devtools_attached_) { |
529 if (devtools_proxy_) { | 558 if (devtools_proxy_) { |
530 // Check ShouldNotifyWorkerStopIgnored not to show the same message | 559 // Check ShouldNotifyWorkerStopIgnored not to show the same message |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
942 case SCRIPT_READ_FINISHED: | 971 case SCRIPT_READ_FINISHED: |
943 return "Script read finished"; | 972 return "Script read finished"; |
944 case STARTING_PHASE_MAX_VALUE: | 973 case STARTING_PHASE_MAX_VALUE: |
945 NOTREACHED(); | 974 NOTREACHED(); |
946 } | 975 } |
947 NOTREACHED() << phase; | 976 NOTREACHED() << phase; |
948 return std::string(); | 977 return std::string(); |
949 } | 978 } |
950 | 979 |
951 } // namespace content | 980 } // namespace content |
OLD | NEW |