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 23 matching lines...) Expand all Loading... | |
| 191 context_->storage()->StoreRegistration( | 192 context_->storage()->StoreRegistration( |
| 192 this, | 193 this, |
| 193 most_recent_version.get(), | 194 most_recent_version.get(), |
| 194 base::Bind(&ServiceWorkerRegistration::OnRestoreFinished, | 195 base::Bind(&ServiceWorkerRegistration::OnRestoreFinished, |
| 195 this, | 196 this, |
| 196 callback, | 197 callback, |
| 197 most_recent_version)); | 198 most_recent_version)); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) { | 201 void ServiceWorkerRegistration::OnNoControllees(ServiceWorkerVersion* version) { |
| 201 DCHECK_EQ(active_version(), version); | |
|
falken
2014/12/01 02:29:59
I guess this DCHECK can fail now if OnNoControllee
xiang
2014/12/01 07:20:07
Thanks for point this out, I think we can remove t
falken
2014/12/01 07:27:52
Looks right, nice idea.
| |
| 202 if (is_uninstalling_) | 202 if (is_uninstalling_) |
| 203 Clear(); | 203 Clear(); |
| 204 else if (should_activate_when_ready_) | 204 else if (should_activate_when_ready_) |
| 205 ActivateWaitingVersion(); | 205 ActivateWaitingVersion(); |
| 206 is_uninstalling_ = false; | 206 is_uninstalling_ = false; |
| 207 should_activate_when_ready_ = false; | 207 should_activate_when_ready_ = false; |
| 208 } | 208 } |
| 209 | 209 |
| 210 void ServiceWorkerRegistration::ActivateWaitingVersion() { | 210 void ServiceWorkerRegistration::ActivateWaitingVersion() { |
| 211 DCHECK(context_); | 211 DCHECK(context_); |
| 212 DCHECK(waiting_version()); | 212 DCHECK(waiting_version()); |
| 213 DCHECK(should_activate_when_ready_); | 213 DCHECK(should_activate_when_ready_); |
| 214 should_activate_when_ready_ = false; | 214 should_activate_when_ready_ = false; |
| 215 scoped_refptr<ServiceWorkerVersion> activating_version = waiting_version(); | 215 scoped_refptr<ServiceWorkerVersion> activating_version = waiting_version(); |
| 216 scoped_refptr<ServiceWorkerVersion> exiting_version = active_version(); | 216 scoped_refptr<ServiceWorkerVersion> exiting_version = active_version(); |
| 217 | 217 |
| 218 if (activating_version->is_doomed() || | 218 if (activating_version->is_doomed() || |
| 219 activating_version->status() == ServiceWorkerVersion::REDUNDANT) { | 219 activating_version->status() == ServiceWorkerVersion::REDUNDANT) { |
| 220 return; // Activation is no longer relevant. | 220 return; // Activation is no longer relevant. |
| 221 } | 221 } |
| 222 | 222 |
| 223 // "4. If exitingWorker is not null, | 223 // "5. If exitingWorker is not null, |
| 224 if (exiting_version.get()) { | 224 if (exiting_version.get()) { |
| 225 DCHECK(!exiting_version->HasControllee()); | |
| 226 // TODO(michaeln): should wait for events to be complete | 225 // TODO(michaeln): should wait for events to be complete |
| 227 // "1. Wait for exitingWorker to finish handling any in-progress requests." | 226 // "1. Wait for exitingWorker to finish handling any in-progress requests." |
| 228 // "2. Terminate exitingWorker." | 227 // "2. Terminate exitingWorker." |
| 229 exiting_version->StopWorker( | 228 exiting_version->StopWorker( |
| 230 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 229 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 231 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and | 230 // "3. Run the [[UpdateState]] algorithm passing exitingWorker and |
| 232 // "redundant" as the arguments." | 231 // "redundant" as the arguments." |
| 233 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); | 232 exiting_version->SetStatus(ServiceWorkerVersion::REDUNDANT); |
| 234 } | 233 } |
| 235 | 234 |
| 236 // "5. Set serviceWorkerRegistration.activeWorker to activatingWorker." | 235 // "6. Set serviceWorkerRegistration.activeWorker to activatingWorker." |
| 237 // "6. Set serviceWorkerRegistration.waitingWorker to null." | 236 // "7. Set serviceWorkerRegistration.waitingWorker to null." |
| 238 SetActiveVersion(activating_version.get()); | 237 SetActiveVersion(activating_version.get()); |
| 239 | 238 |
| 240 // "7. Run the [[UpdateState]] algorithm passing registration.activeWorker and | 239 // "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and |
| 241 // "activating" as arguments." | 240 // "activating" as arguments." |
| 242 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); | 241 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); |
| 242 // "9. Fire a simple event named controllerchange..." | |
| 243 // Notify associated provider hosts to change the controller. | |
| 244 if (activating_version->skip_waiting()) | |
| 245 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); | |
| 243 | 246 |
| 244 // TODO(nhiroki): "8. Fire a simple event named controllerchange..." | 247 // "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( | 248 activating_version->DispatchActivateEvent( |
| 248 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, | 249 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, |
| 249 this, activating_version)); | 250 this, activating_version)); |
| 250 } | 251 } |
| 251 | 252 |
| 252 void ServiceWorkerRegistration::OnActivateEventFinished( | 253 void ServiceWorkerRegistration::OnActivateEventFinished( |
| 253 ServiceWorkerVersion* activating_version, | 254 ServiceWorkerVersion* activating_version, |
| 254 ServiceWorkerStatusCode status) { | 255 ServiceWorkerStatusCode status) { |
| 255 if (!context_ || activating_version != active_version()) | 256 if (!context_ || activating_version != active_version()) |
| 256 return; | 257 return; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 if (!context_) { | 329 if (!context_) { |
| 329 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 330 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 330 return; | 331 return; |
| 331 } | 332 } |
| 332 context_->storage()->NotifyDoneInstallingRegistration( | 333 context_->storage()->NotifyDoneInstallingRegistration( |
| 333 this, version.get(), status); | 334 this, version.get(), status); |
| 334 callback.Run(status); | 335 callback.Run(status); |
| 335 } | 336 } |
| 336 | 337 |
| 337 } // namespace content | 338 } // namespace content |
| OLD | NEW |