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

Unified Diff: content/browser/service_worker/service_worker_version.cc

Issue 2578023002: ServiceWorker: Stop don't send a message before connection established (Closed)
Patch Set: Reset starting_phase when releasing the process Created 3 years, 11 months 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_version.cc
diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc
index 2370600532f4d3623c885906f58fa9e44a1dee42..21c34b4aa38fc9cf4919c2ee1e87b61505183a57 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -494,19 +494,27 @@ void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) {
TRACE_EVENT_SCOPE_THREAD, "Script", script_url_.spec(),
"Status", VersionStatusToString(status_));
- if (running_status() == EmbeddedWorkerStatus::STOPPED) {
- RunSoon(base::Bind(callback, SERVICE_WORKER_OK));
- return;
- }
-
- if (stop_callbacks_.empty()) {
- ServiceWorkerStatusCode status = embedded_worker_->Stop();
- if (status != SERVICE_WORKER_OK) {
- RunSoon(base::Bind(callback, status));
+ switch (running_status()) {
+ case EmbeddedWorkerStatus::STARTING:
+ case EmbeddedWorkerStatus::RUNNING:
+ // Stop() returns false when it's called before StartWorker message hasn't
+ // been sent to the renderer process even though EmbeddedWorkerInstance is
+ // stopped properly.
+ // TODO(shimazu): Remove this check after Stop() hides the IPC behavior.
+ // See also a TODO on EmbeddedWorkerInstance::Stop.
+ if (!embedded_worker_->Stop()) {
+ RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_IPC_FAILED));
+ return;
+ }
+ stop_callbacks_.push_back(callback);
+ return;
+ case EmbeddedWorkerStatus::STOPPING:
+ stop_callbacks_.push_back(callback);
+ return;
+ case EmbeddedWorkerStatus::STOPPED:
+ RunSoon(base::Bind(callback, SERVICE_WORKER_OK));
return;
- }
}
- stop_callbacks_.push_back(callback);
}
void ServiceWorkerVersion::ScheduleUpdate() {

Powered by Google App Engine
This is Rietveld 408576698