Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 Clear(); | 204 Clear(); |
| 204 else if (should_activate_when_ready_) | 205 else if (should_activate_when_ready_) |
| 205 ActivateWaitingVersion(); | 206 ActivateWaitingVersion(); |
| 206 is_uninstalling_ = false; | 207 is_uninstalling_ = false; |
| 207 should_activate_when_ready_ = false; | 208 should_activate_when_ready_ = false; |
| 208 } | 209 } |
| 209 | 210 |
| 210 void ServiceWorkerRegistration::ActivateWaitingVersion() { | 211 void ServiceWorkerRegistration::ActivateWaitingVersion() { |
| 211 DCHECK(context_); | 212 DCHECK(context_); |
| 212 DCHECK(waiting_version()); | 213 DCHECK(waiting_version()); |
| 213 DCHECK(should_activate_when_ready_); | 214 CHECK(should_activate_when_ready_); |
|
falken
2014/11/19 04:19:56
why not DCHECK?
xiang
2014/11/24 07:04:01
Done.
| |
| 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 |
| 224 if (activating_version->skip_waiting()) | |
| 225 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); | |
| 226 | |
| 223 // "4. If exitingWorker is not null, | 227 // "4. If exitingWorker is not null, |
| 224 if (exiting_version.get()) { | 228 if (exiting_version.get()) { |
| 225 DCHECK(!exiting_version->HasControllee()); | 229 DCHECK(!exiting_version->HasControllee()); |
| 226 // TODO(michaeln): should wait for events to be complete | 230 // TODO(michaeln): should wait for events to be complete |
| 227 // "1. Wait for exitingWorker to finish handling any in-progress requests." | 231 // "1. Wait for exitingWorker to finish handling any in-progress requests." |
| 228 // "2. Terminate exitingWorker." | 232 // "2. Terminate exitingWorker." |
| 229 exiting_version->StopWorker( | 233 exiting_version->StopWorker( |
| 230 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 234 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 231 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and | 235 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and |
| 232 // "redundant" as the arguments." | 236 // "redundant" as the arguments." |
| 233 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); | 237 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); |
| 234 } | 238 } |
| 235 | 239 |
| 236 // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker." | 240 // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker." |
| 237 // "6. Set serviceWorkerRegistration.waitingWorker to null." | 241 // "6. Set serviceWorkerRegistration.waitingWorker to null." |
| 238 SetActiveVersion(activating_version.get()); | 242 SetActiveVersion(activating_version.get()); |
| 239 | 243 |
| 240 // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and | 244 // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and |
| 241 // "activating" as arguments." | 245 // "activating" as arguments." |
| 246 // "8. Fire a simple event named controllerchange..." | |
|
falken
2014/11/19 04:19:56
these line numbers are now out of the sync with th
xiang
2014/11/24 07:04:01
Done.
| |
| 242 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); | 247 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); |
| 243 | 248 |
| 244 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." | |
| 245 | |
| 246 // "9. Queue a task to fire an event named activate..." | 249 // "9. Queue a task to fire an event named activate..." |
| 247 activating_version->DispatchActivateEvent( | 250 activating_version->DispatchActivateEvent( |
| 248 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, | 251 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, |
| 249 this, activating_version)); | 252 this, activating_version)); |
| 250 } | 253 } |
| 251 | 254 |
| 252 void ServiceWorkerRegistration::OnActivateEventFinished( | 255 void ServiceWorkerRegistration::OnActivateEventFinished( |
| 253 ServiceWorkerVersion* activating_version, | 256 ServiceWorkerVersion* activating_version, |
| 254 ServiceWorkerStatusCode status) { | 257 ServiceWorkerStatusCode status) { |
| 255 if (!context_ || activating_version != active_version()) | 258 if (!context_ || activating_version != active_version()) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 if (!context_) { | 331 if (!context_) { |
| 329 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 332 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 330 return; | 333 return; |
| 331 } | 334 } |
| 332 context_->storage()->NotifyDoneInstallingRegistration( | 335 context_->storage()->NotifyDoneInstallingRegistration( |
| 333 this, version.get(), status); | 336 this, version.get(), status); |
| 334 callback.Run(status); | 337 callback.Run(status); |
| 335 } | 338 } |
| 336 | 339 |
| 337 } // namespace content | 340 } // namespace content |
| OLD | NEW |