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

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

Issue 1923143005: service worker: Bump update time even when the script was identical (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 7 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
« no previous file with comments | « content/browser/service_worker/service_worker_register_job.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } else { 350 } else {
351 new_version()->set_pause_after_download(false); 351 new_version()->set_pause_after_download(false);
352 } 352 }
353 new_version()->StartWorker( 353 new_version()->StartWorker(
354 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, 354 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished,
355 weak_factory_.GetWeakPtr())); 355 weak_factory_.GetWeakPtr()));
356 } 356 }
357 357
358 void ServiceWorkerRegisterJob::OnStartWorkerFinished( 358 void ServiceWorkerRegisterJob::OnStartWorkerFinished(
359 ServiceWorkerStatusCode status) { 359 ServiceWorkerStatusCode status) {
360 // Bump the last update check time only when the register/update job fetched 360 BumpLastUpdateCheckTimeIfNeeded();
361 // the version having bypassed the network cache. We assume that the
362 // BYPASS_CACHE flag evicts an existing cache entry, so even if the install
363 // ultimately failed for whatever reason, we know the version in the HTTP
364 // cache is not stale, so it's OK to bump the update check time.
365 if (new_version()->embedded_worker()->network_accessed_for_script() ||
366 new_version()->force_bypass_cache_for_scripts() ||
367 registration()->last_update_check().is_null()) {
368 registration()->set_last_update_check(base::Time::Now());
369
370 if (registration()->has_installed_version())
371 context_->storage()->UpdateLastUpdateCheckTime(registration());
372 }
373 361
374 if (status == SERVICE_WORKER_OK) { 362 if (status == SERVICE_WORKER_OK) {
375 InstallAndContinue(); 363 InstallAndContinue();
376 return; 364 return;
377 } 365 }
378 366
379 // "If serviceWorker fails to start up..." then reject the promise with an 367 // "If serviceWorker fails to start up..." then reject the promise with an
380 // error and abort. 368 // error and abort.
381 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { 369 if (status == SERVICE_WORKER_ERROR_TIMEOUT) {
382 Complete(status, "Timed out while trying to start the Service Worker."); 370 Complete(status, "Timed out while trying to start the Service Worker.");
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 void ServiceWorkerRegisterJob::OnScriptLoaded() { 568 void ServiceWorkerRegisterJob::OnScriptLoaded() {
581 DCHECK(new_version()->pause_after_download()); 569 DCHECK(new_version()->pause_after_download());
582 new_version()->set_pause_after_download(false); 570 new_version()->set_pause_after_download(false);
583 net::URLRequestStatus status = 571 net::URLRequestStatus status =
584 new_version()->script_cache_map()->main_script_status(); 572 new_version()->script_cache_map()->main_script_status();
585 if (!status.is_success()) { 573 if (!status.is_success()) {
586 // OnScriptLoaded signifies a successful network load, which translates into 574 // OnScriptLoaded signifies a successful network load, which translates into
587 // a script cache error only in the byte-for-byte identical case. 575 // a script cache error only in the byte-for-byte identical case.
588 DCHECK_EQ(status.error(), 576 DCHECK_EQ(status.error(),
589 ServiceWorkerWriteToCacheJob::kIdenticalScriptError); 577 ServiceWorkerWriteToCacheJob::kIdenticalScriptError);
578
579 BumpLastUpdateCheckTimeIfNeeded();
590 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration()); 580 ResolvePromise(SERVICE_WORKER_OK, std::string(), registration());
591 Complete(SERVICE_WORKER_ERROR_EXISTS, 581 Complete(SERVICE_WORKER_ERROR_EXISTS,
592 "The updated worker is identical to the incumbent."); 582 "The updated worker is identical to the incumbent.");
593 return; 583 return;
594 } 584 }
595 585
596 new_version()->embedded_worker()->ResumeAfterDownload(); 586 new_version()->embedded_worker()->ResumeAfterDownload();
597 } 587 }
598 588
589 void ServiceWorkerRegisterJob::BumpLastUpdateCheckTimeIfNeeded() {
590 // Bump the last update check time only when the register/update job fetched
591 // the version having bypassed the network cache. We assume that the
592 // BYPASS_CACHE flag evicts an existing cache entry, so even if the install
593 // ultimately failed for whatever reason, we know the version in the HTTP
594 // cache is not stale, so it's OK to bump the update check time.
595 if (new_version()->embedded_worker()->network_accessed_for_script() ||
596 new_version()->force_bypass_cache_for_scripts() ||
597 registration()->last_update_check().is_null()) {
598 registration()->set_last_update_check(base::Time::Now());
599
600 if (registration()->has_installed_version())
601 context_->storage()->UpdateLastUpdateCheckTime(registration());
602 }
603 }
604
599 } // namespace content 605 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_register_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698