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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 void ServiceWorkerRegisterJob::OnStartWorkerFinished( | 338 void ServiceWorkerRegisterJob::OnStartWorkerFinished( |
339 ServiceWorkerStatusCode status) { | 339 ServiceWorkerStatusCode status) { |
340 if (status == SERVICE_WORKER_OK) { | 340 if (status == SERVICE_WORKER_OK) { |
341 InstallAndContinue(); | 341 InstallAndContinue(); |
342 return; | 342 return; |
343 } | 343 } |
344 | 344 |
345 // The updated worker is identical to the incumbent. | 345 // The updated worker is identical to the incumbent. |
346 if (status == SERVICE_WORKER_ERROR_EXISTS) { | 346 if (status == SERVICE_WORKER_ERROR_EXISTS) { |
347 // Only bump the last check time when we've bypassed the browser cache. | |
348 base::TimeDelta time_since_last_check = | |
349 base::Time::Now() - registration()->last_update_check(); | |
350 if (time_since_last_check > base::TimeDelta::FromHours( | |
351 kServiceWorkerScriptMaxCacheAgeInHours) || | |
352 new_version()->force_bypass_cache_for_scripts()) { | |
353 registration()->set_last_update_check(base::Time::Now()); | |
354 context_->storage()->UpdateLastUpdateCheckTime(registration()); | |
355 } | |
356 | |
357 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); | 347 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); |
358 Complete(status, "The updated worker is identical to the incumbent."); | 348 Complete(status, "The updated worker is identical to the incumbent."); |
359 return; | 349 return; |
360 } | 350 } |
361 | 351 |
362 // "If serviceWorker fails to start up..." then reject the promise with an | 352 // "If serviceWorker fails to start up..." then reject the promise with an |
363 // error and abort. | 353 // error and abort. |
364 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { | 354 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { |
365 Complete(status, "Timed out while trying to start the Service Worker."); | 355 Complete(status, "Timed out while trying to start the Service Worker."); |
366 return; | 356 return; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 ServiceWorkerStatusCode status) { | 401 ServiceWorkerStatusCode status) { |
412 ServiceWorkerMetrics::RecordInstallEventStatus(status); | 402 ServiceWorkerMetrics::RecordInstallEventStatus(status); |
413 | 403 |
414 if (status != SERVICE_WORKER_OK) { | 404 if (status != SERVICE_WORKER_OK) { |
415 // "8. If installFailed is true, then:..." | 405 // "8. If installFailed is true, then:..." |
416 Complete(status); | 406 Complete(status); |
417 return; | 407 return; |
418 } | 408 } |
419 | 409 |
420 SetPhase(STORE); | 410 SetPhase(STORE); |
421 registration()->set_last_update_check(base::Time::Now()); | |
422 context_->storage()->StoreRegistration( | 411 context_->storage()->StoreRegistration( |
423 registration(), | 412 registration(), |
424 new_version(), | 413 new_version(), |
425 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, | 414 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, |
426 weak_factory_.GetWeakPtr())); | 415 weak_factory_.GetWeakPtr())); |
427 } | 416 } |
428 | 417 |
429 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( | 418 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( |
430 ServiceWorkerStatusCode status) { | 419 ServiceWorkerStatusCode status) { |
431 if (status != SERVICE_WORKER_OK) { | 420 if (status != SERVICE_WORKER_OK) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 if (host->IsHostToRunningServiceWorker()) | 521 if (host->IsHostToRunningServiceWorker()) |
533 continue; | 522 continue; |
534 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 523 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
535 host->document_url())) | 524 host->document_url())) |
536 continue; | 525 continue; |
537 host->AddMatchingRegistration(registration); | 526 host->AddMatchingRegistration(registration); |
538 } | 527 } |
539 } | 528 } |
540 | 529 |
541 } // namespace content | 530 } // namespace content |
OLD | NEW |