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

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: Update the unittest. 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. As bypassing the network
355 // cache will evict an existing cache entry, it is okay to bump the update
356 // check time.
falken 2015/12/16 08:27:48 I think the second sentence of this comment would
jungkees 2015/12/16 08:59:20 Thanks for the comment. I used the words as-is exc
357 if (new_version()->embedded_worker()->network_accessed_for_script() ||
358 new_version()->force_bypass_cache_for_scripts()) {
359 registration()->set_last_update_check(base::Time::Now());
360
361 if (job_type_ == UPDATE_JOB)
362 context_->storage()->UpdateLastUpdateCheckTime(registration());
363 }
364
353 if (status == SERVICE_WORKER_OK) { 365 if (status == SERVICE_WORKER_OK) {
354 InstallAndContinue(); 366 InstallAndContinue();
355 return; 367 return;
356 } 368 }
357 369
358 // The updated worker is identical to the incumbent. 370 // The updated worker is identical to the incumbent.
359 if (status == SERVICE_WORKER_ERROR_EXISTS) { 371 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()); 372 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration());
371 Complete(status, "The updated worker is identical to the incumbent."); 373 Complete(status, "The updated worker is identical to the incumbent.");
372 return; 374 return;
373 } 375 }
374 376
375 // "If serviceWorker fails to start up..." then reject the promise with an 377 // "If serviceWorker fails to start up..." then reject the promise with an
376 // error and abort. 378 // error and abort.
377 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { 379 if (status == SERVICE_WORKER_ERROR_TIMEOUT) {
378 Complete(status, "Timed out while trying to start the Service Worker."); 380 Complete(status, "Timed out while trying to start the Service Worker.");
379 return; 381 return;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 ServiceWorkerStatusCode status) { 426 ServiceWorkerStatusCode status) {
425 ServiceWorkerMetrics::RecordInstallEventStatus(status); 427 ServiceWorkerMetrics::RecordInstallEventStatus(status);
426 428
427 if (status != SERVICE_WORKER_OK) { 429 if (status != SERVICE_WORKER_OK) {
428 // "8. If installFailed is true, then:..." 430 // "8. If installFailed is true, then:..."
429 Complete(status); 431 Complete(status);
430 return; 432 return;
431 } 433 }
432 434
433 SetPhase(STORE); 435 SetPhase(STORE);
434 registration()->set_last_update_check(base::Time::Now());
435 context_->storage()->StoreRegistration( 436 context_->storage()->StoreRegistration(
436 registration(), 437 registration(),
437 new_version(), 438 new_version(),
438 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete, 439 base::Bind(&ServiceWorkerRegisterJob::OnStoreRegistrationComplete,
439 weak_factory_.GetWeakPtr())); 440 weak_factory_.GetWeakPtr()));
440 } 441 }
441 442
442 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete( 443 void ServiceWorkerRegisterJob::OnStoreRegistrationComplete(
443 ServiceWorkerStatusCode status) { 444 ServiceWorkerStatusCode status) {
444 if (status != SERVICE_WORKER_OK) { 445 if (status != SERVICE_WORKER_OK) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 if (host->IsHostToRunningServiceWorker()) 546 if (host->IsHostToRunningServiceWorker())
546 continue; 547 continue;
547 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), 548 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(),
548 host->document_url())) 549 host->document_url()))
549 continue; 550 continue;
550 host->AddMatchingRegistration(registration); 551 host->AddMatchingRegistration(registration);
551 } 552 }
552 } 553 }
553 554
554 } // namespace content 555 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698