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

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: rebase again 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 void ServiceWorkerRegistration::SetVersionInternal( 118 void ServiceWorkerRegistration::SetVersionInternal(
119 ServiceWorkerVersion* version, 119 ServiceWorkerVersion* version,
120 scoped_refptr<ServiceWorkerVersion>* data_member, 120 scoped_refptr<ServiceWorkerVersion>* data_member,
121 int change_flag) { 121 int change_flag) {
122 if (version == data_member->get()) 122 if (version == data_member->get())
123 return; 123 return;
124 scoped_refptr<ServiceWorkerVersion> protect(version); 124 scoped_refptr<ServiceWorkerVersion> protect(version);
125 ChangedVersionAttributesMask mask; 125 ChangedVersionAttributesMask mask;
126 if (version) 126 if (version)
127 UnsetVersionInternal(version, &mask); 127 UnsetVersionInternal(version, &mask);
128 if (*data_member && *data_member == active_version_)
129 active_version_->RemoveListener(this);
128 *data_member = version; 130 *data_member = version;
129 if (active_version_.get() && active_version_.get() == version) 131 if (active_version_.get() && active_version_.get() == version)
130 active_version_->AddListener(this); 132 active_version_->AddListener(this);
131 mask.add(change_flag); 133 mask.add(change_flag);
132 ServiceWorkerRegistrationInfo info = GetInfo(); 134 ServiceWorkerRegistrationInfo info = GetInfo();
133 FOR_EACH_OBSERVER(Listener, listeners_, 135 FOR_EACH_OBSERVER(Listener, listeners_,
134 OnVersionAttributesChanged(this, mask, info)); 136 OnVersionAttributesChanged(this, mask, info));
135 } 137 }
136 138
137 void ServiceWorkerRegistration::UnsetVersionInternal( 139 void ServiceWorkerRegistration::UnsetVersionInternal(
138 ServiceWorkerVersion* version, 140 ServiceWorkerVersion* version,
139 ChangedVersionAttributesMask* mask) { 141 ChangedVersionAttributesMask* mask) {
140 DCHECK(version); 142 DCHECK(version);
141 if (installing_version_.get() == version) { 143 if (installing_version_.get() == version) {
142 installing_version_ = NULL; 144 installing_version_ = NULL;
143 mask->add(ChangedVersionAttributesMask::INSTALLING_VERSION); 145 mask->add(ChangedVersionAttributesMask::INSTALLING_VERSION);
144 } else if (waiting_version_.get() == version) { 146 } else if (waiting_version_.get() == version) {
145 waiting_version_ = NULL; 147 waiting_version_ = NULL;
146 mask->add(ChangedVersionAttributesMask::WAITING_VERSION); 148 mask->add(ChangedVersionAttributesMask::WAITING_VERSION);
147 } else if (active_version_.get() == version) { 149 } else if (active_version_.get() == version) {
148 active_version_->RemoveListener(this); 150 active_version_->RemoveListener(this);
149 active_version_ = NULL; 151 active_version_ = NULL;
150 mask->add(ChangedVersionAttributesMask::ACTIVE_VERSION); 152 mask->add(ChangedVersionAttributesMask::ACTIVE_VERSION);
151 } 153 }
152 } 154 }
153 155
154 void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() { 156 void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() {
155 DCHECK(waiting_version()); 157 DCHECK(waiting_version());
156 should_activate_when_ready_ = true; 158 should_activate_when_ready_ = true;
157 if (!active_version() || !active_version()->HasControllee()) 159 if (!active_version() || !active_version()->HasControllee() ||
160 waiting_version()->skip_waiting())
158 ActivateWaitingVersion(); 161 ActivateWaitingVersion();
159 } 162 }
160 163
161 void ServiceWorkerRegistration::ClearWhenReady() { 164 void ServiceWorkerRegistration::ClearWhenReady() {
162 DCHECK(context_); 165 DCHECK(context_);
163 if (is_uninstalling_) 166 if (is_uninstalling_)
164 return; 167 return;
165 is_uninstalling_ = true; 168 is_uninstalling_ = true;
166 169
167 context_->storage()->NotifyUninstallingRegistration(this); 170 context_->storage()->NotifyUninstallingRegistration(this);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 DCHECK(should_activate_when_ready_); 239 DCHECK(should_activate_when_ready_);
237 should_activate_when_ready_ = false; 240 should_activate_when_ready_ = false;
238 scoped_refptr<ServiceWorkerVersion> activating_version = waiting_version(); 241 scoped_refptr<ServiceWorkerVersion> activating_version = waiting_version();
239 scoped_refptr<ServiceWorkerVersion> exiting_version = active_version(); 242 scoped_refptr<ServiceWorkerVersion> exiting_version = active_version();
240 243
241 if (activating_version->is_doomed() || 244 if (activating_version->is_doomed() ||
242 activating_version->status() == ServiceWorkerVersion::REDUNDANT) { 245 activating_version->status() == ServiceWorkerVersion::REDUNDANT) {
243 return; // Activation is no longer relevant. 246 return; // Activation is no longer relevant.
244 } 247 }
245 248
246 // "4. If exitingWorker is not null, 249 // "5. If exitingWorker is not null,
247 if (exiting_version.get()) { 250 if (exiting_version.get()) {
248 DCHECK(!exiting_version->HasControllee());
249 // TODO(michaeln): should wait for events to be complete 251 // TODO(michaeln): should wait for events to be complete
250 // "1. Wait for exitingWorker to finish handling any in-progress requests." 252 // "1. Wait for exitingWorker to finish handling any in-progress requests."
251 // "2. Terminate exitingWorker." 253 // "2. Terminate exitingWorker."
252 exiting_version->StopWorker( 254 exiting_version->StopWorker(
253 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 255 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
254 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and 256 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and
255 // "redundant" as the arguments." 257 // "redundant" as the arguments."
256 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); 258 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT);
257 } 259 }
258 260
259 // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker." 261 // "6. Set serviceWorkerRegistration.activeWorker to activatingWorker."
260 // "6. Set serviceWorkerRegistration.waitingWorker to null." 262 // "7. Set serviceWorkerRegistration.waitingWorker to null."
261 SetActiveVersion(activating_version.get()); 263 SetActiveVersion(activating_version.get());
262 264
263 // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and 265 // "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and
264 // "activating" as arguments." 266 // "activating" as arguments."
265 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); 267 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING);
268 // "9. Fire a simple event named controllerchange..."
269 // Notify associated provider hosts to change the controller.
270 if (activating_version->skip_waiting())
271 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this));
266 272
267 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." 273 // "10. Queue a task to fire an event named activate..."
268
269 // "9. Queue a task to fire an event named activate..."
270 activating_version->DispatchActivateEvent( 274 activating_version->DispatchActivateEvent(
271 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, 275 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished,
272 this, activating_version)); 276 this, activating_version));
273 } 277 }
274 278
275 void ServiceWorkerRegistration::OnActivateEventFinished( 279 void ServiceWorkerRegistration::OnActivateEventFinished(
276 ServiceWorkerVersion* activating_version, 280 ServiceWorkerVersion* activating_version,
277 ServiceWorkerStatusCode status) { 281 ServiceWorkerStatusCode status) {
278 if (!context_ || activating_version != active_version()) 282 if (!context_ || activating_version != active_version())
279 return; 283 return;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 if (!context_) { 355 if (!context_) {
352 callback.Run(SERVICE_WORKER_ERROR_ABORT); 356 callback.Run(SERVICE_WORKER_ERROR_ABORT);
353 return; 357 return;
354 } 358 }
355 context_->storage()->NotifyDoneInstallingRegistration( 359 context_->storage()->NotifyDoneInstallingRegistration(
356 this, version.get(), status); 360 this, version.get(), status);
357 callback.Run(status); 361 callback.Run(status);
358 } 362 }
359 363
360 } // namespace content 364 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_registration.h ('k') | content/browser/service_worker/service_worker_version.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698