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