Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: content/browser/service_worker/embedded_worker_instance.cc

Issue 2578023002: ServiceWorker: Stop don't send a message before connection established (Closed)
Patch Set: Addressed comments from nhiroki@ Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_);
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;
504 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { 503 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) {
505 status = SERVICE_WORKER_OK; 504 ServiceWorkerStatusCode status = SERVICE_WORKER_OK;
505 if (status_ == EmbeddedWorkerStatus::STARTING) {
506 // Handle like detach when connection hasn't been established yet.
507 switch (starting_phase()) {
508 case NOT_STARTING:
509 NOTREACHED();
510 case ALLOCATING_PROCESS:
511 status = SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND;
512 OnDetached();
513 break;
514 case REGISTERING_TO_DEVTOOLS:
515 status = SERVICE_WORKER_ERROR_IPC_FAILED;
516 OnDetached();
517 break;
518 case SENT_START_WORKER:
519 case SCRIPT_DOWNLOADING:
520 case SCRIPT_READ_STARTED:
521 case SCRIPT_READ_FINISHED:
522 case SCRIPT_LOADED:
523 case THREAD_STARTED:
524 case SCRIPT_EVALUATED:
525 status = SERVICE_WORKER_OK;
526 break;
527 default:
nhiroki 2016/12/19 09:21:55 Can you use "STARTING_PHASE_MAX_VALUE:" instead of
shimazu 2016/12/19 09:47:51 Done.
528 NOTREACHED();
529 }
530 }
531 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status", status,
532 SERVICE_WORKER_ERROR_MAX_VALUE);
533 if (status != SERVICE_WORKER_OK)
534 return status;
506 client_->StopWorker(base::Bind(&EmbeddedWorkerRegistry::OnWorkerStopped, 535 client_->StopWorker(base::Bind(&EmbeddedWorkerRegistry::OnWorkerStopped,
507 base::Unretained(registry_.get()), 536 base::Unretained(registry_.get()),
508 process_id(), embedded_worker_id())); 537 process_id(), embedded_worker_id()));
538 status_ = EmbeddedWorkerStatus::STOPPING;
539 for (auto& observer : listener_list_)
540 observer.OnStopping();
541 return status;
509 } else { 542 } else {
510 status = registry_->StopWorker(process_id(), embedded_worker_id_); 543 ServiceWorkerStatusCode status =
511 } 544 registry_->StopWorker(process_id(), embedded_worker_id_);
512 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status", status, 545 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status", status,
513 SERVICE_WORKER_ERROR_MAX_VALUE); 546 SERVICE_WORKER_ERROR_MAX_VALUE);
514 // StopWorker could fail if we were starting up and don't have a process yet, 547 // 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. 548 // yet, or we can no longer communicate with the process. So just detach.
516 if (status != SERVICE_WORKER_OK) { 549 if (status != SERVICE_WORKER_OK) {
517 OnDetached(); 550 OnDetached();
551 return status;
552 }
553 status_ = EmbeddedWorkerStatus::STOPPING;
554 for (auto& observer : listener_list_)
555 observer.OnStopping();
518 return status; 556 return status;
nhiroki 2016/12/19 09:21:55 nit: We could merge line 553-556 into 538-541 and
shimazu 2016/12/19 09:47:51 Done.
519 } 557 }
520
521 status_ = EmbeddedWorkerStatus::STOPPING;
522 for (auto& observer : listener_list_)
523 observer.OnStopping();
524 return status;
525 } 558 }
526 559
527 void EmbeddedWorkerInstance::StopIfIdle() { 560 void EmbeddedWorkerInstance::StopIfIdle() {
528 if (devtools_attached_) { 561 if (devtools_attached_) {
529 if (devtools_proxy_) { 562 if (devtools_proxy_) {
530 // Check ShouldNotifyWorkerStopIgnored not to show the same message 563 // Check ShouldNotifyWorkerStopIgnored not to show the same message
531 // multiple times in DevTools. 564 // multiple times in DevTools.
532 if (devtools_proxy_->ShouldNotifyWorkerStopIgnored()) { 565 if (devtools_proxy_->ShouldNotifyWorkerStopIgnored()) {
533 AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_DEBUG, 566 AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_DEBUG,
534 kServiceWorkerTerminationCanceledMesage); 567 kServiceWorkerTerminationCanceledMesage);
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 case SCRIPT_READ_FINISHED: 975 case SCRIPT_READ_FINISHED:
943 return "Script read finished"; 976 return "Script read finished";
944 case STARTING_PHASE_MAX_VALUE: 977 case STARTING_PHASE_MAX_VALUE:
945 NOTREACHED(); 978 NOTREACHED();
946 } 979 }
947 NOTREACHED() << phase; 980 NOTREACHED() << phase;
948 return std::string(); 981 return std::string();
949 } 982 }
950 983
951 } // namespace content 984 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698