Chromium Code Reviews| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "content/browser/service_worker/embedded_worker_status.h" | 9 #include "content/browser/service_worker/embedded_worker_status.h" |
| 10 #include "content/browser/service_worker/service_worker_context_core.h" | 10 #include "content/browser/service_worker/service_worker_context_core.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 | 71 |
| 72 void ServiceWorkerRegistration::AddListener(Listener* listener) { | 72 void ServiceWorkerRegistration::AddListener(Listener* listener) { |
| 73 listeners_.AddObserver(listener); | 73 listeners_.AddObserver(listener); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ServiceWorkerRegistration::RemoveListener(Listener* listener) { | 76 void ServiceWorkerRegistration::RemoveListener(Listener* listener) { |
| 77 listeners_.RemoveObserver(listener); | 77 listeners_.RemoveObserver(listener); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void ServiceWorkerRegistration::NotifyRegistrationFailed() { | 80 void ServiceWorkerRegistration::NotifyRegistrationFailed() { |
| 81 FOR_EACH_OBSERVER(Listener, listeners_, OnRegistrationFailed(this)); | 81 for (auto& observer : listeners_) |
| 82 observer.OnRegistrationFailed(this); | |
| 82 NotifyRegistrationFinished(); | 83 NotifyRegistrationFinished(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void ServiceWorkerRegistration::NotifyUpdateFound() { | 86 void ServiceWorkerRegistration::NotifyUpdateFound() { |
| 86 FOR_EACH_OBSERVER(Listener, listeners_, OnUpdateFound(this)); | 87 for (auto& observer : listeners_) |
| 88 observer.OnUpdateFound(this); | |
| 87 } | 89 } |
| 88 | 90 |
| 89 void ServiceWorkerRegistration::NotifyVersionAttributesChanged( | 91 void ServiceWorkerRegistration::NotifyVersionAttributesChanged( |
| 90 ChangedVersionAttributesMask mask) { | 92 ChangedVersionAttributesMask mask) { |
| 91 FOR_EACH_OBSERVER(Listener, listeners_, | 93 for (auto& observer : listeners_) |
| 92 OnVersionAttributesChanged(this, mask, GetInfo())); | 94 observer.OnVersionAttributesChanged(this, mask, GetInfo()); |
| 93 if (mask.active_changed() || mask.waiting_changed()) | 95 if (mask.active_changed() || mask.waiting_changed()) |
| 94 NotifyRegistrationFinished(); | 96 NotifyRegistrationFinished(); |
| 95 } | 97 } |
| 96 | 98 |
| 97 ServiceWorkerRegistrationInfo ServiceWorkerRegistration::GetInfo() { | 99 ServiceWorkerRegistrationInfo ServiceWorkerRegistration::GetInfo() { |
| 98 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 100 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 99 return ServiceWorkerRegistrationInfo( | 101 return ServiceWorkerRegistrationInfo( |
| 100 pattern(), registration_id_, | 102 pattern(), registration_id_, |
| 101 is_deleted_ ? ServiceWorkerRegistrationInfo::IS_DELETED | 103 is_deleted_ ? ServiceWorkerRegistrationInfo::IS_DELETED |
| 102 : ServiceWorkerRegistrationInfo::IS_NOT_DELETED, | 104 : ServiceWorkerRegistrationInfo::IS_NOT_DELETED, |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 } | 309 } |
| 308 | 310 |
| 309 // "6. Set serviceWorkerRegistration.activeWorker to activatingWorker." | 311 // "6. Set serviceWorkerRegistration.activeWorker to activatingWorker." |
| 310 // "7. Set serviceWorkerRegistration.waitingWorker to null." | 312 // "7. Set serviceWorkerRegistration.waitingWorker to null." |
| 311 SetActiveVersion(activating_version); | 313 SetActiveVersion(activating_version); |
| 312 | 314 |
| 313 // "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and | 315 // "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and |
| 314 // "activating" as arguments." | 316 // "activating" as arguments." |
| 315 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); | 317 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); |
| 316 // "9. Fire a simple event named controllerchange..." | 318 // "9. Fire a simple event named controllerchange..." |
| 317 if (activating_version->skip_waiting()) | 319 if (activating_version->skip_waiting()) |
|
horo
2016/10/17 02:22:28
Nit: please add bracket.
if (activating_version
| |
| 318 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); | 320 for (auto& observer : listeners_) |
| 321 observer.OnSkippedWaiting(this); | |
| 319 | 322 |
| 320 // "10. Queue a task to fire an event named activate..." | 323 // "10. Queue a task to fire an event named activate..." |
| 321 // The browser could be shutting down. To avoid spurious start worker | 324 // The browser could be shutting down. To avoid spurious start worker |
| 322 // failures, wait a bit before continuing. | 325 // failures, wait a bit before continuing. |
| 323 if (delay) { | 326 if (delay) { |
| 324 task_runner_->PostDelayedTask( | 327 task_runner_->PostDelayedTask( |
| 325 FROM_HERE, base::Bind(&ServiceWorkerRegistration::ContinueActivation, | 328 FROM_HERE, base::Bind(&ServiceWorkerRegistration::ContinueActivation, |
| 326 this, activating_version), | 329 this, activating_version), |
| 327 base::TimeDelta::FromSeconds(1)); | 330 base::TimeDelta::FromSeconds(1)); |
| 328 } else { | 331 } else { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 if (mask.changed()) { | 484 if (mask.changed()) { |
| 482 NotifyVersionAttributesChanged(mask); | 485 NotifyVersionAttributesChanged(mask); |
| 483 | 486 |
| 484 // Doom only after notifying attributes changed, because the spec requires | 487 // Doom only after notifying attributes changed, because the spec requires |
| 485 // the attributes to be cleared by the time the statechange event is | 488 // the attributes to be cleared by the time the statechange event is |
| 486 // dispatched. | 489 // dispatched. |
| 487 for (const auto& version : versions_to_doom) | 490 for (const auto& version : versions_to_doom) |
| 488 version->Doom(); | 491 version->Doom(); |
| 489 } | 492 } |
| 490 | 493 |
| 491 FOR_EACH_OBSERVER( | 494 for (auto& observer : listeners_) |
| 492 Listener, listeners_, OnRegistrationFinishedUninstalling(this)); | 495 observer.OnRegistrationFinishedUninstalling(this); |
| 493 } | 496 } |
| 494 | 497 |
| 495 void ServiceWorkerRegistration::OnRestoreFinished( | 498 void ServiceWorkerRegistration::OnRestoreFinished( |
| 496 const StatusCallback& callback, | 499 const StatusCallback& callback, |
| 497 scoped_refptr<ServiceWorkerVersion> version, | 500 scoped_refptr<ServiceWorkerVersion> version, |
| 498 ServiceWorkerStatusCode status) { | 501 ServiceWorkerStatusCode status) { |
| 499 if (!context_) { | 502 if (!context_) { |
| 500 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 503 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 501 return; | 504 return; |
| 502 } | 505 } |
| 503 context_->storage()->NotifyDoneInstallingRegistration( | 506 context_->storage()->NotifyDoneInstallingRegistration( |
| 504 this, version.get(), status); | 507 this, version.get(), status); |
| 505 callback.Run(status); | 508 callback.Run(status); |
| 506 } | 509 } |
| 507 | 510 |
| 508 } // namespace content | 511 } // namespace content |
| OLD | NEW |