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

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: Added DCHECKs 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;
506 client_->StopWorker(base::Bind(&EmbeddedWorkerRegistry::OnWorkerStopped, 504 client_->StopWorker(base::Bind(&EmbeddedWorkerRegistry::OnWorkerStopped,
507 base::Unretained(registry_.get()), 505 base::Unretained(registry_.get()),
508 process_id(), embedded_worker_id())); 506 process_id(), embedded_worker_id()));
507 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status",
508 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.
509 SERVICE_WORKER_ERROR_MAX_VALUE);
510 if (status_ == EmbeddedWorkerStatus::STARTING) {
511 // Handles like detach when connection hasn't been established yet.
512 switch (starting_phase()) {
513 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_ ==
514 case ALLOCATING_PROCESS:
515 OnDetached();
516 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.
517 case REGISTERING_TO_DEVTOOLS:
518 OnDetached();
519 return SERVICE_WORKER_ERROR_IPC_FAILED;
nhiroki 2016/12/15 09:53:15 ditto.
shimazu 2016/12/19 08:25:12 Acknowledged.
520 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.
521 break;
522 }
523 }
524 status_ = EmbeddedWorkerStatus::STOPPING;
525 for (auto& observer : listener_list_)
526 observer.OnStopping();
527 return SERVICE_WORKER_OK;
509 } else { 528 } else {
510 status = registry_->StopWorker(process_id(), embedded_worker_id_); 529 ServiceWorkerStatusCode status =
511 } 530 registry_->StopWorker(process_id(), embedded_worker_id_);
512 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status", status, 531 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.SendStopWorker.Status", status,
513 SERVICE_WORKER_ERROR_MAX_VALUE); 532 SERVICE_WORKER_ERROR_MAX_VALUE);
514 // StopWorker could fail if we were starting up and don't have a process yet, 533 // 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. 534 // yet, or we can no longer communicate with the process. So just detach.
516 if (status != SERVICE_WORKER_OK) { 535 if (status != SERVICE_WORKER_OK) {
517 OnDetached(); 536 OnDetached();
537 return status;
538 }
539 status_ = EmbeddedWorkerStatus::STOPPING;
540 for (auto& observer : listener_list_)
541 observer.OnStopping();
518 return status; 542 return status;
519 } 543 }
520
521 status_ = EmbeddedWorkerStatus::STOPPING;
522 for (auto& observer : listener_list_)
523 observer.OnStopping();
524 return status;
525 } 544 }
526 545
527 void EmbeddedWorkerInstance::StopIfIdle() { 546 void EmbeddedWorkerInstance::StopIfIdle() {
528 if (devtools_attached_) { 547 if (devtools_attached_) {
529 if (devtools_proxy_) { 548 if (devtools_proxy_) {
530 // Check ShouldNotifyWorkerStopIgnored not to show the same message 549 // Check ShouldNotifyWorkerStopIgnored not to show the same message
531 // multiple times in DevTools. 550 // multiple times in DevTools.
532 if (devtools_proxy_->ShouldNotifyWorkerStopIgnored()) { 551 if (devtools_proxy_->ShouldNotifyWorkerStopIgnored()) {
533 AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_DEBUG, 552 AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_DEBUG,
534 kServiceWorkerTerminationCanceledMesage); 553 kServiceWorkerTerminationCanceledMesage);
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 case SCRIPT_READ_FINISHED: 961 case SCRIPT_READ_FINISHED:
943 return "Script read finished"; 962 return "Script read finished";
944 case STARTING_PHASE_MAX_VALUE: 963 case STARTING_PHASE_MAX_VALUE:
945 NOTREACHED(); 964 NOTREACHED();
946 } 965 }
947 NOTREACHED() << phase; 966 NOTREACHED() << phase;
948 return std::string(); 967 return std::string();
949 } 968 }
950 969
951 } // namespace content 970 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698