| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
| 10 #include "content/browser/service_worker/service_worker_info.h" | 10 #include "content/browser/service_worker/service_worker_info.h" |
| 11 #include "content/browser/service_worker/service_worker_metrics.h" | 11 #include "content/browser/service_worker/service_worker_metrics.h" |
| 12 #include "content/browser/service_worker/service_worker_register_job.h" | 12 #include "content/browser/service_worker/service_worker_register_job.h" |
| 13 #include "content/common/service_worker/service_worker_messages.h" |
| 13 #include "content/common/service_worker/service_worker_utils.h" | 14 #include "content/common/service_worker/service_worker_utils.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 ServiceWorkerVersionInfo GetVersionInfo(ServiceWorkerVersion* version) { | 21 ServiceWorkerVersionInfo GetVersionInfo(ServiceWorkerVersion* version) { |
| 21 if (!version) | 22 if (!version) |
| 22 return ServiceWorkerVersionInfo(); | 23 return ServiceWorkerVersionInfo(); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 SetActiveVersion(activating_version); | 279 SetActiveVersion(activating_version); |
| 279 | 280 |
| 280 // "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and | 281 // "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and |
| 281 // "activating" as arguments." | 282 // "activating" as arguments." |
| 282 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); | 283 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); |
| 283 // "9. Fire a simple event named controllerchange..." | 284 // "9. Fire a simple event named controllerchange..." |
| 284 if (activating_version->skip_waiting()) | 285 if (activating_version->skip_waiting()) |
| 285 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); | 286 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); |
| 286 | 287 |
| 287 // "10. Queue a task to fire an event named activate..." | 288 // "10. Queue a task to fire an event named activate..." |
| 288 activating_version->DispatchActivateEvent( | 289 activating_version->RunAfterStartWorker( |
| 289 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, | 290 base::Bind(&ServiceWorkerRegistration::DispatchActivateEvent, this, |
| 290 this, activating_version)); | 291 activating_version), |
| 292 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, this, |
| 293 activating_version)); |
| 291 } | 294 } |
| 292 | 295 |
| 293 void ServiceWorkerRegistration::DeleteVersion( | 296 void ServiceWorkerRegistration::DeleteVersion( |
| 294 const scoped_refptr<ServiceWorkerVersion>& version) { | 297 const scoped_refptr<ServiceWorkerVersion>& version) { |
| 295 DCHECK_EQ(id(), version->registration_id()); | 298 DCHECK_EQ(id(), version->registration_id()); |
| 296 | 299 |
| 297 UnsetVersion(version.get()); | 300 UnsetVersion(version.get()); |
| 298 | 301 |
| 299 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = | 302 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
| 300 context_->GetProviderHostIterator(); | 303 context_->GetProviderHostIterator(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 331 } | 334 } |
| 332 | 335 |
| 333 void ServiceWorkerRegistration::RegisterRegistrationFinishedCallback( | 336 void ServiceWorkerRegistration::RegisterRegistrationFinishedCallback( |
| 334 const base::Closure& callback) { | 337 const base::Closure& callback) { |
| 335 // This should only be called if the registration is in progress. | 338 // This should only be called if the registration is in progress. |
| 336 DCHECK(!active_version() && !waiting_version() && !is_uninstalled() && | 339 DCHECK(!active_version() && !waiting_version() && !is_uninstalled() && |
| 337 !is_uninstalling()); | 340 !is_uninstalling()); |
| 338 registration_finished_callbacks_.push_back(callback); | 341 registration_finished_callbacks_.push_back(callback); |
| 339 } | 342 } |
| 340 | 343 |
| 344 void ServiceWorkerRegistration::DispatchActivateEvent( |
| 345 const scoped_refptr<ServiceWorkerVersion>& activating_version) { |
| 346 if (activating_version != active_version()) { |
| 347 OnActivateEventFinished(activating_version, SERVICE_WORKER_ERROR_FAILED); |
| 348 return; |
| 349 } |
| 350 |
| 351 DCHECK_EQ(ServiceWorkerVersion::ACTIVATING, activating_version->status()); |
| 352 DCHECK_EQ(ServiceWorkerVersion::RUNNING, activating_version->running_status()) |
| 353 << "Worker stopped too soon after it was started."; |
| 354 int request_id = activating_version->StartRequest( |
| 355 ServiceWorkerMetrics::EventType::ACTIVATE, |
| 356 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, this, |
| 357 activating_version)); |
| 358 activating_version |
| 359 ->DispatchSimpleEvent<ServiceWorkerHostMsg_ActivateEventFinished>( |
| 360 request_id, ServiceWorkerMsg_ActivateEvent(request_id)); |
| 361 } |
| 362 |
| 341 void ServiceWorkerRegistration::OnActivateEventFinished( | 363 void ServiceWorkerRegistration::OnActivateEventFinished( |
| 342 ServiceWorkerVersion* activating_version, | 364 const scoped_refptr<ServiceWorkerVersion>& activating_version, |
| 343 ServiceWorkerStatusCode status) { | 365 ServiceWorkerStatusCode status) { |
| 344 if (!context_ || activating_version != active_version() || | 366 if (!context_ || activating_version != active_version() || |
| 345 activating_version->status() != ServiceWorkerVersion::ACTIVATING) | 367 activating_version->status() != ServiceWorkerVersion::ACTIVATING) |
| 346 return; | 368 return; |
| 347 | 369 |
| 348 // |status| is just for UMA. Once we've attempted to dispatch the activate | 370 // |status| is just for UMA. Once we've attempted to dispatch the activate |
| 349 // event to an installed worker, it's committed to becoming active. | 371 // event to an installed worker, it's committed to becoming active. |
| 350 ServiceWorkerMetrics::RecordActivateEventStatus(status); | 372 ServiceWorkerMetrics::RecordActivateEventStatus(status); |
| 351 | 373 |
| 352 // "Run the Update State algorithm passing registration's active worker and | 374 // "Run the Update State algorithm passing registration's active worker and |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 if (!context_) { | 430 if (!context_) { |
| 409 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 431 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 410 return; | 432 return; |
| 411 } | 433 } |
| 412 context_->storage()->NotifyDoneInstallingRegistration( | 434 context_->storage()->NotifyDoneInstallingRegistration( |
| 413 this, version.get(), status); | 435 this, version.get(), status); |
| 414 callback.Run(status); | 436 callback.Run(status); |
| 415 } | 437 } |
| 416 | 438 |
| 417 } // namespace content | 439 } // namespace content |
| OLD | NEW |