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_register_job.h" | 5 #include "content/browser/service_worker/service_worker_register_job.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); | 403 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); |
| 404 | 404 |
| 405 // "Fire a simple event named updatefound..." | 405 // "Fire a simple event named updatefound..." |
| 406 registration()->NotifyUpdateFound(); | 406 registration()->NotifyUpdateFound(); |
| 407 | 407 |
| 408 // "Fire an event named install..." | 408 // "Fire an event named install..." |
| 409 new_version()->RunAfterStartWorker( | 409 new_version()->RunAfterStartWorker( |
| 410 ServiceWorkerMetrics::EventType::INSTALL, | 410 ServiceWorkerMetrics::EventType::INSTALL, |
| 411 base::Bind(&ServiceWorkerRegisterJob::DispatchInstallEvent, | 411 base::Bind(&ServiceWorkerRegisterJob::DispatchInstallEvent, |
| 412 weak_factory_.GetWeakPtr()), | 412 weak_factory_.GetWeakPtr()), |
| 413 base::Bind(&ServiceWorkerRegisterJob::OnInstallFinished, | 413 base::Bind(&ServiceWorkerRegisterJob::OnInstallFailed, |
| 414 weak_factory_.GetWeakPtr())); | 414 weak_factory_.GetWeakPtr())); |
| 415 | 415 |
| 416 // A subsequent registration job may terminate our installing worker. It can | 416 // A subsequent registration job may terminate our installing worker. It can |
| 417 // only do so after we've started the worker and dispatched the install | 417 // only do so after we've started the worker and dispatched the install |
| 418 // event, as those are atomic substeps in the [[Install]] algorithm. | 418 // event, as those are atomic substeps in the [[Install]] algorithm. |
| 419 if (doom_installing_worker_) | 419 if (doom_installing_worker_) |
| 420 Complete(SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); | 420 Complete(SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); |
| 421 } | 421 } |
| 422 | 422 |
| 423 void ServiceWorkerRegisterJob::DispatchInstallEvent() { | 423 void ServiceWorkerRegisterJob::DispatchInstallEvent() { |
| 424 DCHECK_EQ(ServiceWorkerVersion::INSTALLING, new_version()->status()) | 424 DCHECK_EQ(ServiceWorkerVersion::INSTALLING, new_version()->status()) |
| 425 << new_version()->status(); | 425 << new_version()->status(); |
| 426 DCHECK_EQ(ServiceWorkerVersion::RUNNING, new_version()->running_status()) | 426 DCHECK_EQ(ServiceWorkerVersion::RUNNING, new_version()->running_status()) |
| 427 << "Worker stopped too soon after it was started."; | 427 << "Worker stopped too soon after it was started."; |
| 428 int request_id = new_version()->StartRequest( | 428 int request_id = new_version()->StartRequest( |
| 429 ServiceWorkerMetrics::EventType::INSTALL, | 429 ServiceWorkerMetrics::EventType::INSTALL, |
| 430 base::Bind(&ServiceWorkerRegisterJob::OnInstallFailed, | |
| 431 weak_factory_.GetWeakPtr())); | |
| 432 new_version()->DispatchEvent<ServiceWorkerHostMsg_InstallEventFinished>( | |
| 433 request_id, ServiceWorkerMsg_InstallEvent(request_id), | |
| 430 base::Bind(&ServiceWorkerRegisterJob::OnInstallFinished, | 434 base::Bind(&ServiceWorkerRegisterJob::OnInstallFinished, |
| 431 weak_factory_.GetWeakPtr())); | 435 weak_factory_.GetWeakPtr())); |
| 432 new_version()->DispatchSimpleEvent<ServiceWorkerHostMsg_InstallEventFinished>( | |
| 433 request_id, ServiceWorkerMsg_InstallEvent(request_id)); | |
| 434 } | 436 } |
| 435 | 437 |
| 436 void ServiceWorkerRegisterJob::OnInstallFinished( | 438 void ServiceWorkerRegisterJob::OnInstallFinished( |
| 437 ServiceWorkerStatusCode status) { | 439 int request_id, |
| 438 ServiceWorkerMetrics::RecordInstallEventStatus(status); | 440 blink::WebServiceWorkerEventResult result, |
| 441 bool has_fetch_handler) { | |
| 442 new_version()->FinishRequest( | |
| 443 request_id, result == blink::WebServiceWorkerEventResultCompleted); | |
| 444 | |
| 445 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
| 446 switch (result) { | |
| 447 case blink::WebServiceWorkerEventResultCompleted: | |
| 448 status = SERVICE_WORKER_OK; | |
| 449 break; | |
| 450 case blink::WebServiceWorkerEventResultRejected: | |
| 451 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; | |
| 452 break; | |
|
falken
2016/05/25 01:19:35
default: NOTREACHED()
shimazu
2016/05/25 03:35:13
Done.
| |
| 453 } | |
| 439 | 454 |
| 440 if (status != SERVICE_WORKER_OK) { | 455 if (status != SERVICE_WORKER_OK) { |
| 441 // "8. If installFailed is true, then:..." | 456 OnInstallFailed(status); |
| 442 Complete(status, std::string("ServiceWorker failed to install: ") + | |
| 443 ServiceWorkerStatusToString(status)); | |
| 444 return; | 457 return; |
| 445 } | 458 } |
| 446 | 459 |
| 460 ServiceWorkerMetrics::RecordInstallEventStatus(status); | |
| 461 | |
| 447 SetPhase(STORE); | 462 SetPhase(STORE); |
| 448 DCHECK(!registration()->last_update_check().is_null()); | 463 DCHECK(!registration()->last_update_check().is_null()); |
| 464 new_version()->set_has_fetch_handler(has_fetch_handler); | |
| 449 context_->storage()->StoreRegistration( | 465 context_->storage()->StoreRegistration( |
| 450 registration(), | 466 registration(), |
| 451 new_version(), | 467 new_version(), |
| 452 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, | 468 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, |
| 453 weak_factory_.GetWeakPtr())); | 469 weak_factory_.GetWeakPtr())); |
| 454 } | 470 } |
| 455 | 471 |
| 472 void ServiceWorkerRegisterJob::OnInstallFailed(ServiceWorkerStatusCode status) { | |
| 473 ServiceWorkerMetrics::RecordInstallEventStatus(status); | |
| 474 | |
| 475 if (status != SERVICE_WORKER_OK) { | |
| 476 Complete(status, std::string("ServiceWorker failed to install: ") + | |
| 477 ServiceWorkerStatusToString(status)); | |
| 478 } else { | |
| 479 NOTREACHED() << "OnInstallFailed should not handle SERVICE_WORKER_OK"; | |
| 480 } | |
| 481 } | |
| 482 | |
| 456 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( | 483 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( |
| 457 ServiceWorkerStatusCode status) { | 484 ServiceWorkerStatusCode status) { |
| 458 if (status != SERVICE_WORKER_OK) { | 485 if (status != SERVICE_WORKER_OK) { |
| 459 Complete(status); | 486 Complete(status); |
| 460 return; | 487 return; |
| 461 } | 488 } |
| 462 | 489 |
| 463 // "9. If registration.waitingWorker is not null, then:..." | 490 // "9. If registration.waitingWorker is not null, then:..." |
| 464 if (registration()->waiting_version()) { | 491 if (registration()->waiting_version()) { |
| 465 // "1. Run the [[UpdateState]] algorithm passing registration.waitingWorker | 492 // "1. Run the [[UpdateState]] algorithm passing registration.waitingWorker |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 new_version()->force_bypass_cache_for_scripts() || | 629 new_version()->force_bypass_cache_for_scripts() || |
| 603 registration()->last_update_check().is_null()) { | 630 registration()->last_update_check().is_null()) { |
| 604 registration()->set_last_update_check(base::Time::Now()); | 631 registration()->set_last_update_check(base::Time::Now()); |
| 605 | 632 |
| 606 if (registration()->has_installed_version()) | 633 if (registration()->has_installed_version()) |
| 607 context_->storage()->UpdateLastUpdateCheckTime(registration()); | 634 context_->storage()->UpdateLastUpdateCheckTime(registration()); |
| 608 } | 635 } |
| 609 } | 636 } |
| 610 | 637 |
| 611 } // namespace content | 638 } // namespace content |
| OLD | NEW |