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

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

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: fix tests Created 3 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_context_request_handler. h" 5 #include "content/browser/service_worker/service_worker_context_request_handler. h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "content/browser/service_worker/service_worker_context_core.h" 8 #include "content/browser/service_worker/service_worker_context_core.h"
9 #include "content/browser/service_worker/service_worker_provider_host.h" 9 #include "content/browser/service_worker/service_worker_provider_host.h"
10 #include "content/browser/service_worker/service_worker_read_from_cache_job.h" 10 #include "content/browser/service_worker/service_worker_read_from_cache_job.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (resource_id == kInvalidServiceWorkerResourceId) { 202 if (resource_id == kInvalidServiceWorkerResourceId) {
203 *out_status = CreateJobStatus::ERROR_OUT_OF_RESOURCE_IDS; 203 *out_status = CreateJobStatus::ERROR_OUT_OF_RESOURCE_IDS;
204 return nullptr; 204 return nullptr;
205 } 205 }
206 206
207 // Bypass the browser cache for initial installs and update checks after 24 207 // Bypass the browser cache for initial installs and update checks after 24
208 // hours have passed. 208 // hours have passed.
209 int extra_load_flags = 0; 209 int extra_load_flags = 0;
210 base::TimeDelta time_since_last_check = 210 base::TimeDelta time_since_last_check =
211 base::Time::Now() - registration->last_update_check(); 211 base::Time::Now() - registration->last_update_check();
212
212 if (time_since_last_check > 213 if (time_since_last_check >
213 base::TimeDelta::FromHours(kServiceWorkerScriptMaxCacheAgeInHours) || 214 base::TimeDelta::FromHours(kServiceWorkerScriptMaxCacheAgeInHours) ||
214 version_->force_bypass_cache_for_scripts()) { 215 version_->force_bypass_cache_for_scripts() ||
216 !registration->use_cache()) {
215 extra_load_flags = net::LOAD_BYPASS_CACHE; 217 extra_load_flags = net::LOAD_BYPASS_CACHE;
216 } 218 }
217 219
218 ServiceWorkerVersion* stored_version = registration->waiting_version() 220 ServiceWorkerVersion* stored_version = registration->waiting_version()
219 ? registration->waiting_version() 221 ? registration->waiting_version()
220 : registration->active_version(); 222 : registration->active_version();
221 int64_t incumbent_resource_id = kInvalidServiceWorkerResourceId; 223 int64_t incumbent_resource_id = kInvalidServiceWorkerResourceId;
222 if (is_main_script) { 224 if (is_main_script) {
223 if (stored_version && stored_version->script_url() == request->url()) { 225 if (stored_version && stored_version->script_url() == request->url()) {
224 incumbent_resource_id = 226 incumbent_resource_id =
225 stored_version->script_cache_map()->LookupResourceId(request->url()); 227 stored_version->script_cache_map()->LookupResourceId(request->url());
226 } 228 }
227 version_->embedded_worker()->OnURLJobCreatedForMainScript(); 229 version_->embedded_worker()->OnURLJobCreatedForMainScript();
228 } 230 }
229 *out_status = incumbent_resource_id == kInvalidServiceWorkerResourceId 231 *out_status = incumbent_resource_id == kInvalidServiceWorkerResourceId
230 ? CreateJobStatus::WRITE_JOB 232 ? CreateJobStatus::WRITE_JOB
231 : CreateJobStatus::WRITE_JOB_WITH_INCUMBENT; 233 : CreateJobStatus::WRITE_JOB_WITH_INCUMBENT;
232 return new ServiceWorkerWriteToCacheJob( 234 return new ServiceWorkerWriteToCacheJob(
233 request, network_delegate, resource_type_, context_, version_.get(), 235 request, network_delegate, resource_type_, context_, version_.get(),
234 extra_load_flags, resource_id, incumbent_resource_id); 236 extra_load_flags, resource_id, incumbent_resource_id);
235 } 237 }
236 238
237 } // namespace content 239 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698