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

Unified Diff: content/browser/service_worker/service_worker_registration.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: 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_registration.cc
diff --git a/content/browser/service_worker/service_worker_registration.cc b/content/browser/service_worker/service_worker_registration.cc
index 130559589d4469aef9c036890dcc2975034305d9..7b1802979310fbb890fb578885e36841da8d0c84 100644
--- a/content/browser/service_worker/service_worker_registration.cc
+++ b/content/browser/service_worker/service_worker_registration.cc
@@ -30,6 +30,7 @@ ServiceWorkerRegistration::ServiceWorkerRegistration(
: pattern_(pattern),
script_url_(script_url),
registration_id_(registration_id),
+ is_uninstalling_(false),
context_(context) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(context_);
@@ -91,6 +92,13 @@ void ServiceWorkerRegistration::UnsetVersion(ServiceWorkerVersion* version) {
}
}
+void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) {
+ DCHECK_EQ(active_version(), version);
+ version->RemoveListener(this);
+ if (is_uninstalling())
+ Uninstall();
+}
+
void ServiceWorkerRegistration::SetVersionInternal(
ServiceWorkerVersion* version,
scoped_refptr<ServiceWorkerVersion>* data_member,
@@ -164,6 +172,39 @@ void ServiceWorkerRegistration::ActivateWaitingVersion(
this, activating_version, completion_callback));
}
+void ServiceWorkerRegistration::StartUninstall() {
michaeln 2014/07/25 00:02:04 let's harmonize on naming, i'm using ActivateWait
falken 2014/07/25 12:47:25 Sounds good.
+ DCHECK(context_);
+ set_uninstalling(true);
+ // "11. Wait until no document is using registration as their Service Worker
+ // registration."
+ if (active_version() && active_version()->HasControllee())
+ active_version()->AddListener(this);
+ else
+ Uninstall();
+}
+
+void ServiceWorkerRegistration::Uninstall() {
+ DCHECK(is_uninstalling());
+ if (!context_)
+ return;
+
+ // "12. If registration.activeWorker is not null, then:"
+ if (active_version()) {
+ // "1. Run the [[UpdateState]] algorithm passing registration.activeWorker
+ // and 'redundant' as the arguments."
+ active_version()->Doom();
+ // "2. Set registration.activeWorker to null."
+ UnsetVersion(active_version());
+ }
+
+ // "13. Delete a Record {[[key]], [[value]]} entry of its
+ // [[ScopeToRegistrationMap]] where scope matches entry.[[key]]."
+ context_->storage()->DeleteRegistration(
+ id(),
+ script_url().GetOrigin(),
+ base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
+}
+
void ServiceWorkerRegistration::OnActivateEventFinished(
ServiceWorkerVersion* activating_version,
const StatusCallback& completion_callback,

Powered by Google App Engine
This is Rietveld 408576698