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 "content/browser/service_worker/service_worker_context_core.h" | 7 #include "content/browser/service_worker/service_worker_context_core.h" |
8 #include "content/browser/service_worker/service_worker_provider_host.h" | 8 #include "content/browser/service_worker/service_worker_provider_host.h" |
9 #include "content/browser/service_worker/service_worker_read_from_cache_job.h" | 9 #include "content/browser/service_worker/service_worker_read_from_cache_job.h" |
10 #include "content/browser/service_worker/service_worker_storage.h" | 10 #include "content/browser/service_worker/service_worker_storage.h" |
11 #include "content/browser/service_worker/service_worker_version.h" | 11 #include "content/browser/service_worker/service_worker_version.h" |
12 #include "content/browser/service_worker/service_worker_write_to_cache_job.h" | 12 #include "content/browser/service_worker/service_worker_write_to_cache_job.h" |
| 13 #include "net/base/load_flags.h" |
13 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 ServiceWorkerContextRequestHandler::ServiceWorkerContextRequestHandler( | 18 ServiceWorkerContextRequestHandler::ServiceWorkerContextRequestHandler( |
18 base::WeakPtr<ServiceWorkerContextCore> context, | 19 base::WeakPtr<ServiceWorkerContextCore> context, |
19 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 20 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
20 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context, | 21 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context, |
21 ResourceType resource_type) | 22 ResourceType resource_type) |
22 : ServiceWorkerRequestHandler(context, | 23 : ServiceWorkerRequestHandler(context, |
(...skipping 21 matching lines...) Expand all Loading... |
44 // importScripts(), even if a cached script is xhr'd, we don't | 45 // importScripts(), even if a cached script is xhr'd, we don't |
45 // retrieve it from the script cache. | 46 // retrieve it from the script cache. |
46 // TODO(michaeln): Get the desired behavior clarified in the spec, | 47 // TODO(michaeln): Get the desired behavior clarified in the spec, |
47 // and make tweak the behavior here to match. | 48 // and make tweak the behavior here to match. |
48 if (resource_type_ != RESOURCE_TYPE_SERVICE_WORKER && | 49 if (resource_type_ != RESOURCE_TYPE_SERVICE_WORKER && |
49 resource_type_ != RESOURCE_TYPE_SCRIPT) { | 50 resource_type_ != RESOURCE_TYPE_SCRIPT) { |
50 return NULL; | 51 return NULL; |
51 } | 52 } |
52 | 53 |
53 if (ShouldAddToScriptCache(request->url())) { | 54 if (ShouldAddToScriptCache(request->url())) { |
| 55 ServiceWorkerRegistration* registration = |
| 56 context_->GetLiveRegistration(version_->registration_id()); |
| 57 DCHECK(registration); // We're registering or updating so must be there. |
| 58 |
54 int64 response_id = context_->storage()->NewResourceId(); | 59 int64 response_id = context_->storage()->NewResourceId(); |
55 if (response_id == kInvalidServiceWorkerResponseId) | 60 if (response_id == kInvalidServiceWorkerResponseId) |
56 return NULL; | 61 return NULL; |
| 62 |
| 63 // Bypass the browser cache for initial installs and update |
| 64 // checks after 24 hours have passed. |
| 65 int extra_load_flags = 0; |
| 66 base::TimeDelta time_since_last_check = |
| 67 base::Time::Now() - registration->last_update_check(); |
| 68 if (time_since_last_check > base::TimeDelta::FromHours(24)) |
| 69 extra_load_flags = net::LOAD_BYPASS_CACHE; |
| 70 |
57 return new ServiceWorkerWriteToCacheJob(request, | 71 return new ServiceWorkerWriteToCacheJob(request, |
58 network_delegate, | 72 network_delegate, |
59 resource_type_, | 73 resource_type_, |
60 context_, | 74 context_, |
61 version_, | 75 version_, |
| 76 extra_load_flags, |
62 response_id); | 77 response_id); |
63 } | 78 } |
64 | 79 |
65 int64 response_id = kInvalidServiceWorkerResponseId; | 80 int64 response_id = kInvalidServiceWorkerResponseId; |
66 if (ShouldReadFromScriptCache(request->url(), &response_id)) { | 81 if (ShouldReadFromScriptCache(request->url(), &response_id)) { |
67 return new ServiceWorkerReadFromCacheJob( | 82 return new ServiceWorkerReadFromCacheJob( |
68 request, network_delegate, context_, response_id); | 83 request, network_delegate, context_, response_id); |
69 } | 84 } |
70 | 85 |
71 // NULL means use the network. | 86 // NULL means use the network. |
(...skipping 22 matching lines...) Expand all Loading... |
94 const GURL& url, int64* response_id_out) { | 109 const GURL& url, int64* response_id_out) { |
95 // We don't read from the script cache until the version is INSTALLED. | 110 // We don't read from the script cache until the version is INSTALLED. |
96 if (version_->status() == ServiceWorkerVersion::NEW || | 111 if (version_->status() == ServiceWorkerVersion::NEW || |
97 version_->status() == ServiceWorkerVersion::INSTALLING) | 112 version_->status() == ServiceWorkerVersion::INSTALLING) |
98 return false; | 113 return false; |
99 *response_id_out = version_->script_cache_map()->Lookup(url); | 114 *response_id_out = version_->script_cache_map()->Lookup(url); |
100 return *response_id_out != kInvalidServiceWorkerResponseId; | 115 return *response_id_out != kInvalidServiceWorkerResponseId; |
101 } | 116 } |
102 | 117 |
103 } // namespace content | 118 } // namespace content |
OLD | NEW |