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

Side by Side 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: review update Created 6 years 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 unified diff | Download patch
OLDNEW
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } else if (active_version_.get() == version) { 147 } else if (active_version_.get() == version) {
148 active_version_->RemoveListener(this); 148 active_version_->RemoveListener(this);
149 active_version_ = NULL; 149 active_version_ = NULL;
150 mask->add(ChangedVersionAttributesMask::ACTIVE_VERSION); 150 mask->add(ChangedVersionAttributesMask::ACTIVE_VERSION);
151 } 151 }
152 } 152 }
153 153
154 void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() { 154 void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() {
155 DCHECK(waiting_version()); 155 DCHECK(waiting_version());
156 should_activate_when_ready_ = true; 156 should_activate_when_ready_ = true;
157 if (!active_version() || !active_version()->HasControllee()) 157 if (!active_version() || !active_version()->HasControllee()
158 || waiting_version()->skip_waiting())
158 ActivateWaitingVersion(); 159 ActivateWaitingVersion();
159 } 160 }
160 161
161 void ServiceWorkerRegistration::ClearWhenReady() { 162 void ServiceWorkerRegistration::ClearWhenReady() {
162 DCHECK(context_); 163 DCHECK(context_);
163 if (is_uninstalling_) 164 if (is_uninstalling_)
164 return; 165 return;
165 is_uninstalling_ = true; 166 is_uninstalling_ = true;
166 167
167 context_->storage()->NotifyUninstallingRegistration(this); 168 context_->storage()->NotifyUninstallingRegistration(this);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 DCHECK(should_activate_when_ready_); 214 DCHECK(should_activate_when_ready_);
214 should_activate_when_ready_ = false; 215 should_activate_when_ready_ = false;
215 scoped_refptr<ServiceWorkerVersion> activating_version = waiting_version(); 216 scoped_refptr<ServiceWorkerVersion> activating_version = waiting_version();
216 scoped_refptr<ServiceWorkerVersion> exiting_version = active_version(); 217 scoped_refptr<ServiceWorkerVersion> exiting_version = active_version();
217 218
218 if (activating_version->is_doomed() || 219 if (activating_version->is_doomed() ||
219 activating_version->status() == ServiceWorkerVersion::REDUNDANT) { 220 activating_version->status() == ServiceWorkerVersion::REDUNDANT) {
220 return; // Activation is no longer relevant. 221 return; // Activation is no longer relevant.
221 } 222 }
222 223
223 // "4. If exitingWorker is not null, 224 // "5. If exitingWorker is not null,
224 if (exiting_version.get()) { 225 if (exiting_version.get()) {
225 DCHECK(!exiting_version->HasControllee()); 226 DCHECK(!exiting_version->HasControllee());
falken 2014/11/27 03:40:40 Can't this DCHECK fail in the skip waiting scenari
xiang 2014/11/28 08:04:26 Done.
226 // TODO(michaeln): should wait for events to be complete 227 // TODO(michaeln): should wait for events to be complete
227 // "1. Wait for exitingWorker to finish handling any in-progress requests." 228 // "1. Wait for exitingWorker to finish handling any in-progress requests."
228 // "2. Terminate exitingWorker." 229 // "2. Terminate exitingWorker."
229 exiting_version->StopWorker( 230 exiting_version->StopWorker(
230 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 231 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
231 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and 232 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and
232 // "redundant" as the arguments." 233 // "redundant" as the arguments."
233 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); 234 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT);
234 } 235 }
235 236
236 // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker." 237 // "6. Set serviceWorkerRegistration.activeWorker to activatingWorker."
237 // "6. Set serviceWorkerRegistration.waitingWorker to null." 238 // "7. Set serviceWorkerRegistration.waitingWorker to null."
238 SetActiveVersion(activating_version.get()); 239 SetActiveVersion(activating_version.get());
239 240
240 // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and 241 // "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and
241 // "activating" as arguments." 242 // "activating" as arguments."
243 // "9. Fire a simple event named controllerchange..."
falken 2014/11/25 09:25:02 It's not too clear how Step 9 is implemented, can
xiang 2014/11/28 08:04:26 Done.
242 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); 244 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING);
245 if (activating_version->skip_waiting())
246 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this));
243 247
244 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." 248 // "10. Queue a task to fire an event named activate..."
245
246 // "9. Queue a task to fire an event named activate..."
247 activating_version->DispatchActivateEvent( 249 activating_version->DispatchActivateEvent(
248 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, 250 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished,
249 this, activating_version)); 251 this, activating_version));
250 } 252 }
251 253
252 void ServiceWorkerRegistration::OnActivateEventFinished( 254 void ServiceWorkerRegistration::OnActivateEventFinished(
253 ServiceWorkerVersion* activating_version, 255 ServiceWorkerVersion* activating_version,
254 ServiceWorkerStatusCode status) { 256 ServiceWorkerStatusCode status) {
255 if (!context_ || activating_version != active_version()) 257 if (!context_ || activating_version != active_version())
256 return; 258 return;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if (!context_) { 330 if (!context_) {
329 callback.Run(SERVICE_WORKER_ERROR_ABORT); 331 callback.Run(SERVICE_WORKER_ERROR_ABORT);
330 return; 332 return;
331 } 333 }
332 context_->storage()->NotifyDoneInstallingRegistration( 334 context_->storage()->NotifyDoneInstallingRegistration(
333 this, version.get(), status); 335 this, version.get(), status);
334 callback.Run(status); 336 callback.Run(status);
335 } 337 }
336 338
337 } // namespace content 339 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698