| 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 |
| 160 if (!active_version() || !active_version()->HasControllee()) | 161 if (!active_version() || !active_version()->HasControllee()) |
| 161 Clear(); | 162 Clear(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 void ServiceWorkerRegistration::AbortPendingClear( | 165 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); | |
| 169 return; | 168 return; |
| 170 } | |
| 171 is_uninstalling_ = false; | 169 is_uninstalling_ = false; |
| 172 context_->storage()->NotifyDoneUninstallingRegistration(this); | 170 context_->storage()->NotifyDoneUninstallingRegistration(this); |
| 173 | 171 |
| 174 scoped_refptr<ServiceWorkerVersion> most_recent_version = | 172 scoped_refptr<ServiceWorkerVersion> most_recent_version = |
| 175 waiting_version() ? waiting_version() : active_version(); | 173 waiting_version() ? waiting_version() : active_version(); |
| 176 DCHECK(most_recent_version); | 174 DCHECK(most_recent_version); |
| 177 context_->storage()->NotifyInstallingRegistration(this); | 175 context_->storage()->NotifyInstallingRegistration(this); |
| 178 context_->storage()->StoreRegistration( | 176 context_->storage()->StoreRegistration( |
| 179 this, | 177 this, |
| 180 most_recent_version, | 178 most_recent_version, |
| 181 base::Bind(&ServiceWorkerRegistration::OnRestoreFinished, | 179 base::Bind(&ServiceWorkerRegistration::OnStoreFinished, |
| 182 this, | 180 this, |
| 183 callback, | |
| 184 most_recent_version)); | 181 most_recent_version)); |
| 185 } | 182 } |
| 186 | 183 |
| 187 void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) { | 184 void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) { |
| 188 DCHECK_EQ(active_version(), version); | 185 DCHECK_EQ(active_version(), version); |
| 189 if (is_uninstalling_) | 186 if (is_uninstalling_) |
| 190 Clear(); | 187 Clear(); |
| 191 else if (should_activate_when_ready_) | 188 else if (should_activate_when_ready_) |
| 192 ActivateWaitingVersion(); | 189 ActivateWaitingVersion(); |
| 193 is_uninstalling_ = false; | 190 is_uninstalling_ = false; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 266 } |
| 270 } | 267 } |
| 271 | 268 |
| 272 void ServiceWorkerRegistration::OnDeleteFinished( | 269 void ServiceWorkerRegistration::OnDeleteFinished( |
| 273 ServiceWorkerStatusCode status) { | 270 ServiceWorkerStatusCode status) { |
| 274 // Intentionally empty completion callback, used to prevent | 271 // Intentionally empty completion callback, used to prevent |
| 275 // |this| from being deleted until the storage method completes. | 272 // |this| from being deleted until the storage method completes. |
| 276 } | 273 } |
| 277 | 274 |
| 278 void ServiceWorkerRegistration::Clear() { | 275 void ServiceWorkerRegistration::Clear() { |
| 279 is_uninstalling_ = false; | 276 context_->storage()->NotifyDoneUninstallingRegistration(this); |
| 280 if (context_) | |
| 281 context_->storage()->NotifyDoneUninstallingRegistration(this); | |
| 282 | 277 |
| 283 ChangedVersionAttributesMask mask; | 278 ChangedVersionAttributesMask mask; |
| 284 if (installing_version_) { | 279 if (installing_version_) { |
| 285 installing_version_->Doom(); | 280 installing_version_->Doom(); |
| 286 installing_version_ = NULL; | 281 installing_version_ = NULL; |
| 287 mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION); | 282 mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION); |
| 288 } | 283 } |
| 289 if (waiting_version_) { | 284 if (waiting_version_) { |
| 290 waiting_version_->Doom(); | 285 waiting_version_->Doom(); |
| 291 waiting_version_ = NULL; | 286 waiting_version_ = NULL; |
| 292 mask.add(ChangedVersionAttributesMask::WAITING_VERSION); | 287 mask.add(ChangedVersionAttributesMask::WAITING_VERSION); |
| 293 } | 288 } |
| 294 if (active_version_) { | 289 if (active_version_) { |
| 295 active_version_->Doom(); | 290 active_version_->Doom(); |
| 296 active_version_->RemoveListener(this); | 291 active_version_->RemoveListener(this); |
| 297 active_version_ = NULL; | 292 active_version_ = NULL; |
| 298 mask.add(ChangedVersionAttributesMask::ACTIVE_VERSION); | 293 mask.add(ChangedVersionAttributesMask::ACTIVE_VERSION); |
| 299 } | 294 } |
| 300 if (mask.changed()) { | 295 if (mask.changed()) { |
| 301 ServiceWorkerRegistrationInfo info = GetInfo(); | 296 ServiceWorkerRegistrationInfo info = GetInfo(); |
| 302 FOR_EACH_OBSERVER(Listener, listeners_, | 297 FOR_EACH_OBSERVER(Listener, listeners_, |
| 303 OnVersionAttributesChanged(this, mask, info)); | 298 OnVersionAttributesChanged(this, mask, info)); |
| 304 } | 299 } |
| 305 | |
| 306 FOR_EACH_OBSERVER( | |
| 307 Listener, listeners_, OnRegistrationFinishedUninstalling(this)); | |
| 308 } | 300 } |
| 309 | 301 |
| 310 void ServiceWorkerRegistration::OnRestoreFinished( | 302 void ServiceWorkerRegistration::OnStoreFinished( |
| 311 const StatusCallback& callback, | |
| 312 scoped_refptr<ServiceWorkerVersion> version, | 303 scoped_refptr<ServiceWorkerVersion> version, |
| 313 ServiceWorkerStatusCode status) { | 304 ServiceWorkerStatusCode status) { |
| 314 if (!context_) { | 305 if (!context_) |
| 315 callback.Run(ServiceWorkerStatusCode::SERVICE_WORKER_ERROR_ABORT); | |
| 316 return; | 306 return; |
| 317 } | |
| 318 context_->storage()->NotifyDoneInstallingRegistration( | 307 context_->storage()->NotifyDoneInstallingRegistration( |
| 319 this, version.get(), status); | 308 this, version.get(), status); |
| 320 callback.Run(status); | |
| 321 } | 309 } |
| 322 | 310 |
| 323 } // namespace content | 311 } // namespace content |
| OLD | NEW |