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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 exiting_version->StopWorker( | 265 exiting_version->StopWorker( |
266 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 266 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
267 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and | 267 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and |
268 // "redundant" as the arguments." | 268 // "redundant" as the arguments." |
269 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); | 269 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); |
270 } | 270 } |
271 | 271 |
272 // "6. Set serviceWorkerRegistration.activeWorker to activatingWorker." | 272 // "6. Set serviceWorkerRegistration.activeWorker to activatingWorker." |
273 // "7. Set serviceWorkerRegistration.waitingWorker to null." | 273 // "7. Set serviceWorkerRegistration.waitingWorker to null." |
274 SetActiveVersion(activating_version.get()); | 274 SetActiveVersion(activating_version.get()); |
| 275 FOR_EACH_OBSERVER(Listener, listeners_, OnActivateVersion(this)); |
275 | 276 |
276 // "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and | 277 // "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and |
277 // "activating" as arguments." | 278 // "activating" as arguments." |
278 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); | 279 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); |
279 // "9. Fire a simple event named controllerchange..." | 280 // "9. Fire a simple event named controllerchange..." |
280 if (activating_version->skip_waiting()) | 281 if (activating_version->skip_waiting()) |
281 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); | 282 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); |
282 | 283 |
283 // "10. Queue a task to fire an event named activate..." | 284 // "10. Queue a task to fire an event named activate..." |
284 activating_version->DispatchActivateEvent( | 285 activating_version->DispatchActivateEvent( |
(...skipping 11 matching lines...) Expand all Loading... |
296 if (status != SERVICE_WORKER_OK) { | 297 if (status != SERVICE_WORKER_OK) { |
297 // "11. If activateFailed is true, then:..." | 298 // "11. If activateFailed is true, then:..." |
298 UnsetVersion(activating_version); | 299 UnsetVersion(activating_version); |
299 activating_version->Doom(); | 300 activating_version->Doom(); |
300 if (!waiting_version()) { | 301 if (!waiting_version()) { |
301 // Delete the records from the db. | 302 // Delete the records from the db. |
302 context_->storage()->DeleteRegistration( | 303 context_->storage()->DeleteRegistration( |
303 id(), pattern().GetOrigin(), | 304 id(), pattern().GetOrigin(), |
304 base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this)); | 305 base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this)); |
305 // But not from memory if there is a version in the pipeline. | 306 // But not from memory if there is a version in the pipeline. |
306 if (installing_version()) | 307 if (installing_version()) { |
307 is_deleted_ = false; | 308 is_deleted_ = false; |
308 else | 309 } else { |
309 is_uninstalled_ = true; | 310 is_uninstalled_ = true; |
| 311 FOR_EACH_OBSERVER(Listener, listeners_, OnRegistrationFailed(this)); |
| 312 } |
310 } | 313 } |
311 return; | 314 return; |
312 } | 315 } |
313 | 316 |
314 // "12. Run the [[UpdateState]] algorithm passing registration.activeWorker | 317 // "12. Run the [[UpdateState]] algorithm passing registration.activeWorker |
315 // and "activated" as the arguments." | 318 // and "activated" as the arguments." |
316 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); | 319 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); |
317 if (context_) { | 320 if (context_) { |
318 context_->storage()->UpdateToActiveState( | 321 context_->storage()->UpdateToActiveState( |
319 this, | 322 this, |
(...skipping 28 matching lines...) Expand all Loading... |
348 active_version_->Doom(); | 351 active_version_->Doom(); |
349 active_version_->RemoveListener(this); | 352 active_version_->RemoveListener(this); |
350 active_version_ = NULL; | 353 active_version_ = NULL; |
351 mask.add(ChangedVersionAttributesMask::ACTIVE_VERSION); | 354 mask.add(ChangedVersionAttributesMask::ACTIVE_VERSION); |
352 } | 355 } |
353 if (mask.changed()) { | 356 if (mask.changed()) { |
354 ServiceWorkerRegistrationInfo info = GetInfo(); | 357 ServiceWorkerRegistrationInfo info = GetInfo(); |
355 FOR_EACH_OBSERVER(Listener, listeners_, | 358 FOR_EACH_OBSERVER(Listener, listeners_, |
356 OnVersionAttributesChanged(this, mask, info)); | 359 OnVersionAttributesChanged(this, mask, info)); |
357 } | 360 } |
| 361 |
| 362 FOR_EACH_OBSERVER( |
| 363 Listener, listeners_, OnRegistrationFinishedUninstalling(this)); |
358 } | 364 } |
359 | 365 |
360 void ServiceWorkerRegistration::OnRestoreFinished( | 366 void ServiceWorkerRegistration::OnRestoreFinished( |
361 const StatusCallback& callback, | 367 const StatusCallback& callback, |
362 scoped_refptr<ServiceWorkerVersion> version, | 368 scoped_refptr<ServiceWorkerVersion> version, |
363 ServiceWorkerStatusCode status) { | 369 ServiceWorkerStatusCode status) { |
364 if (!context_) { | 370 if (!context_) { |
365 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 371 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
366 return; | 372 return; |
367 } | 373 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 if (registration && | 416 if (registration && |
411 (registration->is_uninstalling() || registration->is_uninstalled())) | 417 (registration->is_uninstalling() || registration->is_uninstalled())) |
412 continue; | 418 continue; |
413 if (matcher.MatchLongest(info.pattern)) | 419 if (matcher.MatchLongest(info.pattern)) |
414 return false; | 420 return false; |
415 } | 421 } |
416 return true; | 422 return true; |
417 } | 423 } |
418 | 424 |
419 } // namespace content | 425 } // namespace content |
OLD | NEW |