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) { | |
nhiroki
2015/04/27 04:24:25
ServiceWorkerRegisterJob::CompleteInternal seems t
falken
2015/04/27 04:58:16
Yes good point, these are pretty similar. I'll see
| |
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 | |
305 void ServiceWorkerRegistration::OnActivateEventFinished( | 344 void ServiceWorkerRegistration::OnActivateEventFinished( |
306 ServiceWorkerVersion* activating_version, | 345 ServiceWorkerVersion* activating_version, |
307 ServiceWorkerStatusCode status) { | 346 ServiceWorkerStatusCode status) { |
308 if (!context_ || activating_version != active_version()) | 347 if (!context_ || activating_version != active_version()) |
309 return; | 348 return; |
310 ServiceWorkerMetrics::RecordActivateEventStatus(status); | 349 ServiceWorkerMetrics::RecordActivateEventStatus(status); |
311 | 350 |
312 // "If activateFailed is true, then:..." | 351 // "If activateFailed is true, then:..." |
313 if (status != SERVICE_WORKER_OK) { | 352 if (status != SERVICE_WORKER_OK) { |
314 // "Set registration's active worker to null." (The spec's step order may | 353 DeleteVersion(make_scoped_refptr(activating_version)); |
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 } | |
346 return; | 354 return; |
347 } | 355 } |
348 | 356 |
349 // "Run the Update State algorithm passing registration's active worker and | 357 // "Run the Update State algorithm passing registration's active worker and |
350 // 'activated' as the arguments." | 358 // 'activated' as the arguments." |
351 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); | 359 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATED); |
352 if (context_) { | 360 if (context_) { |
353 context_->storage()->UpdateToActiveState( | 361 context_->storage()->UpdateToActiveState( |
354 this, | 362 this, |
355 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 363 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 if (!context_) { | 410 if (!context_) { |
403 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 411 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
404 return; | 412 return; |
405 } | 413 } |
406 context_->storage()->NotifyDoneInstallingRegistration( | 414 context_->storage()->NotifyDoneInstallingRegistration( |
407 this, version.get(), status); | 415 this, version.get(), status); |
408 callback.Run(status); | 416 callback.Run(status); |
409 } | 417 } |
410 | 418 |
411 } // namespace content | 419 } // namespace content |
OLD | NEW |