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_metrics.h" | 9 #include "content/browser/service_worker/service_worker_metrics.h" |
10 #include "content/browser/service_worker/service_worker_register_job.h" | 10 #include "content/browser/service_worker/service_worker_register_job.h" |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 // "9. Fire a simple event named controllerchange..." | 295 // "9. Fire a simple event named controllerchange..." |
296 if (activating_version->skip_waiting()) | 296 if (activating_version->skip_waiting()) |
297 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); | 297 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); |
298 | 298 |
299 // "10. Queue a task to fire an event named activate..." | 299 // "10. Queue a task to fire an event named activate..." |
300 activating_version->DispatchActivateEvent( | 300 activating_version->DispatchActivateEvent( |
301 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, | 301 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, |
302 this, activating_version)); | 302 this, activating_version)); |
303 } | 303 } |
304 | 304 |
305 void ServiceWorkerRegistration::DeleteVersion( | |
306 const scoped_refptr<ServiceWorkerVersion>& version) { | |
307 DCHECK_EQ(id(), version->registration_id()); | |
308 | |
309 // "Set registration's active worker to null." (The spec's step order may | |
310 // differ. It's OK because the other steps queue a task.) | |
311 UnsetVersion(version.get()); | |
312 | |
313 // "Run the Update State algorithm passing registration's active worker and | |
314 // 'redundant' as the arguments." | |
315 version->SetStatus(ServiceWorkerVersion::REDUNDANT); | |
316 | |
317 // "For each service worker client client whose active worker is | |
318 // registration's active worker..." set the active worker to null. | |
319 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = | |
320 context_->GetProviderHostIterator(); | |
321 !it->IsAtEnd(); it->Advance()) { | |
322 ServiceWorkerProviderHost* host = it->GetProviderHost(); | |
323 if (host->controlling_version() == version) | |
324 host->NotifyControllerActivationFailed(); | |
325 } | |
326 | |
327 version->Doom(); | |
328 | |
329 if (!active_version() && !waiting_version()) { | |
330 // Delete the records from the db. | |
331 context_->storage()->DeleteRegistration( | |
332 id(), pattern().GetOrigin(), | |
333 base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this)); | |
334 // But not from memory if there is a version in the pipeline. | |
335 if (installing_version()) { | |
336 is_deleted_ = false; | |
337 } else { | |
338 is_uninstalled_ = true; | |
339 FOR_EACH_OBSERVER(Listener, listeners_, OnRegistrationFailed(this)); | |
340 } | |
341 } | |
342 } | |
343 | |
344 void ServiceWorkerRegistration::OnActivateEventFinished( | 305 void ServiceWorkerRegistration::OnActivateEventFinished( |
345 ServiceWorkerVersion* activating_version, | 306 ServiceWorkerVersion* activating_version, |
346 ServiceWorkerStatusCode status) { | 307 ServiceWorkerStatusCode status) { |
347 if (!context_ || activating_version != active_version()) | 308 if (!context_ || activating_version != active_version()) |
348 return; | 309 return; |
349 ServiceWorkerMetrics::RecordActivateEventStatus(status); | 310 ServiceWorkerMetrics::RecordActivateEventStatus(status); |
350 | 311 |
351 // "If activateFailed is true, then:..." | 312 // "If activateFailed is true, then:..." |
352 if (status != SERVICE_WORKER_OK) { | 313 if (status != SERVICE_WORKER_OK) { |
353 DeleteVersion(make_scoped_refptr(activating_version)); | 314 // "Set registration's active worker to null." (The spec's step order may |
| 315 // differ. It's OK because the other steps queue a task.) |
| 316 UnsetVersion(activating_version); |
| 317 |
| 318 // "Run the Update State algorithm passing registration's active worker and |
| 319 // 'redundant' as the arguments." |
| 320 activating_version->SetStatus(ServiceWorkerVersion::REDUNDANT); |
| 321 |
| 322 // "For each service worker client client whose active worker is |
| 323 // registration's active worker..." set the active worker to null. |
| 324 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
| 325 context_->GetProviderHostIterator(); |
| 326 !it->IsAtEnd(); it->Advance()) { |
| 327 ServiceWorkerProviderHost* host = it->GetProviderHost(); |
| 328 if (host->controlling_version() == activating_version) |
| 329 host->NotifyControllerActivationFailed(); |
| 330 } |
| 331 |
| 332 activating_version->Doom(); |
| 333 if (!waiting_version()) { |
| 334 // Delete the records from the db. |
| 335 context_->storage()->DeleteRegistration( |
| 336 id(), pattern().GetOrigin(), |
| 337 base::Bind(&ServiceWorkerRegistration::OnDeleteFinished, this)); |
| 338 // But not from memory if there is a version in the pipeline. |
| 339 if (installing_version()) { |
| 340 is_deleted_ = false; |
| 341 } else { |
| 342 is_uninstalled_ = true; |
| 343 FOR_EACH_OBSERVER(Listener, listeners_, OnRegistrationFailed(this)); |
| 344 } |
| 345 } |
354 return; | 346 return; |
355 } | 347 } |
356 | 348 |
357 // "Run the Update State algorithm passing registration's active worker and | 349 // "Run the Update State algorithm passing registration's active worker and |
358 // 'activated' as the arguments." | 350 // 'activated' as the arguments." |
359 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); | 351 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); |
360 if (context_) { | 352 if (context_) { |
361 context_->storage()->UpdateToActiveState( | 353 context_->storage()->UpdateToActiveState( |
362 this, | 354 this, |
363 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 355 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 if (!context_) { | 402 if (!context_) { |
411 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 403 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
412 return; | 404 return; |
413 } | 405 } |
414 context_->storage()->NotifyDoneInstallingRegistration( | 406 context_->storage()->NotifyDoneInstallingRegistration( |
415 this, version.get(), status); | 407 this, version.get(), status); |
416 callback.Run(status); | 408 callback.Run(status); |
417 } | 409 } |
418 | 410 |
419 } // namespace content | 411 } // namespace content |
OLD | NEW |