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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 | 57 |
58 if (ShouldAddToScriptCache(request->url())) { | 58 if (ShouldAddToScriptCache(request->url())) { |
59 ServiceWorkerRegistration* registration = | 59 ServiceWorkerRegistration* registration = |
60 context_->GetLiveRegistration(version_->registration_id()); | 60 context_->GetLiveRegistration(version_->registration_id()); |
61 DCHECK(registration); // We're registering or updating so must be there. | 61 DCHECK(registration); // We're registering or updating so must be there. |
62 | 62 |
63 int64 response_id = context_->storage()->NewResourceId(); | 63 int64 response_id = context_->storage()->NewResourceId(); |
64 if (response_id == kInvalidServiceWorkerResponseId) | 64 if (response_id == kInvalidServiceWorkerResponseId) |
65 return NULL; | 65 return NULL; |
66 | 66 |
67 // Bypass the browser cache for initial installs and update | 67 // Bypass the browser cache for initial installs and update checks after |
68 // checks after 24 hours have passed. | 68 // min(Cache-Control's max-age value, 86400) seconds have passed. |
69 int extra_load_flags = 0; | 69 int extra_load_flags = 0; |
70 base::TimeDelta time_since_last_check = | 70 base::TimeDelta time_since_last_check = |
71 base::Time::Now() - registration->last_update_check(); | 71 base::Time::Now() - registration->last_update_check(); |
72 if (time_since_last_check > base::TimeDelta::FromHours( | 72 if (time_since_last_check > version_->max_age() || |
nhiroki
2015/08/19 06:59:01
The original code (time_since_last_check > FromHou
jungkees
2015/08/20 01:52:56
Agreed on your point. Having double-checked the lo
| |
73 kServiceWorkerScriptMaxCacheAgeInHours) || | 73 version_->force_bypass_cache_for_scripts()) |
74 version_->force_bypass_cache_for_scripts()) { | |
75 extra_load_flags = net::LOAD_BYPASS_CACHE; | 74 extra_load_flags = net::LOAD_BYPASS_CACHE; |
76 } | |
77 | 75 |
78 ServiceWorkerVersion* stored_version = registration->waiting_version() | 76 ServiceWorkerVersion* stored_version = registration->waiting_version() |
79 ? registration->waiting_version() | 77 ? registration->waiting_version() |
80 : registration->active_version(); | 78 : registration->active_version(); |
81 int64 incumbent_response_id = kInvalidServiceWorkerResourceId; | 79 int64 incumbent_response_id = kInvalidServiceWorkerResourceId; |
82 if (stored_version && stored_version->script_url() == request->url()) { | 80 if (stored_version && stored_version->script_url() == request->url()) { |
83 incumbent_response_id = | 81 incumbent_response_id = |
84 stored_version->script_cache_map()->LookupResourceId(request->url()); | 82 stored_version->script_cache_map()->LookupResourceId(request->url()); |
85 } | 83 } |
86 return new ServiceWorkerWriteToCacheJob( | 84 return new ServiceWorkerWriteToCacheJob( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 const GURL& url, int64* response_id_out) { | 120 const GURL& url, int64* response_id_out) { |
123 // We don't read from the script cache until the version is INSTALLED. | 121 // We don't read from the script cache until the version is INSTALLED. |
124 if (version_->status() == ServiceWorkerVersion::NEW || | 122 if (version_->status() == ServiceWorkerVersion::NEW || |
125 version_->status() == ServiceWorkerVersion::INSTALLING) | 123 version_->status() == ServiceWorkerVersion::INSTALLING) |
126 return false; | 124 return false; |
127 *response_id_out = version_->script_cache_map()->LookupResourceId(url); | 125 *response_id_out = version_->script_cache_map()->LookupResourceId(url); |
128 return *response_id_out != kInvalidServiceWorkerResponseId; | 126 return *response_id_out != kInvalidServiceWorkerResponseId; |
129 } | 127 } |
130 | 128 |
131 } // namespace content | 129 } // namespace content |
OLD | NEW |