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

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

Issue 413063004: Service Worker: in Unregister, wait until after the active worker no longer controls a document (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: delete/restore from storage Created 6 years, 5 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_register_job.cc
diff --git a/content/browser/service_worker/service_worker_register_job.cc b/content/browser/service_worker/service_worker_register_job.cc
index dd96b604b3c19393659c30f33e7d5f79bc0b4c3b..09af452a7f519072b9006aaa59a7e519a7f4ff86 100644
--- a/content/browser/service_worker/service_worker_register_job.cc
+++ b/content/browser/service_worker/service_worker_register_job.cc
@@ -114,7 +114,13 @@ void ServiceWorkerRegisterJob::Start() {
&ServiceWorkerRegisterJob::ContinueWithUpdate,
weak_factory_.GetWeakPtr());
}
- context_->storage()->FindRegistrationForPattern(pattern_, next_step);
+
+ scoped_refptr<ServiceWorkerRegistration> registration =
+ context_->storage()->GetUninstallingRegistration(pattern_);
+ if (registration)
+ RunSoon(base::Bind(next_step, SERVICE_WORKER_OK, registration));
+ else
+ context_->storage()->FindRegistrationForPattern(pattern_, next_step);
}
void ServiceWorkerRegisterJob::Abort() {
@@ -197,53 +203,48 @@ void ServiceWorkerRegisterJob::SetPhase(Phase phase) {
phase_ = phase;
}
-// This function corresponds to the steps in Register following
-// "Let serviceWorkerRegistration be _GetRegistration(scope)"
-// |existing_registration| corresponds to serviceWorkerRegistration.
+// This function corresponds to the steps in [[Register]] following
+// "Let registration be the result of running the [[GetRegistration]] algorithm.
// Throughout this file, comments in quotes are excerpts from the spec.
void ServiceWorkerRegisterJob::ContinueWithRegistration(
ServiceWorkerStatusCode status,
const scoped_refptr<ServiceWorkerRegistration>& existing_registration) {
DCHECK_EQ(REGISTRATION_JOB, job_type_);
- // On unexpected error, abort this registration job.
if (status != SERVICE_WORKER_ERROR_NOT_FOUND && status != SERVICE_WORKER_OK) {
Complete(status);
return;
}
- // "If serviceWorkerRegistration is not null and script is equal to
- // serviceWorkerRegistration.scriptUrl..." resolve with the existing
- // registration and abort.
- if (existing_registration.get() &&
- existing_registration->script_url() == script_url_) {
+ if (!existing_registration) {
+ RegisterAndContinue(SERVICE_WORKER_OK);
+ return;
+ }
+
+ // "1. Set registration.[[Uninstalling]] to false."
+ existing_registration->AbortPendingClear();
michaeln 2014/07/29 03:33:39 what if extisting.script != new.script?
falken 2014/07/29 05:36:22 Great catch, this is a big point. There are two ca
+
+ // "2. If scriptURL is equal to registration.[[ScriptURL]], then:"
+ if (existing_registration->script_url() == script_url_) {
+ // Spec says to resolve with registration.[[GetNewestWorker]]. We come close
+ // by resolving with the active version.
set_registration(existing_registration);
- // If there's no active version, go ahead to Update (this isn't in the spec
- // but seems reasonable, and without SoftUpdate implemented we can never
- // Update otherwise).
+
if (!existing_registration->active_version()) {
UpdateAndContinue();
return;
}
+
ResolvePromise(
status, existing_registration, existing_registration->active_version());
Complete(SERVICE_WORKER_OK);
return;
}
- // "If serviceWorkerRegistration is null..." create a new registration.
- if (!existing_registration.get()) {
- RegisterAndContinue(SERVICE_WORKER_OK);
- return;
- }
-
- // On script URL mismatch, "set serviceWorkerRegistration.scriptUrl to
- // script." We accomplish this by deleting the existing registration and
- // registering a new one.
- // TODO(falken): Match the spec. We now throw away the active_version_ and
- // waiting_version_ of the existing registration, which isn't in the spec.
+ // "Set registration.[[ScriptURL]] to scriptURL." We accomplish this by
+ // deleting the existing registration and registering a new one.
// TODO(michaeln): Deactivate the live existing_registration object and
- // eventually call storage->DeleteVersionResources()
- // when it no longer has any controllees.
+ // eventually call storage->DeleteVersionResources() when it no longer has any
+ // controllees.
context_->storage()->DeleteRegistration(
existing_registration->id(),
existing_registration->script_url().GetOrigin(),

Powered by Google App Engine
This is Rietveld 408576698