| 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 new_version()->set_pause_after_download(false); | 351 new_version()->set_pause_after_download(false); |
| 352 } | 352 } |
| 353 new_version()->StartWorker( | 353 new_version()->StartWorker( |
| 354 ServiceWorkerMetrics::EventType::INSTALL, | 354 ServiceWorkerMetrics::EventType::INSTALL, |
| 355 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, | 355 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, |
| 356 weak_factory_.GetWeakPtr())); | 356 weak_factory_.GetWeakPtr())); |
| 357 } | 357 } |
| 358 | 358 |
| 359 void ServiceWorkerRegisterJob::OnStartWorkerFinished( | 359 void ServiceWorkerRegisterJob::OnStartWorkerFinished( |
| 360 ServiceWorkerStatusCode status) { | 360 ServiceWorkerStatusCode status) { |
| 361 // Bump the last update check time only when the register/update job fetched | 361 BumpLastUpdateCheckTimeIfNeeded(); |
| 362 // the version having bypassed the network cache. We assume that the | |
| 363 // BYPASS_CACHE flag evicts an existing cache entry, so even if the install | |
| 364 // ultimately failed for whatever reason, we know the version in the HTTP | |
| 365 // cache is not stale, so it's OK to bump the update check time. | |
| 366 if (new_version()->embedded_worker()->network_accessed_for_script() || | |
| 367 new_version()->force_bypass_cache_for_scripts() || | |
| 368 registration()->last_update_check().is_null()) { | |
| 369 registration()->set_last_update_check(base::Time::Now()); | |
| 370 | |
| 371 if (registration()->has_installed_version()) | |
| 372 context_->storage()->UpdateLastUpdateCheckTime(registration()); | |
| 373 } | |
| 374 | 362 |
| 375 if (status == SERVICE_WORKER_OK) { | 363 if (status == SERVICE_WORKER_OK) { |
| 376 InstallAndContinue(); | 364 InstallAndContinue(); |
| 377 return; | 365 return; |
| 378 } | 366 } |
| 379 | 367 |
| 380 // "If serviceWorker fails to start up..." then reject the promise with an | 368 // "If serviceWorker fails to start up..." then reject the promise with an |
| 381 // error and abort. | 369 // error and abort. |
| 382 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { | 370 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { |
| 383 Complete(status, "Timed out while trying to start the Service Worker."); | 371 Complete(status, "Timed out while trying to start the Service Worker."); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 void ServiceWorkerRegisterJob::OnScriptLoaded() { | 570 void ServiceWorkerRegisterJob::OnScriptLoaded() { |
| 583 DCHECK(new_version()->pause_after_download()); | 571 DCHECK(new_version()->pause_after_download()); |
| 584 new_version()->set_pause_after_download(false); | 572 new_version()->set_pause_after_download(false); |
| 585 net::URLRequestStatus status = | 573 net::URLRequestStatus status = |
| 586 new_version()->script_cache_map()->main_script_status(); | 574 new_version()->script_cache_map()->main_script_status(); |
| 587 if (!status.is_success()) { | 575 if (!status.is_success()) { |
| 588 // OnScriptLoaded signifies a successful network load, which translates into | 576 // OnScriptLoaded signifies a successful network load, which translates into |
| 589 // a script cache error only in the byte-for-byte identical case. | 577 // a script cache error only in the byte-for-byte identical case. |
| 590 DCHECK_EQ(status.error(), | 578 DCHECK_EQ(status.error(), |
| 591 ServiceWorkerWriteToCacheJob::kIdenticalScriptError); | 579 ServiceWorkerWriteToCacheJob::kIdenticalScriptError); |
| 580 |
| 581 BumpLastUpdateCheckTimeIfNeeded(); |
| 592 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); | 582 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); |
| 593 Complete(SERVICE_WORKER_ERROR_EXISTS, | 583 Complete(SERVICE_WORKER_ERROR_EXISTS, |
| 594 "The updated worker is identical to the incumbent."); | 584 "The updated worker is identical to the incumbent."); |
| 595 return; | 585 return; |
| 596 } | 586 } |
| 597 | 587 |
| 598 new_version()->embedded_worker()->ResumeAfterDownload(); | 588 new_version()->embedded_worker()->ResumeAfterDownload(); |
| 599 } | 589 } |
| 600 | 590 |
| 591 void ServiceWorkerRegisterJob::BumpLastUpdateCheckTimeIfNeeded() { |
| 592 // Bump the last update check time only when the register/update job fetched |
| 593 // the version having bypassed the network cache. We assume that the |
| 594 // BYPASS_CACHE flag evicts an existing cache entry, so even if the install |
| 595 // ultimately failed for whatever reason, we know the version in the HTTP |
| 596 // cache is not stale, so it's OK to bump the update check time. |
| 597 if (new_version()->embedded_worker()->network_accessed_for_script() || |
| 598 new_version()->force_bypass_cache_for_scripts() || |
| 599 registration()->last_update_check().is_null()) { |
| 600 registration()->set_last_update_check(base::Time::Now()); |
| 601 |
| 602 if (registration()->has_installed_version()) |
| 603 context_->storage()->UpdateLastUpdateCheckTime(registration()); |
| 604 } |
| 605 } |
| 606 |
| 601 } // namespace content | 607 } // namespace content |
| OLD | NEW |