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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 version_(provider_host_->running_hosted_version()) { | 27 version_(provider_host_->running_hosted_version()) { |
28 DCHECK(provider_host_->IsHostToRunningServiceWorker()); | 28 DCHECK(provider_host_->IsHostToRunningServiceWorker()); |
29 } | 29 } |
30 | 30 |
31 ServiceWorkerContextRequestHandler::~ServiceWorkerContextRequestHandler() { | 31 ServiceWorkerContextRequestHandler::~ServiceWorkerContextRequestHandler() { |
32 } | 32 } |
33 | 33 |
34 net::URLRequestJob* ServiceWorkerContextRequestHandler::MaybeCreateJob( | 34 net::URLRequestJob* ServiceWorkerContextRequestHandler::MaybeCreateJob( |
35 net::URLRequest* request, | 35 net::URLRequest* request, |
36 net::NetworkDelegate* network_delegate) { | 36 net::NetworkDelegate* network_delegate) { |
37 if (!provider_host_ || !version_ || !context_) | 37 if (!provider_host_ || !version_.get() || !context_) |
38 return NULL; | 38 return NULL; |
39 | 39 |
40 // We currently have no use case for hijacking a redirected request. | 40 // We currently have no use case for hijacking a redirected request. |
41 if (request->url_chain().size() > 1) | 41 if (request->url_chain().size() > 1) |
42 return NULL; | 42 return NULL; |
43 | 43 |
44 // We only use the script cache for main script loading and | 44 // We only use the script cache for main script loading and |
45 // 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 |
46 // retrieve it from the script cache. | 46 // retrieve it from the script cache. |
47 // TODO(michaeln): Get the desired behavior clarified in the spec, | 47 // TODO(michaeln): Get the desired behavior clarified in the spec, |
(...skipping 17 matching lines...) Expand all Loading... |
65 int extra_load_flags = 0; | 65 int extra_load_flags = 0; |
66 base::TimeDelta time_since_last_check = | 66 base::TimeDelta time_since_last_check = |
67 base::Time::Now() - registration->last_update_check(); | 67 base::Time::Now() - registration->last_update_check(); |
68 if (time_since_last_check > base::TimeDelta::FromHours(24)) | 68 if (time_since_last_check > base::TimeDelta::FromHours(24)) |
69 extra_load_flags = net::LOAD_BYPASS_CACHE; | 69 extra_load_flags = net::LOAD_BYPASS_CACHE; |
70 | 70 |
71 return new ServiceWorkerWriteToCacheJob(request, | 71 return new ServiceWorkerWriteToCacheJob(request, |
72 network_delegate, | 72 network_delegate, |
73 resource_type_, | 73 resource_type_, |
74 context_, | 74 context_, |
75 version_, | 75 version_.get(), |
76 extra_load_flags, | 76 extra_load_flags, |
77 response_id); | 77 response_id); |
78 } | 78 } |
79 | 79 |
80 int64 response_id = kInvalidServiceWorkerResponseId; | 80 int64 response_id = kInvalidServiceWorkerResponseId; |
81 if (ShouldReadFromScriptCache(request->url(), &response_id)) { | 81 if (ShouldReadFromScriptCache(request->url(), &response_id)) { |
82 return new ServiceWorkerReadFromCacheJob( | 82 return new ServiceWorkerReadFromCacheJob( |
83 request, network_delegate, context_, response_id); | 83 request, network_delegate, context_, response_id); |
84 } | 84 } |
85 | 85 |
(...skipping 23 matching lines...) Expand all Loading... |
109 const GURL& url, int64* response_id_out) { | 109 const GURL& url, int64* response_id_out) { |
110 // 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. |
111 if (version_->status() == ServiceWorkerVersion::NEW || | 111 if (version_->status() == ServiceWorkerVersion::NEW || |
112 version_->status() == ServiceWorkerVersion::INSTALLING) | 112 version_->status() == ServiceWorkerVersion::INSTALLING) |
113 return false; | 113 return false; |
114 *response_id_out = version_->script_cache_map()->Lookup(url); | 114 *response_id_out = version_->script_cache_map()->Lookup(url); |
115 return *response_id_out != kInvalidServiceWorkerResponseId; | 115 return *response_id_out != kInvalidServiceWorkerResponseId; |
116 } | 116 } |
117 | 117 |
118 } // namespace content | 118 } // namespace content |
OLD | NEW |