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

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: Change the condition to check if SWRegistration is stored Created 4 years, 11 months 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 <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
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 (registration()->waiting_version() || registration()->active_version())
michaeln 2016/01/19 19:20:28 if job_type_ == UPDATE_JOB works as the condition
jungkees 2016/01/20 05:38:11 I discussed with falken@ and tried so, but later h
falken 2016/01/20 09:31:54 Right. I was then worried about whether waiting_ve
365 context_->storage()->UpdateLastUpdateCheckTime(registration());
366 }
michaeln 2016/01/21 20:55:31 else { there's an assumption here that last_update
jungkees 2016/01/22 05:22:27 Done.
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
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());
michaeln 2016/01/19 19:20:28 Is there any chance we can be here w/o having set
jungkees 2016/01/20 05:38:11 No, I don't think so.
falken 2016/01/20 09:31:54 I guess it'd only be possible if network_accessed_
michaeln 2016/01/21 20:55:31 Right, an assurance of some kind about having a me
jungkees 2016/01/22 05:22:26 Okay. To assure that, I added this assertion as we
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698