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

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 a database error Created 3 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 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (resource_id == kInvalidServiceWorkerResourceId) { 184 if (resource_id == kInvalidServiceWorkerResourceId) {
185 *out_status = CreateJobStatus::ERROR_OUT_OF_RESOURCE_IDS; 185 *out_status = CreateJobStatus::ERROR_OUT_OF_RESOURCE_IDS;
186 return nullptr; 186 return nullptr;
187 } 187 }
188 188
189 // Bypass the browser cache for initial installs and update checks after 24 189 // Bypass the browser cache for initial installs and update checks after 24
190 // hours have passed. 190 // hours have passed.
191 int extra_load_flags = 0; 191 int extra_load_flags = 0;
192 base::TimeDelta time_since_last_check = 192 base::TimeDelta time_since_last_check =
193 base::Time::Now() - registration->last_update_check(); 193 base::Time::Now() - registration->last_update_check();
194 if (time_since_last_check > kServiceWorkerScriptMaxCacheAge || 194 bool should_bypass_cache =
195 (is_main_script && registration->update_via_cache() !=
196 blink::WebServiceWorkerUpdateViaCache::kAll) ||
197 registration->update_via_cache() ==
198 blink::WebServiceWorkerUpdateViaCache::kNone;
nhiroki 2017/08/04 09:24:50 Would it be possible to move this policy decision
yuryu 2017/08/17 07:36:35 I think it makes sense to extract the part to anot
199 if (should_bypass_cache ||
200 time_since_last_check > kServiceWorkerScriptMaxCacheAge ||
195 version_->force_bypass_cache_for_scripts()) { 201 version_->force_bypass_cache_for_scripts()) {
196 extra_load_flags = net::LOAD_BYPASS_CACHE; 202 extra_load_flags = net::LOAD_BYPASS_CACHE;
197 } 203 }
198 204
199 ServiceWorkerVersion* stored_version = registration->waiting_version() 205 ServiceWorkerVersion* stored_version = registration->waiting_version()
200 ? registration->waiting_version() 206 ? registration->waiting_version()
201 : registration->active_version(); 207 : registration->active_version();
202 int64_t incumbent_resource_id = kInvalidServiceWorkerResourceId; 208 int64_t incumbent_resource_id = kInvalidServiceWorkerResourceId;
203 if (is_main_script) { 209 if (is_main_script) {
204 if (stored_version && stored_version->script_url() == request->url()) { 210 if (stored_version && stored_version->script_url() == request->url()) {
205 incumbent_resource_id = 211 incumbent_resource_id =
206 stored_version->script_cache_map()->LookupResourceId(request->url()); 212 stored_version->script_cache_map()->LookupResourceId(request->url());
207 } 213 }
208 version_->embedded_worker()->OnURLJobCreatedForMainScript(); 214 version_->embedded_worker()->OnURLJobCreatedForMainScript();
209 } 215 }
210 *out_status = incumbent_resource_id == kInvalidServiceWorkerResourceId 216 *out_status = incumbent_resource_id == kInvalidServiceWorkerResourceId
211 ? CreateJobStatus::WRITE_JOB 217 ? CreateJobStatus::WRITE_JOB
212 : CreateJobStatus::WRITE_JOB_WITH_INCUMBENT; 218 : CreateJobStatus::WRITE_JOB_WITH_INCUMBENT;
213 return new ServiceWorkerWriteToCacheJob( 219 return new ServiceWorkerWriteToCacheJob(
214 request, network_delegate, resource_type_, context_, version_.get(), 220 request, network_delegate, resource_type_, context_, version_.get(),
215 extra_load_flags, resource_id, incumbent_resource_id); 221 extra_load_flags, resource_id, incumbent_resource_id);
216 } 222 }
217 223
218 } // namespace content 224 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698