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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 version_id, context_)); | 343 version_id, context_)); |
| 344 new_version()->set_force_bypass_cache_for_scripts(force_bypass_cache_); | 344 new_version()->set_force_bypass_cache_for_scripts(force_bypass_cache_); |
| 345 new_version()->set_skip_script_comparison(skip_script_comparison_); | 345 new_version()->set_skip_script_comparison(skip_script_comparison_); |
| 346 new_version()->StartWorker( | 346 new_version()->StartWorker( |
| 347 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, | 347 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, |
| 348 weak_factory_.GetWeakPtr())); | 348 weak_factory_.GetWeakPtr())); |
| 349 } | 349 } |
| 350 | 350 |
| 351 void ServiceWorkerRegisterJob::OnStartWorkerFinished( | 351 void ServiceWorkerRegisterJob::OnStartWorkerFinished( |
| 352 ServiceWorkerStatusCode status) { | 352 ServiceWorkerStatusCode status) { |
| 353 // Bump the last update check time only when the register/update job fetched | |
| 354 // the version having bypassed the network cache. We assume that the | |
| 355 // BYPASS_CACHE flag evicts an existing cache entry, so even if the successive | |
|
falken
2015/12/17 13:23:43
nit: "successive" seems confusing. I'd just remove
jungkees
2015/12/23 03:08:58
Done.
| |
| 356 // install ultimately failed for whatever reason, we know the version in the | |
| 357 // HTTP cache is not stale, so it's OK to bump the update check time. | |
| 358 if (new_version()->embedded_worker()->network_accessed_for_script() || | |
| 359 new_version()->force_bypass_cache_for_scripts()) { | |
| 360 registration()->set_last_update_check(base::Time::Now()); | |
| 361 | |
| 362 if (job_type_ == UPDATE_JOB) | |
| 363 context_->storage()->UpdateLastUpdateCheckTime(registration()); | |
| 364 } | |
| 365 | |
| 353 if (status == SERVICE_WORKER_OK) { | 366 if (status == SERVICE_WORKER_OK) { |
| 354 InstallAndContinue(); | 367 InstallAndContinue(); |
| 355 return; | 368 return; |
| 356 } | 369 } |
| 357 | 370 |
| 358 // The updated worker is identical to the incumbent. | 371 // The updated worker is identical to the incumbent. |
| 359 if (status == SERVICE_WORKER_ERROR_EXISTS) { | 372 if (status == SERVICE_WORKER_ERROR_EXISTS) { |
| 360 // Only bump the last check time when we've bypassed the browser cache. | |
| 361 base::TimeDelta time_since_last_check = | |
| 362 base::Time::Now() - registration()->last_update_check(); | |
| 363 if (time_since_last_check > base::TimeDelta::FromHours( | |
| 364 kServiceWorkerScriptMaxCacheAgeInHours) || | |
| 365 new_version()->force_bypass_cache_for_scripts()) { | |
| 366 registration()->set_last_update_check(base::Time::Now()); | |
| 367 context_->storage()->UpdateLastUpdateCheckTime(registration()); | |
| 368 } | |
| 369 | |
| 370 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); | 373 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); |
| 371 Complete(status, "The updated worker is identical to the incumbent."); | 374 Complete(status, "The updated worker is identical to the incumbent."); |
| 372 return; | 375 return; |
| 373 } | 376 } |
| 374 | 377 |
| 375 // "If serviceWorker fails to start up..." then reject the promise with an | 378 // "If serviceWorker fails to start up..." then reject the promise with an |
| 376 // error and abort. | 379 // error and abort. |
| 377 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { | 380 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { |
| 378 Complete(status, "Timed out while trying to start the Service Worker."); | 381 Complete(status, "Timed out while trying to start the Service Worker."); |
| 379 return; | 382 return; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 ServiceWorkerStatusCode status) { | 427 ServiceWorkerStatusCode status) { |
| 425 ServiceWorkerMetrics::RecordInstallEventStatus(status); | 428 ServiceWorkerMetrics::RecordInstallEventStatus(status); |
| 426 | 429 |
| 427 if (status != SERVICE_WORKER_OK) { | 430 if (status != SERVICE_WORKER_OK) { |
| 428 // "8. If installFailed is true, then:..." | 431 // "8. If installFailed is true, then:..." |
| 429 Complete(status); | 432 Complete(status); |
| 430 return; | 433 return; |
| 431 } | 434 } |
| 432 | 435 |
| 433 SetPhase(STORE); | 436 SetPhase(STORE); |
| 434 registration()->set_last_update_check(base::Time::Now()); | |
| 435 context_->storage()->StoreRegistration( | 437 context_->storage()->StoreRegistration( |
| 436 registration(), | 438 registration(), |
| 437 new_version(), | 439 new_version(), |
| 438 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, | 440 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, |
| 439 weak_factory_.GetWeakPtr())); | 441 weak_factory_.GetWeakPtr())); |
| 440 } | 442 } |
| 441 | 443 |
| 442 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( | 444 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( |
| 443 ServiceWorkerStatusCode status) { | 445 ServiceWorkerStatusCode status) { |
| 444 if (status != SERVICE_WORKER_OK) { | 446 if (status != SERVICE_WORKER_OK) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 if (host->IsHostToRunningServiceWorker()) | 547 if (host->IsHostToRunningServiceWorker()) |
| 546 continue; | 548 continue; |
| 547 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 549 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
| 548 host->document_url())) | 550 host->document_url())) |
| 549 continue; | 551 continue; |
| 550 host->AddMatchingRegistration(registration); | 552 host->AddMatchingRegistration(registration); |
| 551 } | 553 } |
| 552 } | 554 } |
| 553 | 555 |
| 554 } // namespace content | 556 } // namespace content |
| OLD | NEW |