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

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: more cleanup Created 6 years, 4 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 9cd539d42567ca84cdd523fe209973bd1cd293e3..3fdd29cca3cbe739319aedcfc75bbca2c6af7562 100644
--- a/content/browser/service_worker/service_worker_registration.cc
+++ b/content/browser/service_worker/service_worker_registration.cc
@@ -31,6 +31,7 @@ ServiceWorkerRegistration::ServiceWorkerRegistration(
script_url_(script_url),
registration_id_(registration_id),
is_deleted_(false),
+ is_uninstalling_(false),
should_activate_when_ready_(false),
context_(context) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
@@ -42,7 +43,8 @@ ServiceWorkerRegistration::~ServiceWorkerRegistration() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (context_)
context_->RemoveLiveRegistration(registration_id_);
- ResetShouldActivateWhenReady();
+ if (active_version())
+ active_version()->RemoveListener(this);
}
void ServiceWorkerRegistration::AddListener(Listener* listener) {
@@ -66,14 +68,14 @@ ServiceWorkerRegistrationInfo ServiceWorkerRegistration::GetInfo() {
void ServiceWorkerRegistration::SetActiveVersion(
ServiceWorkerVersion* version) {
- ResetShouldActivateWhenReady();
+ should_activate_when_ready_ = false;
SetVersionInternal(version, &active_version_,
ChangedVersionAttributesMask::ACTIVE_VERSION);
}
void ServiceWorkerRegistration::SetWaitingVersion(
ServiceWorkerVersion* version) {
- ResetShouldActivateWhenReady();
+ should_activate_when_ready_ = false;
SetVersionInternal(version, &waiting_version_,
ChangedVersionAttributesMask::WAITING_VERSION);
}
@@ -107,6 +109,8 @@ void ServiceWorkerRegistration::SetVersionInternal(
if (version)
UnsetVersionInternal(version, &mask);
*data_member = version;
+ if (active_version_ && active_version_ == version)
+ active_version_->AddListener(this);
mask.add(change_flag);
ServiceWorkerRegistrationInfo info = GetInfo();
FOR_EACH_OBSERVER(Listener, listeners_,
@@ -124,6 +128,7 @@ void ServiceWorkerRegistration::UnsetVersionInternal(
waiting_version_ = NULL;
mask->add(ChangedVersionAttributesMask::WAITING_VERSION);
} else if (active_version_ == version) {
+ active_version_->RemoveListener(this);
active_version_ = NULL;
mask->add(ChangedVersionAttributesMask::ACTIVE_VERSION);
}
@@ -131,27 +136,26 @@ void ServiceWorkerRegistration::UnsetVersionInternal(
void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() {
DCHECK(waiting_version());
- if (should_activate_when_ready_)
- return;
- if (active_version() && active_version()->HasControllee()) {
- active_version()->AddListener(this);
- should_activate_when_ready_ = true;
- return;
- }
- ActivateWaitingVersion();
+ should_activate_when_ready_ = true;
+ if (!active_version() || !active_version()->HasControllee())
+ ActivateWaitingVersion();
}
void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) {
DCHECK_EQ(active_version(), version);
- DCHECK(should_activate_when_ready_);
- active_version_->RemoveListener(this);
+ if (is_uninstalling_)
+ Clear();
+ else if (should_activate_when_ready_)
+ ActivateWaitingVersion();
+ is_uninstalling_ = false;
should_activate_when_ready_ = false;
- ActivateWaitingVersion();
}
void ServiceWorkerRegistration::ActivateWaitingVersion() {
DCHECK(context_);
DCHECK(waiting_version());
+ DCHECK(should_activate_when_ready_);
+ should_activate_when_ready_ = false;
scoped_refptr<ServiceWorkerVersion> activating_version = waiting_version();
scoped_refptr<ServiceWorkerVersion> exiting_version = active_version();
@@ -193,6 +197,25 @@ void ServiceWorkerRegistration::ActivateWaitingVersion() {
this, activating_version));
}
+void ServiceWorkerRegistration::ClearWhenReady() {
+ DCHECK(context_);
+ if (is_uninstalling_)
+ return;
+ is_uninstalling_ = true;
+ context_->storage()->NotifyUninstallingRegistration(this);
michaeln 2014/08/12 02:15:35 I think the call to DeleteRegistration(id()) shoul
falken 2014/08/12 09:06:06 I see your point. Done.
+
+ if (!active_version() || !active_version()->HasControllee())
+ Clear();
+}
+
+void ServiceWorkerRegistration::AbortPendingClear() {
+ DCHECK(context_);
+ if (!is_uninstalling())
+ return;
+ is_uninstalling_ = false;
+ context_->storage()->NotifyAbortedUninstallingRegistration(this);
michaeln 2014/08/12 02:15:35 Ditto the call to (re) StoreRegistration() should
falken 2014/08/12 09:06:06 Done.
+}
+
void ServiceWorkerRegistration::OnActivateEventFinished(
ServiceWorkerVersion* activating_version,
ServiceWorkerStatusCode status) {
@@ -228,17 +251,29 @@ void ServiceWorkerRegistration::OnActivateEventFinished(
}
}
-void ServiceWorkerRegistration::ResetShouldActivateWhenReady() {
- if (should_activate_when_ready_) {
- active_version()->RemoveListener(this);
- should_activate_when_ready_ = false;
- }
-}
-
void ServiceWorkerRegistration::OnDeleteFinished(
ServiceWorkerStatusCode status) {
// Intentionally empty completion callback, used to prevent
// |this| from being deleted until the storage method completes.
}
+void ServiceWorkerRegistration::Clear() {
+ context_->storage()->NotifyUninstalledRegistration(this);
+
+ if (installing_version()) {
+ installing_version()->Doom();
+ UnsetVersion(installing_version());
+ }
+
+ if (waiting_version()) {
+ waiting_version()->Doom();
+ UnsetVersion(waiting_version());
+ }
+
+ if (active_version()) {
+ active_version()->Doom();
+ UnsetVersion(active_version());
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698