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

Unified Diff: content/browser/service_worker/service_worker_register_job.cc

Issue 457903002: After 24 hours, bust the browser cache when checking for ServiceWorker updates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_register_job.cc
diff --git a/content/browser/service_worker/service_worker_register_job.cc b/content/browser/service_worker/service_worker_register_job.cc
index 389fa7f5e6eb320c7af923b7267c4186081092c3..a0453313bc0d33e636ac973cd616178b878e28a5 100644
--- a/content/browser/service_worker/service_worker_register_job.cc
+++ b/content/browser/service_worker/service_worker_register_job.cc
@@ -232,6 +232,10 @@ void ServiceWorkerRegisterJob::ContinueWithUpdate(
return;
}
+ // TODO(michaeln): If the last update check was less than 24 hours
+ // ago, depending on the freshness of the cached worker script we
+ // may be able to complete the update job right here.
+
UpdateAndContinue();
}
@@ -323,6 +327,7 @@ void ServiceWorkerRegisterJob::OnInstallFinished(
}
SetPhase(STORE);
+ registration()->set_last_update_check(base::Time::Now());
context_->storage()->StoreRegistration(
registration(),
new_version(),
@@ -416,11 +421,13 @@ void ServiceWorkerRegisterJob::ResolvePromise(
void ServiceWorkerRegisterJob::OnPausedAfterDownload() {
// This happens prior to OnStartWorkerFinished time.
- scoped_refptr<ServiceWorkerVersion> current_version =
- registration()->active_version();
- DCHECK(current_version);
- int64 current_script_id =
- current_version->script_cache_map()->Lookup(script_url_);
+ scoped_refptr<ServiceWorkerVersion> most_recent_version =
+ registration()->waiting_version() ?
+ registration()->waiting_version() :
+ registration()->active_version();
+ DCHECK(most_recent_version);
+ int64 most_recent_script_id =
+ most_recent_version->script_cache_map()->Lookup(script_url_);
int64 new_script_id =
new_version()->script_cache_map()->Lookup(script_url_);
@@ -428,10 +435,10 @@ void ServiceWorkerRegisterJob::OnPausedAfterDownload() {
// is being downloaded and to avoid writing it to disk until we know
// its needed.
context_->storage()->CompareScriptResources(
- current_script_id, new_script_id,
+ most_recent_script_id, new_script_id,
base::Bind(&ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete,
weak_factory_.GetWeakPtr(),
- current_version));
+ most_recent_version));
}
bool ServiceWorkerRegisterJob::OnMessageReceived(const IPC::Message& message) {
@@ -439,11 +446,19 @@ bool ServiceWorkerRegisterJob::OnMessageReceived(const IPC::Message& message) {
}
void ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete(
- ServiceWorkerVersion* current_version,
+ ServiceWorkerVersion* most_recent_version,
ServiceWorkerStatusCode status,
bool are_equal) {
if (are_equal) {
- ResolvePromise(SERVICE_WORKER_OK, registration(), current_version);
+ // Only bump the last check time when we've bypassed the browser cache.
michaeln 2014/08/15 01:39:59 i changed this part since you last looked
+ base::TimeDelta time_since_last_check =
+ base::Time::Now() - registration()->last_update_check();
+ if (time_since_last_check > base::TimeDelta::FromHours(24)) {
+ registration()->set_last_update_check(base::Time::Now());
+ context_->storage()->UpdateLastUpdateCheckTime(registration());
+ }
+
+ ResolvePromise(SERVICE_WORKER_OK, registration(), most_recent_version);
Complete(SERVICE_WORKER_ERROR_EXISTS);
return;
}

Powered by Google App Engine
This is Rietveld 408576698