Index: content/browser/service_worker/service_worker_register_job.cc |
diff --git a/content/browser/service_worker/service_worker_register_job.cc b/content/browser/service_worker/service_worker_register_job.cc |
index a42706e8482a5f6944a7c406c88fc80f1a22b8e9..97e0ce9c96c55f024ac847b0619311a8ebd128eb 100644 |
--- a/content/browser/service_worker/service_worker_register_job.cc |
+++ b/content/browser/service_worker/service_worker_register_job.cc |
@@ -229,7 +229,6 @@ void ServiceWorkerRegisterJob::UpdateAndContinue( |
// then terminate the installing worker. It doesn't make sense to implement |
// yet since we always activate the worker if install completed, so there can |
// be no installing worker at this point. |
- // TODO(nhiroki): Check 'installing_version()' instead when it's supported. |
// "Let serviceWorker be a newly-created ServiceWorker object..." and start |
// the worker. |
@@ -259,16 +258,24 @@ void ServiceWorkerRegisterJob::OnStartWorkerFinished( |
// "Resolve promise with serviceWorker." |
DCHECK(!registration()->installing_version()); |
ResolvePromise(status, registration(), new_version()); |
- registration()->SetInstallingVersion(new_version()); |
- AssociateInstallingVersionToDocuments(context_, new_version()); |
InstallAndContinue(); |
} |
// This function corresponds to the spec's _Install algorithm. |
void ServiceWorkerRegisterJob::InstallAndContinue() { |
SetPhase(INSTALL); |
- // "Set serviceWorkerRegistration.installingWorker._state to installing." |
- // "Fire install event on the associated ServiceWorkerGlobalScope object." |
+ |
+ // "3. Set registration.installingWorker to worker." |
+ registration()->SetInstallingVersion(new_version()); |
+ AssociateInstallingVersionToDocuments(context_, new_version()); |
+ |
+ // "4. Run the [[UpdateState]] algorithm passing registration.installingWorker |
+ // and "installing" as the arguments." |
+ new_version()->SetStatus(ServiceWorkerVersion::INSTALLING); |
+ |
+ // TODO(nhiroki,michaeln): "5. Fire a simple event named updatefound..." |
+ |
+ // "6. Fire an event named install..." |
new_version()->DispatchInstallEvent( |
-1, |
base::Bind(&ServiceWorkerRegisterJob::OnInstallFinished, |
@@ -277,11 +284,12 @@ void ServiceWorkerRegisterJob::InstallAndContinue() { |
void ServiceWorkerRegisterJob::OnInstallFinished( |
ServiceWorkerStatusCode status) { |
- // "If any handler called waitUntil()..." and the resulting promise |
- // is rejected, abort. |
// TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is |
// unexpectedly terminated) we may want to retry sending the event again. |
if (status != SERVICE_WORKER_OK) { |
+ // "8. If installFailed is true, then:..." |
+ new_version()->SetStatus(ServiceWorkerVersion::REDUNDANT); |
+ registration()->SetInstallingVersion(NULL); |
Complete(status); |
return; |
} |
@@ -297,10 +305,22 @@ void ServiceWorkerRegisterJob::OnInstallFinished( |
void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( |
ServiceWorkerStatusCode status) { |
if (status != SERVICE_WORKER_OK) { |
+ new_version()->SetStatus(ServiceWorkerVersion::REDUNDANT); |
+ registration()->SetInstallingVersion(NULL); |
Complete(status); |
return; |
} |
+ |
+ // "9. If registration.waitingWorker is not null, then:..." |
falken
2014/07/04 09:30:49
it looks like we don't actually do this step. Make
nhiroki
2014/07/04 10:37:26
Done.
|
+ // "10. Set registration.waitingWorker to registration.installingworker." |
+ // "11. Set registration.installing_version to null." |
falken
2014/07/04 09:30:49
"installingWorker"
nhiroki
2014/07/04 10:37:26
Done.
|
+ DisassociateVersionFromDocuments(context_, new_version()); |
registration()->SetWaitingVersion(new_version()); |
+ AssociateWaitingVersionToDocuments(context_, new_version()); |
+ |
+ // "12. Run the [[UpdateState]] algorithm passing registration.waitingWorker |
+ // and "installed" as the arguments." |
+ new_version()->SetStatus(ServiceWorkerVersion::INSTALLED); |
ActivateAndContinue(); |
} |
@@ -308,7 +328,7 @@ void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( |
void ServiceWorkerRegisterJob::ActivateAndContinue() { |
SetPhase(ACTIVATE); |
- // "If existingWorker is not null, then: wait for exitingWorker to finish |
+ // "4. If existingWorker is not null, then: wait for exitingWorker to finish |
// handling any in-progress requests." |
// See if we already have an active_version for the scope and it has |
// controllee documents (if so activating the new version should wait |
@@ -326,13 +346,17 @@ void ServiceWorkerRegisterJob::ActivateAndContinue() { |
return; |
} |
- // "Set serviceWorkerRegistration.waitingWorker to null." |
- // "Set serviceWorkerRegistration.activeWorker to activatingWorker." |
+ // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker." |
+ // "6. Set serviceWorkerRegistration.waitingWorker to null." |
registration()->SetActiveVersion(new_version()); |
- // "Set serviceWorkerRegistration.activeWorker._state to activating." |
- // "Fire activate event on the associated ServiceWorkerGlobalScope object." |
- // "Set serviceWorkerRegistration.activeWorker._state to active." |
+ // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and |
+ // "activating" as arguments." |
+ new_version()->SetStatus(ServiceWorkerVersion::ACTIVATING); |
+ |
+ // TODO(nhiroki): "8. Fire a simple event named controllerchange..." |
+ |
+ // "9. Fire an event named activate..." |
new_version()->DispatchActivateEvent( |
base::Bind(&ServiceWorkerRegisterJob::OnActivateFinished, |
weak_factory_.GetWeakPtr())); |
@@ -340,15 +364,19 @@ void ServiceWorkerRegisterJob::ActivateAndContinue() { |
void ServiceWorkerRegisterJob::OnActivateFinished( |
ServiceWorkerStatusCode status) { |
- // "If any handler called waitUntil()..." and the resulting promise |
- // is rejected, abort. |
// TODO(kinuko,falken): For some error cases (e.g. ServiceWorker is |
// unexpectedly terminated) we may want to retry sending the event again. |
if (status != SERVICE_WORKER_OK) { |
+ // "11. If activateFailed is true, then:..." |
+ new_version()->SetStatus(ServiceWorkerVersion::REDUNDANT); |
registration()->SetActiveVersion(NULL); |
Complete(status); |
return; |
} |
+ |
+ // "12. Run the [[UpdateState]] algorithm passing registration.activeWorker |
+ // and "activated" as the arguments." |
+ new_version()->SetStatus(ServiceWorkerVersion::ACTIVE); |
context_->storage()->UpdateToActiveState( |
registration(), |
base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
@@ -440,6 +468,26 @@ void ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( |
} |
// static |
+void ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments( |
+ base::WeakPtr<ServiceWorkerContextCore> context, |
+ ServiceWorkerVersion* version) { |
+ DCHECK(context); |
+ DCHECK(version); |
+ |
+ for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
+ context->GetProviderHostIterator(); |
+ !it->IsAtEnd(); it->Advance()) { |
falken
2014/07/04 09:30:49
extra spaces
nhiroki
2014/07/04 10:37:26
Done.
|
+ ServiceWorkerProviderHost* host = it->GetProviderHost(); |
+ if (ServiceWorkerUtils::ScopeMatches(version->scope(), |
+ host->document_url())) { |
+ if (!host->CanAssociateVersion(version)) |
+ continue; |
+ host->SetWaitingVersion(version); |
+ } |
+ } |
+} |
+ |
+// static |
void ServiceWorkerRegisterJob::DisassociateVersionFromDocuments( |
base::WeakPtr<ServiceWorkerContextCore> context, |
ServiceWorkerVersion* version) { |