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