Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: content/browser/service_worker/service_worker_register_job.cc

Issue 1381153004: Service Worker: Change the criteria for bumping the last update check time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid reading disk for first time registrations. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
falken 2015/12/07 07:40:33 Please add a comment here about the side effect of
jungkees 2015/12/15 13:07:45 Done.
355 if (new_version()->embedded_worker()->network_accessed_for_script() ||
356 new_version()->force_bypass_cache_for_scripts()) {
357 registration()->set_last_update_check(base::Time::Now());
358
359 // Avoid reading disk for first time registrations.
falken 2015/12/07 07:40:33 I think you can just remove this comment. It's cle
jungkees 2015/12/15 13:07:45 Done.
360 if (job_type_ == UPDATE_JOB)
361 context_->storage()->UpdateLastUpdateCheckTime(registration());
362 }
363
353 if (status == SERVICE_WORKER_OK) { 364 if (status == SERVICE_WORKER_OK) {
354 InstallAndContinue(); 365 InstallAndContinue();
355 return; 366 return;
356 } 367 }
357 368
358 // The updated worker is identical to the incumbent. 369 // The updated worker is identical to the incumbent.
359 if (status == SERVICE_WORKER_ERROR_EXISTS) { 370 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()); 371 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration());
371 Complete(status, "The updated worker is identical to the incumbent."); 372 Complete(status, "The updated worker is identical to the incumbent.");
372 return; 373 return;
373 } 374 }
374 375
375 // "If serviceWorker fails to start up..." then reject the promise with an 376 // "If serviceWorker fails to start up..." then reject the promise with an
376 // error and abort. 377 // error and abort.
377 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { 378 if (status == SERVICE_WORKER_ERROR_TIMEOUT) {
378 Complete(status, "Timed out while trying to start the Service Worker."); 379 Complete(status, "Timed out while trying to start the Service Worker.");
379 return; 380 return;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 ServiceWorkerStatusCode status) { 425 ServiceWorkerStatusCode status) {
425 ServiceWorkerMetrics::RecordInstallEventStatus(status); 426 ServiceWorkerMetrics::RecordInstallEventStatus(status);
426 427
427 if (status != SERVICE_WORKER_OK) { 428 if (status != SERVICE_WORKER_OK) {
428 // "8. If installFailed is true, then:..." 429 // "8. If installFailed is true, then:..."
429 Complete(status); 430 Complete(status);
430 return; 431 return;
431 } 432 }
432 433
433 SetPhase(STORE); 434 SetPhase(STORE);
434 registration()->set_last_update_check(base::Time::Now());
435 context_->storage()->StoreRegistration( 435 context_->storage()->StoreRegistration(
436 registration(), 436 registration(),
437 new_version(), 437 new_version(),
438 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, 438 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete,
439 weak_factory_.GetWeakPtr())); 439 weak_factory_.GetWeakPtr()));
440 } 440 }
441 441
442 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( 442 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete(
443 ServiceWorkerStatusCode status) { 443 ServiceWorkerStatusCode status) {
444 if (status != SERVICE_WORKER_OK) { 444 if (status != SERVICE_WORKER_OK) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 if (host->IsHostToRunningServiceWorker()) 545 if (host->IsHostToRunningServiceWorker())
546 continue; 546 continue;
547 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), 547 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(),
548 host->document_url())) 548 host->document_url()))
549 continue; 549 continue;
550 host->AddMatchingRegistration(registration); 550 host->AddMatchingRegistration(registration);
551 } 551 }
552 } 552 }
553 553
554 } // namespace content 554 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698