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 4f5e6113b327e454adeb5ea71ef157a8b6f7073e..ba89eecdbbce1160c0ea8e5e46c82b14f7c5d951 100644 |
| --- a/content/browser/service_worker/service_worker_registration.cc |
| +++ b/content/browser/service_worker/service_worker_registration.cc |
| @@ -302,6 +302,45 @@ void ServiceWorkerRegistration::ActivateWaitingVersion() { |
| this, activating_version)); |
| } |
| +void ServiceWorkerRegistration::DeleteVersion( |
| + const scoped_refptr<ServiceWorkerVersion>& version) { |
|
nhiroki
2015/04/27 04:24:25
ServiceWorkerRegisterJob::CompleteInternal seems t
falken
2015/04/27 04:58:16
Yes good point, these are pretty similar. I'll see
|
| + DCHECK_EQ(id(), version->registration_id()); |
| + |
| + // "Set registration's active worker to null." (The spec's step order may |
| + // differ. It's OK because the other steps queue a task.) |
| + UnsetVersion(version.get()); |
| + |
| + // "Run the Update State algorithm passing registration's active worker and |
| + // 'redundant' as the arguments." |
| + version->SetStatus(ServiceWorkerVersion::REDUNDANT); |
| + |
| + // "For each service worker client client whose active worker is |
| + // registration's active worker..." set the active worker to null. |
| + for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
| + context_->GetProviderHostIterator(); |
| + !it->IsAtEnd(); it->Advance()) { |
| + ServiceWorkerProviderHost* host = it->GetProviderHost(); |
| + if (host->controlling_version() == version) |
| + host->NotifyControllerActivationFailed(); |
| + } |
| + |
| + version->Doom(); |
| + |
| + if (!active_version() && !waiting_version()) { |
| + // Delete the records from the db. |
| + context_->storage()->DeleteRegistration( |
| + id(), pattern().GetOrigin(), |
| + base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this)); |
| + // But not from memory if there is a version in the pipeline. |
| + if (installing_version()) { |
| + is_deleted_ = false; |
| + } else { |
| + is_uninstalled_ = true; |
| + FOR_EACH_OBSERVER(Listener, listeners_, OnRegistrationFailed(this)); |
| + } |
| + } |
| +} |
| + |
| void ServiceWorkerRegistration::OnActivateEventFinished( |
| ServiceWorkerVersion* activating_version, |
| ServiceWorkerStatusCode status) { |
| @@ -311,38 +350,7 @@ void ServiceWorkerRegistration::OnActivateEventFinished( |
| // "If activateFailed is true, then:..." |
| if (status != SERVICE_WORKER_OK) { |
| - // "Set registration's active worker to null." (The spec's step order may |
| - // differ. It's OK because the other steps queue a task.) |
| - UnsetVersion(activating_version); |
| - |
| - // "Run the Update State algorithm passing registration's active worker and |
| - // 'redundant' as the arguments." |
| - activating_version->SetStatus(ServiceWorkerVersion::REDUNDANT); |
| - |
| - // "For each service worker client client whose active worker is |
| - // registration's active worker..." set the active worker to null. |
| - for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
| - context_->GetProviderHostIterator(); |
| - !it->IsAtEnd(); it->Advance()) { |
| - ServiceWorkerProviderHost* host = it->GetProviderHost(); |
| - if (host->controlling_version() == activating_version) |
| - host->NotifyControllerActivationFailed(); |
| - } |
| - |
| - activating_version->Doom(); |
| - if (!waiting_version()) { |
| - // Delete the records from the db. |
| - context_->storage()->DeleteRegistration( |
| - id(), pattern().GetOrigin(), |
| - base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this)); |
| - // But not from memory if there is a version in the pipeline. |
| - if (installing_version()) { |
| - is_deleted_ = false; |
| - } else { |
| - is_uninstalled_ = true; |
| - FOR_EACH_OBSERVER(Listener, listeners_, OnRegistrationFailed(this)); |
| - } |
| - } |
| + DeleteVersion(make_scoped_refptr(activating_version)); |
| return; |
| } |