OLD | NEW |
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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 if (resource_id == kInvalidServiceWorkerResourceId) { | 203 if (resource_id == kInvalidServiceWorkerResourceId) { |
204 *out_status = CreateJobStatus::ERROR_OUT_OF_RESOURCE_IDS; | 204 *out_status = CreateJobStatus::ERROR_OUT_OF_RESOURCE_IDS; |
205 return nullptr; | 205 return nullptr; |
206 } | 206 } |
207 | 207 |
208 // Bypass the browser cache for initial installs and update checks after 24 | 208 // Bypass the browser cache for initial installs and update checks after 24 |
209 // hours have passed. | 209 // hours have passed. |
210 int extra_load_flags = 0; | 210 int extra_load_flags = 0; |
211 base::TimeDelta time_since_last_check = | 211 base::TimeDelta time_since_last_check = |
212 base::Time::Now() - registration->last_update_check(); | 212 base::Time::Now() - registration->last_update_check(); |
213 if (time_since_last_check > kServiceWorkerScriptMaxCacheAge || | 213 bool should_bypass_cache = |
| 214 (is_main_script && registration->update_via_cache() != |
| 215 blink::WebServiceWorkerUpdateViaCache::kAll) || |
| 216 registration->update_via_cache() == |
| 217 blink::WebServiceWorkerUpdateViaCache::kNone; |
| 218 if (should_bypass_cache || |
| 219 time_since_last_check > kServiceWorkerScriptMaxCacheAge || |
214 version_->force_bypass_cache_for_scripts()) { | 220 version_->force_bypass_cache_for_scripts()) { |
215 extra_load_flags = net::LOAD_BYPASS_CACHE; | 221 extra_load_flags = net::LOAD_BYPASS_CACHE; |
216 } | 222 } |
217 | 223 |
218 ServiceWorkerVersion* stored_version = registration->waiting_version() | 224 ServiceWorkerVersion* stored_version = registration->waiting_version() |
219 ? registration->waiting_version() | 225 ? registration->waiting_version() |
220 : registration->active_version(); | 226 : registration->active_version(); |
221 int64_t incumbent_resource_id = kInvalidServiceWorkerResourceId; | 227 int64_t incumbent_resource_id = kInvalidServiceWorkerResourceId; |
222 if (is_main_script) { | 228 if (is_main_script) { |
223 if (stored_version && stored_version->script_url() == request->url()) { | 229 if (stored_version && stored_version->script_url() == request->url()) { |
224 incumbent_resource_id = | 230 incumbent_resource_id = |
225 stored_version->script_cache_map()->LookupResourceId(request->url()); | 231 stored_version->script_cache_map()->LookupResourceId(request->url()); |
226 } | 232 } |
227 version_->embedded_worker()->OnURLJobCreatedForMainScript(); | 233 version_->embedded_worker()->OnURLJobCreatedForMainScript(); |
228 } | 234 } |
229 *out_status = incumbent_resource_id == kInvalidServiceWorkerResourceId | 235 *out_status = incumbent_resource_id == kInvalidServiceWorkerResourceId |
230 ? CreateJobStatus::WRITE_JOB | 236 ? CreateJobStatus::WRITE_JOB |
231 : CreateJobStatus::WRITE_JOB_WITH_INCUMBENT; | 237 : CreateJobStatus::WRITE_JOB_WITH_INCUMBENT; |
232 return new ServiceWorkerWriteToCacheJob( | 238 return new ServiceWorkerWriteToCacheJob( |
233 request, network_delegate, resource_type_, context_, version_.get(), | 239 request, network_delegate, resource_type_, context_, version_.get(), |
234 extra_load_flags, resource_id, incumbent_resource_id); | 240 extra_load_flags, resource_id, incumbent_resource_id); |
235 } | 241 } |
236 | 242 |
237 } // namespace content | 243 } // namespace content |
OLD | NEW |