Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(715)

Unified Diff: content/browser/service_worker/service_worker_registration.cc

Issue 717353004: ServiceWorker: Add support for .skipWaiting and controllerchange event(2/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add missing '!' Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698