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()->last_update_check().is_null()) { | |
| 363 registration()->set_last_update_check(base::Time::Now()); | |
| 364 | |
| 365 if (registration()->waiting_version() || registration()->active_version()) | |
| 366 context_->storage()->UpdateLastUpdateCheckTime(registration()); | |
| 367 } else { | |
| 368 DCHECK(!registration()->last_update_check().is_null()); | |
|
michaeln
2016/01/22 19:48:13
This dcheck is very useless here. If the time is n
jungkees
2016/01/25 20:03:00
I moved the dcheck as suggested.
| |
| 369 } | |
| 370 | |
| 355 if (status == SERVICE_WORKER_OK) { | 371 if (status == SERVICE_WORKER_OK) { |
| 356 InstallAndContinue(); | 372 InstallAndContinue(); |
| 357 return; | 373 return; |
| 358 } | 374 } |
| 359 | 375 |
| 360 // The updated worker is identical to the incumbent. | 376 // The updated worker is identical to the incumbent. |
| 361 if (status == SERVICE_WORKER_ERROR_EXISTS) { | 377 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()); | 378 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); |
| 373 Complete(status, "The updated worker is identical to the incumbent."); | 379 Complete(status, "The updated worker is identical to the incumbent."); |
| 374 return; | 380 return; |
| 375 } | 381 } |
| 376 | 382 |
| 377 // "If serviceWorker fails to start up..." then reject the promise with an | 383 // "If serviceWorker fails to start up..." then reject the promise with an |
| 378 // error and abort. | 384 // error and abort. |
| 379 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { | 385 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { |
| 380 Complete(status, "Timed out while trying to start the Service Worker."); | 386 Complete(status, "Timed out while trying to start the Service Worker."); |
| 381 return; | 387 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 void ServiceWorkerRegisterJob::OnInstallFinished( | 431 void ServiceWorkerRegisterJob::OnInstallFinished( |
| 426 ServiceWorkerStatusCode status) { | 432 ServiceWorkerStatusCode status) { |
| 427 ServiceWorkerMetrics::RecordInstallEventStatus(status); | 433 ServiceWorkerMetrics::RecordInstallEventStatus(status); |
| 428 | 434 |
| 429 if (status != SERVICE_WORKER_OK) { | 435 if (status != SERVICE_WORKER_OK) { |
| 430 // "8. If installFailed is true, then:..." | 436 // "8. If installFailed is true, then:..." |
| 431 Complete(status); | 437 Complete(status); |
| 432 return; | 438 return; |
| 433 } | 439 } |
| 434 | 440 |
| 435 SetPhase(STORE); | 441 SetPhase(STORE); |
|
michaeln
2016/01/22 19:48:13
If you're going to add the dcheck, please put it h
jungkees
2016/01/25 20:03:00
Yes, I moved the dcheck here.
| |
| 436 registration()->set_last_update_check(base::Time::Now()); | |
| 437 context_->storage()->StoreRegistration( | 442 context_->storage()->StoreRegistration( |
| 438 registration(), | 443 registration(), |
| 439 new_version(), | 444 new_version(), |
| 440 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, | 445 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, |
| 441 weak_factory_.GetWeakPtr())); | 446 weak_factory_.GetWeakPtr())); |
| 442 } | 447 } |
| 443 | 448 |
| 444 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( | 449 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( |
| 445 ServiceWorkerStatusCode status) { | 450 ServiceWorkerStatusCode status) { |
| 446 if (status != SERVICE_WORKER_OK) { | 451 if (status != SERVICE_WORKER_OK) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 if (host->IsHostToRunningServiceWorker()) | 552 if (host->IsHostToRunningServiceWorker()) |
| 548 continue; | 553 continue; |
| 549 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 554 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
| 550 host->document_url())) | 555 host->document_url())) |
| 551 continue; | 556 continue; |
| 552 host->AddMatchingRegistration(registration); | 557 host->AddMatchingRegistration(registration); |
| 553 } | 558 } |
| 554 } | 559 } |
| 555 | 560 |
| 556 } // namespace content | 561 } // namespace content |
| OLD | NEW |