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 <vector> | 7 #include <vector> |
| 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 context_)); | 333 context_)); |
| 334 new_version()->set_force_bypass_cache_for_scripts(force_bypass_cache_); | 334 new_version()->set_force_bypass_cache_for_scripts(force_bypass_cache_); |
| 335 new_version()->set_skip_script_comparison(skip_script_comparison_); | 335 new_version()->set_skip_script_comparison(skip_script_comparison_); |
| 336 new_version()->StartWorker( | 336 new_version()->StartWorker( |
| 337 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, | 337 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, |
| 338 weak_factory_.GetWeakPtr())); | 338 weak_factory_.GetWeakPtr())); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void ServiceWorkerRegisterJob::OnStartWorkerFinished( | 341 void ServiceWorkerRegisterJob::OnStartWorkerFinished( |
| 342 ServiceWorkerStatusCode status) { | 342 ServiceWorkerStatusCode status) { |
| 343 // Only bump the last check time when we've bypassed the browser cache. | |
| 344 if (new_version()->embedded_worker()->network_accessed_for_script() || | |
| 345 new_version()->force_bypass_cache_for_scripts()) { | |
| 346 registration()->set_last_update_check(base::Time::Now()); | |
| 347 context_->storage()->UpdateLastUpdateCheckTime(registration()); | |
|
michaeln
2015/11/09 23:19:10
This block is reachable for first time registratio
jungkees
2015/11/10 02:45:17
Executing this part of the code for the first time
falken
2015/12/02 09:27:39
Michael is saying that for first time registration
jungkees
2015/12/04 11:46:38
Having inspected the code sequence for a first tim
falken
2015/12/07 03:53:34
Right, it's a no-op but it requires reading disk w
jungkees
2015/12/07 07:02:09
Great. I made it only UPDATE_JOBs write to disk.
| |
| 348 } | |
| 349 | |
| 343 if (status == SERVICE_WORKER_OK) { | 350 if (status == SERVICE_WORKER_OK) { |
| 344 InstallAndContinue(); | 351 InstallAndContinue(); |
| 345 return; | 352 return; |
| 346 } | 353 } |
| 347 | 354 |
| 348 // The updated worker is identical to the incumbent. | 355 // The updated worker is identical to the incumbent. |
| 349 if (status == SERVICE_WORKER_ERROR_EXISTS) { | 356 if (status == SERVICE_WORKER_ERROR_EXISTS) { |
| 350 // Only bump the last check time when we've bypassed the browser cache. | |
| 351 base::TimeDelta time_since_last_check = | |
| 352 base::Time::Now() - registration()->last_update_check(); | |
| 353 if (time_since_last_check > base::TimeDelta::FromHours( | |
| 354 kServiceWorkerScriptMaxCacheAgeInHours) || | |
| 355 new_version()->force_bypass_cache_for_scripts()) { | |
| 356 registration()->set_last_update_check(base::Time::Now()); | |
| 357 context_->storage()->UpdateLastUpdateCheckTime(registration()); | |
| 358 } | |
| 359 | |
| 360 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); | 357 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); |
| 361 Complete(status, "The updated worker is identical to the incumbent."); | 358 Complete(status, "The updated worker is identical to the incumbent."); |
| 362 return; | 359 return; |
| 363 } | 360 } |
| 364 | 361 |
| 365 // "If serviceWorker fails to start up..." then reject the promise with an | 362 // "If serviceWorker fails to start up..." then reject the promise with an |
| 366 // error and abort. | 363 // error and abort. |
| 367 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { | 364 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { |
| 368 Complete(status, "Timed out while trying to start the Service Worker."); | 365 Complete(status, "Timed out while trying to start the Service Worker."); |
| 369 return; | 366 return; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 ServiceWorkerStatusCode status) { | 411 ServiceWorkerStatusCode status) { |
| 415 ServiceWorkerMetrics::RecordInstallEventStatus(status); | 412 ServiceWorkerMetrics::RecordInstallEventStatus(status); |
| 416 | 413 |
| 417 if (status != SERVICE_WORKER_OK) { | 414 if (status != SERVICE_WORKER_OK) { |
| 418 // "8. If installFailed is true, then:..." | 415 // "8. If installFailed is true, then:..." |
| 419 Complete(status); | 416 Complete(status); |
| 420 return; | 417 return; |
| 421 } | 418 } |
| 422 | 419 |
| 423 SetPhase(STORE); | 420 SetPhase(STORE); |
| 424 registration()->set_last_update_check(base::Time::Now()); | |
| 425 context_->storage()->StoreRegistration( | 421 context_->storage()->StoreRegistration( |
| 426 registration(), | 422 registration(), |
| 427 new_version(), | 423 new_version(), |
| 428 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, | 424 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, |
| 429 weak_factory_.GetWeakPtr())); | 425 weak_factory_.GetWeakPtr())); |
| 430 } | 426 } |
| 431 | 427 |
| 432 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( | 428 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( |
| 433 ServiceWorkerStatusCode status) { | 429 ServiceWorkerStatusCode status) { |
| 434 if (status != SERVICE_WORKER_OK) { | 430 if (status != SERVICE_WORKER_OK) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 if (host->IsHostToRunningServiceWorker()) | 531 if (host->IsHostToRunningServiceWorker()) |
| 536 continue; | 532 continue; |
| 537 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 533 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
| 538 host->document_url())) | 534 host->document_url())) |
| 539 continue; | 535 continue; |
| 540 host->AddMatchingRegistration(registration); | 536 host->AddMatchingRegistration(registration); |
| 541 } | 537 } |
| 542 } | 538 } |
| 543 | 539 |
| 544 } // namespace content | 540 } // namespace content |
| OLD | NEW |