Chromium Code Reviews| 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..b9eb8e5292e9adf449b043fbb66e14b9986a47d3 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,14 @@ void ServiceWorkerRegistration::UnsetVersion(ServiceWorkerVersion* version) { |
| } |
| } |
| +void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) { |
|
michaeln
2014/07/29 03:33:39
our CL's collide on this method :(
so we'll have
|
| + DCHECK_EQ(active_version(), version); |
| + version->RemoveListener(this); |
| + if (!is_uninstalling()) |
| + return; |
| + Clear(); |
| +} |
| + |
| void ServiceWorkerRegistration::SetVersionInternal( |
| ServiceWorkerVersion* version, |
| scoped_refptr<ServiceWorkerVersion>* data_member, |
| @@ -164,6 +173,47 @@ void ServiceWorkerRegistration::ActivateWaitingVersion( |
| this, activating_version, completion_callback)); |
| } |
| +void ServiceWorkerRegistration::ClearWhenReady() { |
| + DCHECK(context_); |
| + if (is_uninstalling()) |
| + return; |
| + is_uninstalling_ = true; |
| + context_->storage()->NotifyUninstallingRegistration(this); |
| + |
| + // Delete from DB in case browser dies before we're ready. |
| + context_->storage()->DeleteRegistration( |
| + id(), |
| + script_url().GetOrigin(), |
| + base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| + |
| + if (active_version() && active_version()->HasControllee()) |
| + active_version()->AddListener(this); |
| + else |
| + Clear(); |
| +} |
| + |
| +void ServiceWorkerRegistration::AbortPendingClear() { |
| + DCHECK(context_); |
| + if (!is_uninstalling()) |
| + return; |
| + is_uninstalling_ = false; |
| + context_->storage()->NotifyDoneUninstallingRegistration(this); |
| + |
| + if (waiting_version()) { |
| + context_->storage()->StoreRegistration( |
| + this, |
| + waiting_version(), |
| + base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| + return; |
| + } |
| + if (active_version()) { |
| + context_->storage()->StoreRegistration( |
| + this, |
| + active_version(), |
| + base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| + } |
| +} |
| + |
| void ServiceWorkerRegistration::OnActivateEventFinished( |
| ServiceWorkerVersion* activating_version, |
| const StatusCallback& completion_callback, |
| @@ -198,4 +248,26 @@ void ServiceWorkerRegistration::OnActivateEventFinished( |
| completion_callback.Run(SERVICE_WORKER_OK); |
| } |
| +void ServiceWorkerRegistration::Clear() { |
| + DCHECK(is_uninstalling()); |
| + if (!context_) |
| + return; |
| + |
| + context_->storage()->NotifyDoneUninstallingRegistration(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 |