Index: content/browser/service_worker/service_worker_registration.cc |
diff --git a/content/browser/service_worker/service_worker_registration.cc b/content/browser/service_worker/service_worker_registration.cc |
index 0445f08f7e646ba73497be4257adeb4d6ad008c3..901df96bb3bc345bbbc996439e4538b27320aa13 100644 |
--- a/content/browser/service_worker/service_worker_registration.cc |
+++ b/content/browser/service_worker/service_worker_registration.cc |
@@ -210,7 +210,6 @@ void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) { |
void ServiceWorkerRegistration::ActivateWaitingVersion() { |
DCHECK(context_); |
DCHECK(waiting_version()); |
- DCHECK(should_activate_when_ready_); |
should_activate_when_ready_ = false; |
scoped_refptr<ServiceWorkerVersion> activating_version = waiting_version(); |
scoped_refptr<ServiceWorkerVersion> exiting_version = active_version(); |
@@ -220,6 +219,9 @@ void ServiceWorkerRegistration::ActivateWaitingVersion() { |
return; // Activation is no longer relevant. |
} |
+ if (activating_version->skip_waiting()) |
+ PrepareProviderHostsToSkipWaiting(); |
+ |
// "4. If exitingWorker is not null, |
if (exiting_version.get()) { |
DCHECK(!exiting_version->HasControllee()); |
@@ -239,16 +241,41 @@ void ServiceWorkerRegistration::ActivateWaitingVersion() { |
// "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and |
// "activating" as arguments." |
+ // "8. Fire a simple event named controllerchange..." |
activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); |
- // TODO(nhiroki): "8. Fire a simple event named controllerchange..." |
- |
// "9. Queue a task to fire an event named activate..." |
activating_version->DispatchActivateEvent( |
base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, |
this, activating_version)); |
} |
+void ServiceWorkerRegistration::PrepareProviderHostsToSkipWaiting() { |
+ for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
+ context_->GetProviderHostIterator(); |
+ !it->IsAtEnd(); it->Advance()) { |
+ ServiceWorkerProviderHost* host = it->GetProviderHost(); |
+ if (!ServiceWorkerUtils::ScopeMatches(pattern(), |
+ host->document_url())) |
+ continue; |
+ scoped_refptr<ServiceWorkerVersion> exiting_version = |
+ host->active_version(); |
falken
2014/11/14 04:00:15
You can add "1. Let exitingWorker be the active wo
|
+ // "2. If exitingWorker is not null, then:" |
+ if (!exiting_version.get()) |
+ continue; |
+ // TODO(xiang): should wait for events to be complete |
+ // "1. Wait for exitingWorker to finish handling any in-progress requests." |
+ // "2. Terminate exitingWorker." |
+ exiting_version->StopWorker( |
+ base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
+ exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); |
michaeln
2014/11/14 02:05:11
I don't believe this is the desired behavior. What
falken
2014/11/14 04:00:15
Right I think this can happen if this registration
xiang
2014/11/14 13:17:28
Yes, a longer matched registration should not be a
michaeln
2014/11/14 23:06:39
Hmmm, section 7.9 for the [[Install]] algo is obvi
|
+ if (host->associated_registration() != this) { |
+ host->DisassociateRegistration(); |
+ host->AssociateRegistration(this); |
+ } |
+ } |
+} |
+ |
void ServiceWorkerRegistration::OnActivateEventFinished( |
ServiceWorkerVersion* activating_version, |
ServiceWorkerStatusCode status) { |