| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/service_worker/service_worker_registration.h" | 5 #include "content/browser/service_worker/service_worker_registration.h" |
| 6 | 6 |
| 7 #include "content/browser/service_worker/service_worker_context_core.h" | 7 #include "content/browser/service_worker/service_worker_context_core.h" |
| 8 #include "content/browser/service_worker/service_worker_info.h" | 8 #include "content/browser/service_worker/service_worker_info.h" |
| 9 #include "content/browser/service_worker/service_worker_register_job.h" | 9 #include "content/browser/service_worker/service_worker_register_job.h" |
| 10 #include "content/browser/service_worker/service_worker_utils.h" | 10 #include "content/browser/service_worker/service_worker_utils.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 DCHECK(context_); | 150 DCHECK(context_); |
| 151 if (is_uninstalling_) | 151 if (is_uninstalling_) |
| 152 return; | 152 return; |
| 153 is_uninstalling_ = true; | 153 is_uninstalling_ = true; |
| 154 | 154 |
| 155 context_->storage()->NotifyUninstallingRegistration(this); | 155 context_->storage()->NotifyUninstallingRegistration(this); |
| 156 context_->storage()->DeleteRegistration( | 156 context_->storage()->DeleteRegistration( |
| 157 id(), | 157 id(), |
| 158 script_url().GetOrigin(), | 158 script_url().GetOrigin(), |
| 159 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 159 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 160 | |
| 161 if (!active_version() || !active_version()->HasControllee()) | 160 if (!active_version() || !active_version()->HasControllee()) |
| 162 Clear(); | 161 Clear(); |
| 163 } | 162 } |
| 164 | 163 |
| 165 void ServiceWorkerRegistration::AbortPendingClear() { | 164 void ServiceWorkerRegistration::AbortPendingClear( |
| 165 const StatusCallback& callback) { |
| 166 DCHECK(context_); | 166 DCHECK(context_); |
| 167 if (!is_uninstalling()) | 167 if (!is_uninstalling()) { |
| 168 callback.Run(SERVICE_WORKER_OK); |
| 168 return; | 169 return; |
| 170 } |
| 169 is_uninstalling_ = false; | 171 is_uninstalling_ = false; |
| 170 context_->storage()->NotifyDoneUninstallingRegistration(this); | 172 context_->storage()->NotifyDoneUninstallingRegistration(this); |
| 171 | 173 |
| 172 scoped_refptr<ServiceWorkerVersion> most_recent_version = | 174 scoped_refptr<ServiceWorkerVersion> most_recent_version = |
| 173 waiting_version() ? waiting_version() : active_version(); | 175 waiting_version() ? waiting_version() : active_version(); |
| 174 DCHECK(most_recent_version); | 176 DCHECK(most_recent_version); |
| 175 context_->storage()->NotifyInstallingRegistration(this); | 177 context_->storage()->NotifyInstallingRegistration(this); |
| 176 context_->storage()->StoreRegistration( | 178 context_->storage()->StoreRegistration( |
| 177 this, | 179 this, |
| 178 most_recent_version, | 180 most_recent_version, |
| 179 base::Bind(&ServiceWorkerRegistration::OnStoreFinished, | 181 base::Bind(&ServiceWorkerRegistration::OnRestoreFinished, |
| 180 this, | 182 this, |
| 183 callback, |
| 181 most_recent_version)); | 184 most_recent_version)); |
| 182 } | 185 } |
| 183 | 186 |
| 184 void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) { | 187 void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) { |
| 185 DCHECK_EQ(active_version(), version); | 188 DCHECK_EQ(active_version(), version); |
| 186 if (is_uninstalling_) | 189 if (is_uninstalling_) |
| 187 Clear(); | 190 Clear(); |
| 188 else if (should_activate_when_ready_) | 191 else if (should_activate_when_ready_) |
| 189 ActivateWaitingVersion(); | 192 ActivateWaitingVersion(); |
| 190 is_uninstalling_ = false; | 193 is_uninstalling_ = false; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 269 } |
| 267 } | 270 } |
| 268 | 271 |
| 269 void ServiceWorkerRegistration::OnDeleteFinished( | 272 void ServiceWorkerRegistration::OnDeleteFinished( |
| 270 ServiceWorkerStatusCode status) { | 273 ServiceWorkerStatusCode status) { |
| 271 // Intentionally empty completion callback, used to prevent | 274 // Intentionally empty completion callback, used to prevent |
| 272 // |this| from being deleted until the storage method completes. | 275 // |this| from being deleted until the storage method completes. |
| 273 } | 276 } |
| 274 | 277 |
| 275 void ServiceWorkerRegistration::Clear() { | 278 void ServiceWorkerRegistration::Clear() { |
| 276 context_->storage()->NotifyDoneUninstallingRegistration(this); | 279 is_uninstalling_ = false; |
| 280 if (context_) |
| 281 context_->storage()->NotifyDoneUninstallingRegistration(this); |
| 277 | 282 |
| 278 ChangedVersionAttributesMask mask; | 283 ChangedVersionAttributesMask mask; |
| 279 if (installing_version_) { | 284 if (installing_version_) { |
| 280 installing_version_->Doom(); | 285 installing_version_->Doom(); |
| 281 installing_version_ = NULL; | 286 installing_version_ = NULL; |
| 282 mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION); | 287 mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION); |
| 283 } | 288 } |
| 284 if (waiting_version_) { | 289 if (waiting_version_) { |
| 285 waiting_version_->Doom(); | 290 waiting_version_->Doom(); |
| 286 waiting_version_ = NULL; | 291 waiting_version_ = NULL; |
| 287 mask.add(ChangedVersionAttributesMask::WAITING_VERSION); | 292 mask.add(ChangedVersionAttributesMask::WAITING_VERSION); |
| 288 } | 293 } |
| 289 if (active_version_) { | 294 if (active_version_) { |
| 290 active_version_->Doom(); | 295 active_version_->Doom(); |
| 291 active_version_->RemoveListener(this); | 296 active_version_->RemoveListener(this); |
| 292 active_version_ = NULL; | 297 active_version_ = NULL; |
| 293 mask.add(ChangedVersionAttributesMask::ACTIVE_VERSION); | 298 mask.add(ChangedVersionAttributesMask::ACTIVE_VERSION); |
| 294 } | 299 } |
| 295 if (mask.changed()) { | 300 if (mask.changed()) { |
| 296 ServiceWorkerRegistrationInfo info = GetInfo(); | 301 ServiceWorkerRegistrationInfo info = GetInfo(); |
| 297 FOR_EACH_OBSERVER(Listener, listeners_, | 302 FOR_EACH_OBSERVER(Listener, listeners_, |
| 298 OnVersionAttributesChanged(this, mask, info)); | 303 OnVersionAttributesChanged(this, mask, info)); |
| 299 } | 304 } |
| 305 |
| 306 FOR_EACH_OBSERVER( |
| 307 Listener, listeners_, OnRegistrationFinishedUninstalling(this)); |
| 300 } | 308 } |
| 301 | 309 |
| 302 void ServiceWorkerRegistration::OnStoreFinished( | 310 void ServiceWorkerRegistration::OnRestoreFinished( |
| 311 const StatusCallback& callback, |
| 303 scoped_refptr<ServiceWorkerVersion> version, | 312 scoped_refptr<ServiceWorkerVersion> version, |
| 304 ServiceWorkerStatusCode status) { | 313 ServiceWorkerStatusCode status) { |
| 305 if (!context_) | 314 if (!context_) { |
| 315 callback.Run(ServiceWorkerStatusCode::SERVICE_WORKER_ERROR_ABORT); |
| 306 return; | 316 return; |
| 317 } |
| 307 context_->storage()->NotifyDoneInstallingRegistration( | 318 context_->storage()->NotifyDoneInstallingRegistration( |
| 308 this, version.get(), status); | 319 this, version.get(), status); |
| 320 callback.Run(status); |
| 309 } | 321 } |
| 310 | 322 |
| 311 } // namespace content | 323 } // namespace content |
| OLD | NEW |