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

Side by Side Diff: content/renderer/cache_storage/cache_storage_dispatcher.cc

Issue 1039763002: Cache Storage: Move files to content/*/cache_storage, rename classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GN fix Created 5 years, 8 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/renderer/service_worker/service_worker_cache_storage_dispatche r.h" 5 #include "content/renderer/cache_storage/cache_storage_dispatcher.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/thread_local.h" 15 #include "base/threading/thread_local.h"
16 #include "content/child/thread_safe_sender.h" 16 #include "content/child/thread_safe_sender.h"
17 #include "content/common/service_worker/cache_storage_messages.h" 17 #include "content/common/cache_storage/cache_storage_messages.h"
18 #include "content/public/common/referrer.h" 18 #include "content/public/common/referrer.h"
19 #include "content/public/renderer/render_thread.h" 19 #include "content/public/renderer/render_thread.h"
20 #include "content/renderer/service_worker/service_worker_type_util.h" 20 #include "content/renderer/service_worker/service_worker_type_util.h"
21 #include "third_party/WebKit/public/platform/WebServiceWorkerCache.h" 21 #include "third_party/WebKit/public/platform/WebServiceWorkerCache.h"
22 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" 22 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h"
23 #include "third_party/WebKit/public/platform/WebServiceWorkerResponse.h" 23 #include "third_party/WebKit/public/platform/WebServiceWorkerResponse.h"
24 24
25 using base::TimeTicks; 25 using base::TimeTicks;
26 26
27 namespace content { 27 namespace content {
28 28
29 using blink::WebServiceWorkerCacheStorage; 29 using blink::WebServiceWorkerCacheStorage;
30 using blink::WebServiceWorkerCacheError; 30 using blink::WebServiceWorkerCacheError;
31 using blink::WebServiceWorkerRequest; 31 using blink::WebServiceWorkerRequest;
32 32
33 static base::LazyInstance< 33 static base::LazyInstance<base::ThreadLocalPointer<CacheStorageDispatcher>>::
34 base::ThreadLocalPointer<ServiceWorkerCacheStorageDispatcher>>::Leaky 34 Leaky g_cache_storage_dispatcher_tls = LAZY_INSTANCE_INITIALIZER;
35 g_cache_storage_dispatcher_tls = LAZY_INSTANCE_INITIALIZER;
36 35
37 namespace { 36 namespace {
38 37
39 ServiceWorkerCacheStorageDispatcher* const kHasBeenDeleted = 38 CacheStorageDispatcher* const kHasBeenDeleted =
40 reinterpret_cast<ServiceWorkerCacheStorageDispatcher*>(0x1); 39 reinterpret_cast<CacheStorageDispatcher*>(0x1);
41 40
42 ServiceWorkerFetchRequest FetchRequestFromWebRequest( 41 ServiceWorkerFetchRequest FetchRequestFromWebRequest(
43 const blink::WebServiceWorkerRequest& web_request) { 42 const blink::WebServiceWorkerRequest& web_request) {
44 ServiceWorkerHeaderMap headers; 43 ServiceWorkerHeaderMap headers;
45 GetServiceWorkerHeaderMapFromWebRequest(web_request, &headers); 44 GetServiceWorkerHeaderMapFromWebRequest(web_request, &headers);
46 45
47 return ServiceWorkerFetchRequest( 46 return ServiceWorkerFetchRequest(
48 web_request.url(), base::UTF16ToASCII(web_request.method()), headers, 47 web_request.url(), base::UTF16ToASCII(web_request.method()), headers,
49 Referrer(web_request.referrerUrl(), web_request.referrerPolicy()), 48 Referrer(web_request.referrerUrl(), web_request.referrerPolicy()),
50 web_request.isReload()); 49 web_request.isReload());
51 } 50 }
52 51
53 void PopulateWebRequestFromFetchRequest( 52 void PopulateWebRequestFromFetchRequest(
54 const ServiceWorkerFetchRequest& request, 53 const ServiceWorkerFetchRequest& request,
55 blink::WebServiceWorkerRequest* web_request) { 54 blink::WebServiceWorkerRequest* web_request) {
56 web_request->setURL(request.url); 55 web_request->setURL(request.url);
57 web_request->setMethod(base::ASCIIToUTF16(request.method)); 56 web_request->setMethod(base::ASCIIToUTF16(request.method));
58 for (ServiceWorkerHeaderMap::const_iterator i = request.headers.begin(), 57 for (ServiceWorkerHeaderMap::const_iterator i = request.headers.begin(),
59 end = request.headers.end(); 58 end = request.headers.end();
60 i != end; ++i) { 59 i != end; ++i) {
61 web_request->setHeader(base::ASCIIToUTF16(i->first), 60 web_request->setHeader(base::ASCIIToUTF16(i->first),
62 base::ASCIIToUTF16(i->second)); 61 base::ASCIIToUTF16(i->second));
63 } 62 }
64 web_request->setReferrer(base::ASCIIToUTF16(request.referrer.url.spec()), 63 web_request->setReferrer(base::ASCIIToUTF16(request.referrer.url.spec()),
65 request.referrer.policy); 64 request.referrer.policy);
66 web_request->setIsReload(request.is_reload); 65 web_request->setIsReload(request.is_reload);
67 } 66 }
68 67
69 blink::WebVector<blink::WebServiceWorkerRequest> WebRequestsFromRequests( 68 blink::WebVector<blink::WebServiceWorkerRequest> WebRequestsFromRequests(
70 const std::vector<ServiceWorkerFetchRequest>& requests) { 69 const std::vector<ServiceWorkerFetchRequest>& requests) {
71 blink::WebVector<blink::WebServiceWorkerRequest> 70 blink::WebVector<blink::WebServiceWorkerRequest> web_requests(
72 web_requests(requests.size()); 71 requests.size());
73 for (size_t i = 0; i < requests.size(); ++i) 72 for (size_t i = 0; i < requests.size(); ++i)
74 PopulateWebRequestFromFetchRequest(requests[i], &(web_requests[i])); 73 PopulateWebRequestFromFetchRequest(requests[i], &(web_requests[i]));
75 return web_requests; 74 return web_requests;
76 } 75 }
77 76
78 ServiceWorkerResponse ResponseFromWebResponse( 77 ServiceWorkerResponse ResponseFromWebResponse(
79 const blink::WebServiceWorkerResponse& web_response) { 78 const blink::WebServiceWorkerResponse& web_response) {
80 ServiceWorkerHeaderMap headers; 79 ServiceWorkerHeaderMap headers;
81 GetServiceWorkerHeaderMapFromWebResponse(web_response, &headers); 80 GetServiceWorkerHeaderMapFromWebResponse(web_response, &headers);
82 // We don't support streaming for cache. 81 // We don't support streaming for cache.
83 DCHECK(web_response.streamURL().isEmpty()); 82 DCHECK(web_response.streamURL().isEmpty());
84 return ServiceWorkerResponse(web_response.url(), 83 return ServiceWorkerResponse(web_response.url(), web_response.status(),
85 web_response.status(),
86 base::UTF16ToASCII(web_response.statusText()), 84 base::UTF16ToASCII(web_response.statusText()),
87 web_response.responseType(), 85 web_response.responseType(), headers,
88 headers,
89 base::UTF16ToASCII(web_response.blobUUID()), 86 base::UTF16ToASCII(web_response.blobUUID()),
90 web_response.blobSize(), 87 web_response.blobSize(),
91 web_response.streamURL()); 88 web_response.streamURL());
92 } 89 }
93 90
94 ServiceWorkerCacheQueryParams QueryParamsFromWebQueryParams( 91 CacheStorageCacheQueryParams QueryParamsFromWebQueryParams(
95 const blink::WebServiceWorkerCache::QueryParams& web_query_params) { 92 const blink::WebServiceWorkerCache::QueryParams& web_query_params) {
96 ServiceWorkerCacheQueryParams query_params; 93 CacheStorageCacheQueryParams query_params;
97 query_params.ignore_search = web_query_params.ignoreSearch; 94 query_params.ignore_search = web_query_params.ignoreSearch;
98 query_params.ignore_method = web_query_params.ignoreMethod; 95 query_params.ignore_method = web_query_params.ignoreMethod;
99 query_params.ignore_vary = web_query_params.ignoreVary; 96 query_params.ignore_vary = web_query_params.ignoreVary;
100 query_params.cache_name = web_query_params.cacheName; 97 query_params.cache_name = web_query_params.cacheName;
101 return query_params; 98 return query_params;
102 } 99 }
103 100
104 ServiceWorkerCacheOperationType CacheOperationTypeFromWebCacheOperationType( 101 CacheStorageCacheOperationType CacheOperationTypeFromWebCacheOperationType(
105 blink::WebServiceWorkerCache::OperationType operation_type) { 102 blink::WebServiceWorkerCache::OperationType operation_type) {
106 switch (operation_type) { 103 switch (operation_type) {
107 case blink::WebServiceWorkerCache::OperationTypePut: 104 case blink::WebServiceWorkerCache::OperationTypePut:
108 return SERVICE_WORKER_CACHE_OPERATION_TYPE_PUT; 105 return CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT;
109 case blink::WebServiceWorkerCache::OperationTypeDelete: 106 case blink::WebServiceWorkerCache::OperationTypeDelete:
110 return SERVICE_WORKER_CACHE_OPERATION_TYPE_DELETE; 107 return CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE;
111 default: 108 default:
112 return SERVICE_WORKER_CACHE_OPERATION_TYPE_UNDEFINED; 109 return CACHE_STORAGE_CACHE_OPERATION_TYPE_UNDEFINED;
113 } 110 }
114 } 111 }
115 112
116 ServiceWorkerBatchOperation BatchOperationFromWebBatchOperation( 113 CacheStorageBatchOperation BatchOperationFromWebBatchOperation(
117 const blink::WebServiceWorkerCache::BatchOperation& web_operation) { 114 const blink::WebServiceWorkerCache::BatchOperation& web_operation) {
118 ServiceWorkerBatchOperation operation; 115 CacheStorageBatchOperation operation;
119 operation.operation_type = 116 operation.operation_type =
120 CacheOperationTypeFromWebCacheOperationType(web_operation.operationType); 117 CacheOperationTypeFromWebCacheOperationType(web_operation.operationType);
121 operation.request = FetchRequestFromWebRequest(web_operation.request); 118 operation.request = FetchRequestFromWebRequest(web_operation.request);
122 operation.response = ResponseFromWebResponse(web_operation.response); 119 operation.response = ResponseFromWebResponse(web_operation.response);
123 operation.match_params = 120 operation.match_params =
124 QueryParamsFromWebQueryParams(web_operation.matchParams); 121 QueryParamsFromWebQueryParams(web_operation.matchParams);
125 return operation; 122 return operation;
126 } 123 }
127 124
128 template<typename T> 125 template <typename T>
129 void ClearCallbacksMapWithErrors(T* callbacks_map) { 126 void ClearCallbacksMapWithErrors(T* callbacks_map) {
130 typename T::iterator iter(callbacks_map); 127 typename T::iterator iter(callbacks_map);
131 while (!iter.IsAtEnd()) { 128 while (!iter.IsAtEnd()) {
132 blink::WebServiceWorkerCacheError reason = 129 blink::WebServiceWorkerCacheError reason =
133 blink::WebServiceWorkerCacheErrorNotFound; 130 blink::WebServiceWorkerCacheErrorNotFound;
134 iter.GetCurrentValue()->onError(&reason); 131 iter.GetCurrentValue()->onError(&reason);
135 callbacks_map->Remove(iter.GetCurrentKey()); 132 callbacks_map->Remove(iter.GetCurrentKey());
136 iter.Advance(); 133 iter.Advance();
137 } 134 }
138 } 135 }
139 136
140 } // namespace 137 } // namespace
141 138
142 // The WebCache object is the Chromium side implementation of the Blink 139 // The WebCache object is the Chromium side implementation of the Blink
143 // WebServiceWorkerCache API. Most of its methods delegate directly to the 140 // WebServiceWorkerCache API. Most of its methods delegate directly to the
144 // ServiceWorkerStorage object, which is able to assign unique IDs as well 141 // ServiceWorkerStorage object, which is able to assign unique IDs as well
145 // as have a lifetime longer than the requests. 142 // as have a lifetime longer than the requests.
146 class ServiceWorkerCacheStorageDispatcher::WebCache 143 class CacheStorageDispatcher::WebCache : public blink::WebServiceWorkerCache {
147 : public blink::WebServiceWorkerCache {
148 public: 144 public:
149 WebCache(base::WeakPtr<ServiceWorkerCacheStorageDispatcher> dispatcher, 145 WebCache(base::WeakPtr<CacheStorageDispatcher> dispatcher, int cache_id)
150 int cache_id) 146 : dispatcher_(dispatcher), cache_id_(cache_id) {}
151 : dispatcher_(dispatcher),
152 cache_id_(cache_id) {}
153 147
154 virtual ~WebCache() { 148 virtual ~WebCache() {
155 if (dispatcher_) 149 if (dispatcher_)
156 dispatcher_->OnWebCacheDestruction(cache_id_); 150 dispatcher_->OnWebCacheDestruction(cache_id_);
157 } 151 }
158 152
159 // From blink::WebServiceWorkerCache: 153 // From blink::WebServiceWorkerCache:
160 virtual void dispatchMatch(CacheMatchCallbacks* callbacks, 154 virtual void dispatchMatch(CacheMatchCallbacks* callbacks,
161 const blink::WebServiceWorkerRequest& request, 155 const blink::WebServiceWorkerRequest& request,
162 const QueryParams& query_params) { 156 const QueryParams& query_params) {
(...skipping 20 matching lines...) Expand all
183 } 177 }
184 virtual void dispatchBatch( 178 virtual void dispatchBatch(
185 CacheWithResponsesCallbacks* callbacks, 179 CacheWithResponsesCallbacks* callbacks,
186 const blink::WebVector<BatchOperation>& batch_operations) { 180 const blink::WebVector<BatchOperation>& batch_operations) {
187 if (!dispatcher_) 181 if (!dispatcher_)
188 return; 182 return;
189 dispatcher_->dispatchBatchForCache(cache_id_, callbacks, batch_operations); 183 dispatcher_->dispatchBatchForCache(cache_id_, callbacks, batch_operations);
190 } 184 }
191 185
192 private: 186 private:
193 const base::WeakPtr<ServiceWorkerCacheStorageDispatcher> dispatcher_; 187 const base::WeakPtr<CacheStorageDispatcher> dispatcher_;
194 const int cache_id_; 188 const int cache_id_;
195 }; 189 };
196 190
197 ServiceWorkerCacheStorageDispatcher::ServiceWorkerCacheStorageDispatcher( 191 CacheStorageDispatcher::CacheStorageDispatcher(
198 ThreadSafeSender* thread_safe_sender) 192 ThreadSafeSender* thread_safe_sender)
199 : thread_safe_sender_(thread_safe_sender), weak_factory_(this) { 193 : thread_safe_sender_(thread_safe_sender), weak_factory_(this) {
200 g_cache_storage_dispatcher_tls.Pointer()->Set(this); 194 g_cache_storage_dispatcher_tls.Pointer()->Set(this);
201 } 195 }
202 196
203 ServiceWorkerCacheStorageDispatcher::~ServiceWorkerCacheStorageDispatcher() { 197 CacheStorageDispatcher::~CacheStorageDispatcher() {
204 ClearCallbacksMapWithErrors(&has_callbacks_); 198 ClearCallbacksMapWithErrors(&has_callbacks_);
205 ClearCallbacksMapWithErrors(&open_callbacks_); 199 ClearCallbacksMapWithErrors(&open_callbacks_);
206 ClearCallbacksMapWithErrors(&delete_callbacks_); 200 ClearCallbacksMapWithErrors(&delete_callbacks_);
207 ClearCallbacksMapWithErrors(&keys_callbacks_); 201 ClearCallbacksMapWithErrors(&keys_callbacks_);
208 ClearCallbacksMapWithErrors(&match_callbacks_); 202 ClearCallbacksMapWithErrors(&match_callbacks_);
209 203
210 ClearCallbacksMapWithErrors(&cache_match_callbacks_); 204 ClearCallbacksMapWithErrors(&cache_match_callbacks_);
211 ClearCallbacksMapWithErrors(&cache_match_all_callbacks_); 205 ClearCallbacksMapWithErrors(&cache_match_all_callbacks_);
212 ClearCallbacksMapWithErrors(&cache_keys_callbacks_); 206 ClearCallbacksMapWithErrors(&cache_keys_callbacks_);
213 ClearCallbacksMapWithErrors(&cache_batch_callbacks_); 207 ClearCallbacksMapWithErrors(&cache_batch_callbacks_);
214 208
215 g_cache_storage_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); 209 g_cache_storage_dispatcher_tls.Pointer()->Set(kHasBeenDeleted);
216 } 210 }
217 211
218 ServiceWorkerCacheStorageDispatcher* 212 CacheStorageDispatcher* CacheStorageDispatcher::ThreadSpecificInstance(
219 ServiceWorkerCacheStorageDispatcher::ThreadSpecificInstance(
220 ThreadSafeSender* thread_safe_sender) { 213 ThreadSafeSender* thread_safe_sender) {
221 if (g_cache_storage_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { 214 if (g_cache_storage_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) {
222 NOTREACHED() << "Re-instantiating TLS ServiceWorkerCacheStorageDispatcher."; 215 NOTREACHED() << "Re-instantiating TLS CacheStorageDispatcher.";
223 g_cache_storage_dispatcher_tls.Pointer()->Set(NULL); 216 g_cache_storage_dispatcher_tls.Pointer()->Set(NULL);
224 } 217 }
225 if (g_cache_storage_dispatcher_tls.Pointer()->Get()) 218 if (g_cache_storage_dispatcher_tls.Pointer()->Get())
226 return g_cache_storage_dispatcher_tls.Pointer()->Get(); 219 return g_cache_storage_dispatcher_tls.Pointer()->Get();
227 220
228 ServiceWorkerCacheStorageDispatcher* dispatcher = 221 CacheStorageDispatcher* dispatcher =
229 new ServiceWorkerCacheStorageDispatcher(thread_safe_sender); 222 new CacheStorageDispatcher(thread_safe_sender);
230 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) 223 if (WorkerTaskRunner::Instance()->CurrentWorkerId())
231 WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); 224 WorkerTaskRunner::Instance()->AddStopObserver(dispatcher);
232 return dispatcher; 225 return dispatcher;
233 } 226 }
234 227
235 void ServiceWorkerCacheStorageDispatcher::OnWorkerRunLoopStopped() { 228 void CacheStorageDispatcher::OnWorkerRunLoopStopped() {
236 delete this; 229 delete this;
237 } 230 }
238 231
239 bool ServiceWorkerCacheStorageDispatcher::Send(IPC::Message* msg) { 232 bool CacheStorageDispatcher::Send(IPC::Message* msg) {
240 return thread_safe_sender_->Send(msg); 233 return thread_safe_sender_->Send(msg);
241 } 234 }
242 235
243 bool ServiceWorkerCacheStorageDispatcher::OnMessageReceived( 236 bool CacheStorageDispatcher::OnMessageReceived(const IPC::Message& message) {
244 const IPC::Message& message) {
245 bool handled = true; 237 bool handled = true;
246 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerCacheStorageDispatcher, message) 238 IPC_BEGIN_MESSAGE_MAP(CacheStorageDispatcher, message)
247 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageHasSuccess, 239 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheStorageHasSuccess,
248 OnCacheStorageHasSuccess) 240 OnCacheStorageHasSuccess)
249 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageOpenSuccess, 241 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheStorageOpenSuccess,
250 OnCacheStorageOpenSuccess) 242 OnCacheStorageOpenSuccess)
251 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageDeleteSuccess, 243 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheStorageDeleteSuccess,
252 OnCacheStorageDeleteSuccess) 244 OnCacheStorageDeleteSuccess)
253 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageKeysSuccess, 245 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheStorageKeysSuccess,
254 OnCacheStorageKeysSuccess) 246 OnCacheStorageKeysSuccess)
255 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageMatchSuccess, 247 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheStorageMatchSuccess,
256 OnCacheStorageMatchSuccess) 248 OnCacheStorageMatchSuccess)
257 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageHasError, 249 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheStorageHasError,
258 OnCacheStorageHasError) 250 OnCacheStorageHasError)
259 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageOpenError, 251 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheStorageOpenError,
260 OnCacheStorageOpenError) 252 OnCacheStorageOpenError)
261 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageDeleteError, 253 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheStorageDeleteError,
262 OnCacheStorageDeleteError) 254 OnCacheStorageDeleteError)
263 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageKeysError, 255 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheStorageKeysError,
264 OnCacheStorageKeysError) 256 OnCacheStorageKeysError)
265 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageMatchError, 257 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheStorageMatchError,
266 OnCacheStorageMatchError) 258 OnCacheStorageMatchError)
267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheMatchSuccess, 259 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheMatchSuccess,
268 OnCacheMatchSuccess) 260 OnCacheMatchSuccess)
269 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheMatchAllSuccess, 261 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheMatchAllSuccess,
270 OnCacheMatchAllSuccess) 262 OnCacheMatchAllSuccess)
271 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheKeysSuccess, 263 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheKeysSuccess, OnCacheKeysSuccess)
272 OnCacheKeysSuccess) 264 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheBatchSuccess,
273 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheBatchSuccess,
274 OnCacheBatchSuccess) 265 OnCacheBatchSuccess)
275 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheMatchError, 266 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheMatchError, OnCacheMatchError)
276 OnCacheMatchError) 267 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheMatchAllError,
277 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheMatchAllError,
278 OnCacheMatchAllError) 268 OnCacheMatchAllError)
279 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheKeysError, 269 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheKeysError, OnCacheKeysError)
280 OnCacheKeysError) 270 IPC_MESSAGE_HANDLER(CacheStorageMsg_CacheBatchError, OnCacheBatchError)
281 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheBatchError, 271 IPC_MESSAGE_UNHANDLED(handled = false)
282 OnCacheBatchError)
283 IPC_MESSAGE_UNHANDLED(handled = false)
284 IPC_END_MESSAGE_MAP() 272 IPC_END_MESSAGE_MAP()
285 273
286 return handled; 274 return handled;
287 } 275 }
288 276
289 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasSuccess( 277 void CacheStorageDispatcher::OnCacheStorageHasSuccess(int thread_id,
290 int thread_id, 278 int request_id) {
291 int request_id) {
292 DCHECK_EQ(thread_id, CurrentWorkerId()); 279 DCHECK_EQ(thread_id, CurrentWorkerId());
293 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Has", 280 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Has",
294 TimeTicks::Now() - has_times_[request_id]); 281 TimeTicks::Now() - has_times_[request_id]);
295 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks = 282 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks =
296 has_callbacks_.Lookup(request_id); 283 has_callbacks_.Lookup(request_id);
297 callbacks->onSuccess(); 284 callbacks->onSuccess();
298 has_callbacks_.Remove(request_id); 285 has_callbacks_.Remove(request_id);
299 has_times_.erase(request_id); 286 has_times_.erase(request_id);
300 } 287 }
301 288
302 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageOpenSuccess( 289 void CacheStorageDispatcher::OnCacheStorageOpenSuccess(int thread_id,
303 int thread_id, 290 int request_id,
304 int request_id, 291 int cache_id) {
305 int cache_id) {
306 DCHECK_EQ(thread_id, CurrentWorkerId()); 292 DCHECK_EQ(thread_id, CurrentWorkerId());
307 WebCache* web_cache = new WebCache(weak_factory_.GetWeakPtr(), cache_id); 293 WebCache* web_cache = new WebCache(weak_factory_.GetWeakPtr(), cache_id);
308 web_caches_.AddWithID(web_cache, cache_id); 294 web_caches_.AddWithID(web_cache, cache_id);
309 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Open", 295 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Open",
310 TimeTicks::Now() - open_times_[request_id]); 296 TimeTicks::Now() - open_times_[request_id]);
311 WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* callbacks = 297 WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* callbacks =
312 open_callbacks_.Lookup(request_id); 298 open_callbacks_.Lookup(request_id);
313 callbacks->onSuccess(web_cache); 299 callbacks->onSuccess(web_cache);
314 open_callbacks_.Remove(request_id); 300 open_callbacks_.Remove(request_id);
315 open_times_.erase(request_id); 301 open_times_.erase(request_id);
316 } 302 }
317 303
318 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageDeleteSuccess( 304 void CacheStorageDispatcher::OnCacheStorageDeleteSuccess(int thread_id,
319 int thread_id, 305 int request_id) {
320 int request_id) {
321 DCHECK_EQ(thread_id, CurrentWorkerId()); 306 DCHECK_EQ(thread_id, CurrentWorkerId());
322 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Delete", 307 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Delete",
323 TimeTicks::Now() - delete_times_[request_id]); 308 TimeTicks::Now() - delete_times_[request_id]);
324 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks = 309 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks =
325 delete_callbacks_.Lookup(request_id); 310 delete_callbacks_.Lookup(request_id);
326 callbacks->onSuccess(); 311 callbacks->onSuccess();
327 delete_callbacks_.Remove(request_id); 312 delete_callbacks_.Remove(request_id);
328 delete_times_.erase(request_id); 313 delete_times_.erase(request_id);
329 } 314 }
330 315
331 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageKeysSuccess( 316 void CacheStorageDispatcher::OnCacheStorageKeysSuccess(
332 int thread_id, 317 int thread_id,
333 int request_id, 318 int request_id,
334 const std::vector<base::string16>& keys) { 319 const std::vector<base::string16>& keys) {
335 DCHECK_EQ(thread_id, CurrentWorkerId()); 320 DCHECK_EQ(thread_id, CurrentWorkerId());
336 blink::WebVector<blink::WebString> webKeys(keys.size()); 321 blink::WebVector<blink::WebString> webKeys(keys.size());
337 for (size_t i = 0; i < keys.size(); ++i) 322 for (size_t i = 0; i < keys.size(); ++i)
338 webKeys[i] = keys[i]; 323 webKeys[i] = keys[i];
339 324
340 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Keys", 325 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Keys",
341 TimeTicks::Now() - keys_times_[request_id]); 326 TimeTicks::Now() - keys_times_[request_id]);
342 WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks = 327 WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks =
343 keys_callbacks_.Lookup(request_id); 328 keys_callbacks_.Lookup(request_id);
344 callbacks->onSuccess(&webKeys); 329 callbacks->onSuccess(&webKeys);
345 keys_callbacks_.Remove(request_id); 330 keys_callbacks_.Remove(request_id);
346 keys_times_.erase(request_id); 331 keys_times_.erase(request_id);
347 } 332 }
348 333
349 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageMatchSuccess( 334 void CacheStorageDispatcher::OnCacheStorageMatchSuccess(
350 int thread_id, 335 int thread_id,
351 int request_id, 336 int request_id,
352 const ServiceWorkerResponse& response) { 337 const ServiceWorkerResponse& response) {
353 DCHECK_EQ(thread_id, CurrentWorkerId()); 338 DCHECK_EQ(thread_id, CurrentWorkerId());
354 blink::WebServiceWorkerResponse web_response; 339 blink::WebServiceWorkerResponse web_response;
355 PopulateWebResponseFromResponse(response, &web_response); 340 PopulateWebResponseFromResponse(response, &web_response);
356 341
357 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Match", 342 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Match",
358 TimeTicks::Now() - match_times_[request_id]); 343 TimeTicks::Now() - match_times_[request_id]);
359 WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* callbacks = 344 WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* callbacks =
360 match_callbacks_.Lookup(request_id); 345 match_callbacks_.Lookup(request_id);
361 callbacks->onSuccess(&web_response); 346 callbacks->onSuccess(&web_response);
362 match_callbacks_.Remove(request_id); 347 match_callbacks_.Remove(request_id);
363 match_times_.erase(request_id); 348 match_times_.erase(request_id);
364 } 349 }
365 350
366 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasError( 351 void CacheStorageDispatcher::OnCacheStorageHasError(
367 int thread_id, 352 int thread_id,
368 int request_id, 353 int request_id,
369 blink::WebServiceWorkerCacheError reason) { 354 blink::WebServiceWorkerCacheError reason) {
370 DCHECK_EQ(thread_id, CurrentWorkerId()); 355 DCHECK_EQ(thread_id, CurrentWorkerId());
371 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks = 356 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks =
372 has_callbacks_.Lookup(request_id); 357 has_callbacks_.Lookup(request_id);
373 callbacks->onError(&reason); 358 callbacks->onError(&reason);
374 has_callbacks_.Remove(request_id); 359 has_callbacks_.Remove(request_id);
375 has_times_.erase(request_id); 360 has_times_.erase(request_id);
376 } 361 }
377 362
378 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageOpenError( 363 void CacheStorageDispatcher::OnCacheStorageOpenError(
379 int thread_id, 364 int thread_id,
380 int request_id, 365 int request_id,
381 blink::WebServiceWorkerCacheError reason) { 366 blink::WebServiceWorkerCacheError reason) {
382 DCHECK_EQ(thread_id, CurrentWorkerId()); 367 DCHECK_EQ(thread_id, CurrentWorkerId());
383 WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* callbacks = 368 WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* callbacks =
384 open_callbacks_.Lookup(request_id); 369 open_callbacks_.Lookup(request_id);
385 callbacks->onError(&reason); 370 callbacks->onError(&reason);
386 open_callbacks_.Remove(request_id); 371 open_callbacks_.Remove(request_id);
387 open_times_.erase(request_id); 372 open_times_.erase(request_id);
388 } 373 }
389 374
390 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageDeleteError( 375 void CacheStorageDispatcher::OnCacheStorageDeleteError(
391 int thread_id, 376 int thread_id,
392 int request_id, 377 int request_id,
393 blink::WebServiceWorkerCacheError reason) { 378 blink::WebServiceWorkerCacheError reason) {
394 DCHECK_EQ(thread_id, CurrentWorkerId()); 379 DCHECK_EQ(thread_id, CurrentWorkerId());
395 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks = 380 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks =
396 delete_callbacks_.Lookup(request_id); 381 delete_callbacks_.Lookup(request_id);
397 callbacks->onError(&reason); 382 callbacks->onError(&reason);
398 delete_callbacks_.Remove(request_id); 383 delete_callbacks_.Remove(request_id);
399 delete_times_.erase(request_id); 384 delete_times_.erase(request_id);
400 } 385 }
401 386
402 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageKeysError( 387 void CacheStorageDispatcher::OnCacheStorageKeysError(
403 int thread_id, 388 int thread_id,
404 int request_id, 389 int request_id,
405 blink::WebServiceWorkerCacheError reason) { 390 blink::WebServiceWorkerCacheError reason) {
406 DCHECK_EQ(thread_id, CurrentWorkerId()); 391 DCHECK_EQ(thread_id, CurrentWorkerId());
407 WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks = 392 WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks =
408 keys_callbacks_.Lookup(request_id); 393 keys_callbacks_.Lookup(request_id);
409 callbacks->onError(&reason); 394 callbacks->onError(&reason);
410 keys_callbacks_.Remove(request_id); 395 keys_callbacks_.Remove(request_id);
411 keys_times_.erase(request_id); 396 keys_times_.erase(request_id);
412 } 397 }
413 398
414 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageMatchError( 399 void CacheStorageDispatcher::OnCacheStorageMatchError(
415 int thread_id, 400 int thread_id,
416 int request_id, 401 int request_id,
417 blink::WebServiceWorkerCacheError reason) { 402 blink::WebServiceWorkerCacheError reason) {
418 DCHECK_EQ(thread_id, CurrentWorkerId()); 403 DCHECK_EQ(thread_id, CurrentWorkerId());
419 WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* callbacks = 404 WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* callbacks =
420 match_callbacks_.Lookup(request_id); 405 match_callbacks_.Lookup(request_id);
421 callbacks->onError(&reason); 406 callbacks->onError(&reason);
422 match_callbacks_.Remove(request_id); 407 match_callbacks_.Remove(request_id);
423 match_times_.erase(request_id); 408 match_times_.erase(request_id);
424 } 409 }
425 410
426 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchSuccess( 411 void CacheStorageDispatcher::OnCacheMatchSuccess(
427 int thread_id, 412 int thread_id,
428 int request_id, 413 int request_id,
429 const ServiceWorkerResponse& response) { 414 const ServiceWorkerResponse& response) {
430 DCHECK_EQ(thread_id, CurrentWorkerId()); 415 DCHECK_EQ(thread_id, CurrentWorkerId());
431 blink::WebServiceWorkerResponse web_response; 416 blink::WebServiceWorkerResponse web_response;
432 PopulateWebResponseFromResponse(response, &web_response); 417 PopulateWebResponseFromResponse(response, &web_response);
433 418
434 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Match", 419 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Match",
435 TimeTicks::Now() - cache_match_times_[request_id]); 420 TimeTicks::Now() - cache_match_times_[request_id]);
436 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks = 421 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks =
437 cache_match_callbacks_.Lookup(request_id); 422 cache_match_callbacks_.Lookup(request_id);
438 callbacks->onSuccess(&web_response); 423 callbacks->onSuccess(&web_response);
439 cache_match_callbacks_.Remove(request_id); 424 cache_match_callbacks_.Remove(request_id);
440 cache_match_times_.erase(request_id); 425 cache_match_times_.erase(request_id);
441 } 426 }
442 427
443 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchAllSuccess( 428 void CacheStorageDispatcher::OnCacheMatchAllSuccess(
444 int thread_id, 429 int thread_id,
445 int request_id, 430 int request_id,
446 const std::vector<ServiceWorkerResponse>& responses) { 431 const std::vector<ServiceWorkerResponse>& responses) {
447 DCHECK_EQ(thread_id, CurrentWorkerId()); 432 DCHECK_EQ(thread_id, CurrentWorkerId());
448 blink::WebVector<blink::WebServiceWorkerResponse> 433 blink::WebVector<blink::WebServiceWorkerResponse> web_responses =
449 web_responses = WebResponsesFromResponses(responses); 434 WebResponsesFromResponses(responses);
450 435
451 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.MatchAll", 436 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.MatchAll",
452 TimeTicks::Now() - cache_match_all_times_[request_id]); 437 TimeTicks::Now() - cache_match_all_times_[request_id]);
453 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = 438 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks =
454 cache_match_all_callbacks_.Lookup(request_id); 439 cache_match_all_callbacks_.Lookup(request_id);
455 callbacks->onSuccess(&web_responses); 440 callbacks->onSuccess(&web_responses);
456 cache_match_all_callbacks_.Remove(request_id); 441 cache_match_all_callbacks_.Remove(request_id);
457 cache_match_all_times_.erase(request_id); 442 cache_match_all_times_.erase(request_id);
458 } 443 }
459 444
460 void ServiceWorkerCacheStorageDispatcher::OnCacheKeysSuccess( 445 void CacheStorageDispatcher::OnCacheKeysSuccess(
461 int thread_id, 446 int thread_id,
462 int request_id, 447 int request_id,
463 const std::vector<ServiceWorkerFetchRequest>& requests) { 448 const std::vector<ServiceWorkerFetchRequest>& requests) {
464 DCHECK_EQ(thread_id, CurrentWorkerId()); 449 DCHECK_EQ(thread_id, CurrentWorkerId());
465 blink::WebVector<blink::WebServiceWorkerRequest> 450 blink::WebVector<blink::WebServiceWorkerRequest> web_requests =
466 web_requests = WebRequestsFromRequests(requests); 451 WebRequestsFromRequests(requests);
467 452
468 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Keys", 453 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Keys",
469 TimeTicks::Now() - cache_keys_times_[request_id]); 454 TimeTicks::Now() - cache_keys_times_[request_id]);
470 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks = 455 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks =
471 cache_keys_callbacks_.Lookup(request_id); 456 cache_keys_callbacks_.Lookup(request_id);
472 callbacks->onSuccess(&web_requests); 457 callbacks->onSuccess(&web_requests);
473 cache_keys_callbacks_.Remove(request_id); 458 cache_keys_callbacks_.Remove(request_id);
474 cache_keys_times_.erase(request_id); 459 cache_keys_times_.erase(request_id);
475 } 460 }
476 461
477 void ServiceWorkerCacheStorageDispatcher::OnCacheBatchSuccess( 462 void CacheStorageDispatcher::OnCacheBatchSuccess(
478 int thread_id, 463 int thread_id,
479 int request_id, 464 int request_id,
480 const std::vector<ServiceWorkerResponse>& responses) { 465 const std::vector<ServiceWorkerResponse>& responses) {
481 DCHECK_EQ(thread_id, CurrentWorkerId()); 466 DCHECK_EQ(thread_id, CurrentWorkerId());
482 blink::WebVector<blink::WebServiceWorkerResponse> 467 blink::WebVector<blink::WebServiceWorkerResponse> web_responses =
483 web_responses = WebResponsesFromResponses(responses); 468 WebResponsesFromResponses(responses);
484 469
485 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Batch", 470 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Batch",
486 TimeTicks::Now() - cache_batch_times_[request_id]); 471 TimeTicks::Now() - cache_batch_times_[request_id]);
487 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = 472 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks =
488 cache_batch_callbacks_.Lookup(request_id); 473 cache_batch_callbacks_.Lookup(request_id);
489 callbacks->onSuccess(&web_responses); 474 callbacks->onSuccess(&web_responses);
490 cache_batch_callbacks_.Remove(request_id); 475 cache_batch_callbacks_.Remove(request_id);
491 cache_batch_times_.erase(request_id); 476 cache_batch_times_.erase(request_id);
492 } 477 }
493 478
494 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchError( 479 void CacheStorageDispatcher::OnCacheMatchError(
495 int thread_id, 480 int thread_id,
496 int request_id, 481 int request_id,
497 blink::WebServiceWorkerCacheError reason) { 482 blink::WebServiceWorkerCacheError reason) {
498 DCHECK_EQ(thread_id, CurrentWorkerId()); 483 DCHECK_EQ(thread_id, CurrentWorkerId());
499 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks = 484 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks =
500 cache_match_callbacks_.Lookup(request_id); 485 cache_match_callbacks_.Lookup(request_id);
501 callbacks->onError(&reason); 486 callbacks->onError(&reason);
502 cache_match_callbacks_.Remove(request_id); 487 cache_match_callbacks_.Remove(request_id);
503 cache_match_times_.erase(request_id); 488 cache_match_times_.erase(request_id);
504 } 489 }
505 490
506 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchAllError( 491 void CacheStorageDispatcher::OnCacheMatchAllError(
507 int thread_id, 492 int thread_id,
508 int request_id, 493 int request_id,
509 blink::WebServiceWorkerCacheError reason) { 494 blink::WebServiceWorkerCacheError reason) {
510 DCHECK_EQ(thread_id, CurrentWorkerId()); 495 DCHECK_EQ(thread_id, CurrentWorkerId());
511 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = 496 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks =
512 cache_match_all_callbacks_.Lookup(request_id); 497 cache_match_all_callbacks_.Lookup(request_id);
513 callbacks->onError(&reason); 498 callbacks->onError(&reason);
514 cache_match_all_callbacks_.Remove(request_id); 499 cache_match_all_callbacks_.Remove(request_id);
515 cache_match_all_times_.erase(request_id); 500 cache_match_all_times_.erase(request_id);
516 } 501 }
517 502
518 void ServiceWorkerCacheStorageDispatcher::OnCacheKeysError( 503 void CacheStorageDispatcher::OnCacheKeysError(
519 int thread_id, 504 int thread_id,
520 int request_id, 505 int request_id,
521 blink::WebServiceWorkerCacheError reason) { 506 blink::WebServiceWorkerCacheError reason) {
522 DCHECK_EQ(thread_id, CurrentWorkerId()); 507 DCHECK_EQ(thread_id, CurrentWorkerId());
523 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks = 508 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks =
524 cache_keys_callbacks_.Lookup(request_id); 509 cache_keys_callbacks_.Lookup(request_id);
525 callbacks->onError(&reason); 510 callbacks->onError(&reason);
526 cache_keys_callbacks_.Remove(request_id); 511 cache_keys_callbacks_.Remove(request_id);
527 cache_keys_times_.erase(request_id); 512 cache_keys_times_.erase(request_id);
528 } 513 }
529 514
530 void ServiceWorkerCacheStorageDispatcher::OnCacheBatchError( 515 void CacheStorageDispatcher::OnCacheBatchError(
531 int thread_id, 516 int thread_id,
532 int request_id, 517 int request_id,
533 blink::WebServiceWorkerCacheError reason) { 518 blink::WebServiceWorkerCacheError reason) {
534 DCHECK_EQ(thread_id, CurrentWorkerId()); 519 DCHECK_EQ(thread_id, CurrentWorkerId());
535 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = 520 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks =
536 cache_batch_callbacks_.Lookup(request_id); 521 cache_batch_callbacks_.Lookup(request_id);
537 callbacks->onError(&reason); 522 callbacks->onError(&reason);
538 cache_batch_callbacks_.Remove(request_id); 523 cache_batch_callbacks_.Remove(request_id);
539 cache_batch_times_.erase(request_id); 524 cache_batch_times_.erase(request_id);
540 } 525 }
541 526
542 void ServiceWorkerCacheStorageDispatcher::dispatchHas( 527 void CacheStorageDispatcher::dispatchHas(
543 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks, 528 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks,
544 const GURL& origin, 529 const GURL& origin,
545 const blink::WebString& cacheName) { 530 const blink::WebString& cacheName) {
546 int request_id = has_callbacks_.Add(callbacks); 531 int request_id = has_callbacks_.Add(callbacks);
547 has_times_[request_id] = base::TimeTicks::Now(); 532 has_times_[request_id] = base::TimeTicks::Now();
548 Send(new ServiceWorkerHostMsg_CacheStorageHas(CurrentWorkerId(), request_id, 533 Send(new CacheStorageHostMsg_CacheStorageHas(CurrentWorkerId(), request_id,
549 origin, cacheName)); 534 origin, cacheName));
550 } 535 }
551 536
552 void ServiceWorkerCacheStorageDispatcher::dispatchOpen( 537 void CacheStorageDispatcher::dispatchOpen(
553 WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* callbacks, 538 WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* callbacks,
554 const GURL& origin, 539 const GURL& origin,
555 const blink::WebString& cacheName) { 540 const blink::WebString& cacheName) {
556 int request_id = open_callbacks_.Add(callbacks); 541 int request_id = open_callbacks_.Add(callbacks);
557 open_times_[request_id] = base::TimeTicks::Now(); 542 open_times_[request_id] = base::TimeTicks::Now();
558 Send(new ServiceWorkerHostMsg_CacheStorageOpen(CurrentWorkerId(), request_id, 543 Send(new CacheStorageHostMsg_CacheStorageOpen(CurrentWorkerId(), request_id,
559 origin, cacheName)); 544 origin, cacheName));
560 } 545 }
561 546
562 void ServiceWorkerCacheStorageDispatcher::dispatchDelete( 547 void CacheStorageDispatcher::dispatchDelete(
563 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks, 548 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks,
564 const GURL& origin, 549 const GURL& origin,
565 const blink::WebString& cacheName) { 550 const blink::WebString& cacheName) {
566 int request_id = delete_callbacks_.Add(callbacks); 551 int request_id = delete_callbacks_.Add(callbacks);
567 delete_times_[request_id] = base::TimeTicks::Now(); 552 delete_times_[request_id] = base::TimeTicks::Now();
568 Send(new ServiceWorkerHostMsg_CacheStorageDelete( 553 Send(new CacheStorageHostMsg_CacheStorageDelete(CurrentWorkerId(), request_id,
569 CurrentWorkerId(), request_id, origin, cacheName)); 554 origin, cacheName));
570 } 555 }
571 556
572 void ServiceWorkerCacheStorageDispatcher::dispatchKeys( 557 void CacheStorageDispatcher::dispatchKeys(
573 WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks, 558 WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks,
574 const GURL& origin) { 559 const GURL& origin) {
575 int request_id = keys_callbacks_.Add(callbacks); 560 int request_id = keys_callbacks_.Add(callbacks);
576 keys_times_[request_id] = base::TimeTicks::Now(); 561 keys_times_[request_id] = base::TimeTicks::Now();
577 Send(new ServiceWorkerHostMsg_CacheStorageKeys(CurrentWorkerId(), request_id, 562 Send(new CacheStorageHostMsg_CacheStorageKeys(CurrentWorkerId(), request_id,
578 origin)); 563 origin));
579 } 564 }
580 565
581 void ServiceWorkerCacheStorageDispatcher::dispatchMatch( 566 void CacheStorageDispatcher::dispatchMatch(
582 WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* callbacks, 567 WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* callbacks,
583 const GURL& origin, 568 const GURL& origin,
584 const blink::WebServiceWorkerRequest& request, 569 const blink::WebServiceWorkerRequest& request,
585 const blink::WebServiceWorkerCache::QueryParams& query_params) { 570 const blink::WebServiceWorkerCache::QueryParams& query_params) {
586 int request_id = match_callbacks_.Add(callbacks); 571 int request_id = match_callbacks_.Add(callbacks);
587 match_times_[request_id] = base::TimeTicks::Now(); 572 match_times_[request_id] = base::TimeTicks::Now();
588 Send(new ServiceWorkerHostMsg_CacheStorageMatch( 573 Send(new CacheStorageHostMsg_CacheStorageMatch(
589 CurrentWorkerId(), request_id, origin, 574 CurrentWorkerId(), request_id, origin,
590 FetchRequestFromWebRequest(request), 575 FetchRequestFromWebRequest(request),
591 QueryParamsFromWebQueryParams(query_params))); 576 QueryParamsFromWebQueryParams(query_params)));
592 } 577 }
593 578
594 void ServiceWorkerCacheStorageDispatcher::dispatchMatchForCache( 579 void CacheStorageDispatcher::dispatchMatchForCache(
595 int cache_id, 580 int cache_id,
596 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks, 581 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks,
597 const blink::WebServiceWorkerRequest& request, 582 const blink::WebServiceWorkerRequest& request,
598 const blink::WebServiceWorkerCache::QueryParams& query_params) { 583 const blink::WebServiceWorkerCache::QueryParams& query_params) {
599 int request_id = cache_match_callbacks_.Add(callbacks); 584 int request_id = cache_match_callbacks_.Add(callbacks);
600 cache_match_times_[request_id] = base::TimeTicks::Now(); 585 cache_match_times_[request_id] = base::TimeTicks::Now();
601 586
602 Send(new ServiceWorkerHostMsg_CacheMatch( 587 Send(new CacheStorageHostMsg_CacheMatch(
603 CurrentWorkerId(), request_id, cache_id, 588 CurrentWorkerId(), request_id, cache_id,
604 FetchRequestFromWebRequest(request), 589 FetchRequestFromWebRequest(request),
605 QueryParamsFromWebQueryParams(query_params))); 590 QueryParamsFromWebQueryParams(query_params)));
606 } 591 }
607 592
608 void ServiceWorkerCacheStorageDispatcher::dispatchMatchAllForCache( 593 void CacheStorageDispatcher::dispatchMatchAllForCache(
609 int cache_id, 594 int cache_id,
610 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks, 595 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks,
611 const blink::WebServiceWorkerRequest& request, 596 const blink::WebServiceWorkerRequest& request,
612 const blink::WebServiceWorkerCache::QueryParams& query_params) { 597 const blink::WebServiceWorkerCache::QueryParams& query_params) {
613 int request_id = cache_match_all_callbacks_.Add(callbacks); 598 int request_id = cache_match_all_callbacks_.Add(callbacks);
614 cache_match_all_times_[request_id] = base::TimeTicks::Now(); 599 cache_match_all_times_[request_id] = base::TimeTicks::Now();
615 600
616 Send(new ServiceWorkerHostMsg_CacheMatchAll( 601 Send(new CacheStorageHostMsg_CacheMatchAll(
617 CurrentWorkerId(), request_id, cache_id, 602 CurrentWorkerId(), request_id, cache_id,
618 FetchRequestFromWebRequest(request), 603 FetchRequestFromWebRequest(request),
619 QueryParamsFromWebQueryParams(query_params))); 604 QueryParamsFromWebQueryParams(query_params)));
620 } 605 }
621 606
622 void ServiceWorkerCacheStorageDispatcher::dispatchKeysForCache( 607 void CacheStorageDispatcher::dispatchKeysForCache(
623 int cache_id, 608 int cache_id,
624 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks, 609 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks,
625 const blink::WebServiceWorkerRequest* request, 610 const blink::WebServiceWorkerRequest* request,
626 const blink::WebServiceWorkerCache::QueryParams& query_params) { 611 const blink::WebServiceWorkerCache::QueryParams& query_params) {
627 int request_id = cache_keys_callbacks_.Add(callbacks); 612 int request_id = cache_keys_callbacks_.Add(callbacks);
628 cache_keys_times_[request_id] = base::TimeTicks::Now(); 613 cache_keys_times_[request_id] = base::TimeTicks::Now();
629 614
630 Send(new ServiceWorkerHostMsg_CacheKeys( 615 Send(new CacheStorageHostMsg_CacheKeys(
631 CurrentWorkerId(), request_id, cache_id, 616 CurrentWorkerId(), request_id, cache_id,
632 request ? FetchRequestFromWebRequest(*request) 617 request ? FetchRequestFromWebRequest(*request)
633 : ServiceWorkerFetchRequest(), 618 : ServiceWorkerFetchRequest(),
634 QueryParamsFromWebQueryParams(query_params))); 619 QueryParamsFromWebQueryParams(query_params)));
635 } 620 }
636 621
637 void ServiceWorkerCacheStorageDispatcher::dispatchBatchForCache( 622 void CacheStorageDispatcher::dispatchBatchForCache(
638 int cache_id, 623 int cache_id,
639 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks, 624 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks,
640 const blink::WebVector< 625 const blink::WebVector<blink::WebServiceWorkerCache::BatchOperation>&
641 blink::WebServiceWorkerCache::BatchOperation>& web_operations) { 626 web_operations) {
642 int request_id = cache_batch_callbacks_.Add(callbacks); 627 int request_id = cache_batch_callbacks_.Add(callbacks);
643 cache_batch_times_[request_id] = base::TimeTicks::Now(); 628 cache_batch_times_[request_id] = base::TimeTicks::Now();
644 629
645 std::vector<ServiceWorkerBatchOperation> operations; 630 std::vector<CacheStorageBatchOperation> operations;
646 operations.reserve(web_operations.size()); 631 operations.reserve(web_operations.size());
647 for (size_t i = 0; i < web_operations.size(); ++i) { 632 for (size_t i = 0; i < web_operations.size(); ++i) {
648 operations.push_back( 633 operations.push_back(
649 BatchOperationFromWebBatchOperation(web_operations[i])); 634 BatchOperationFromWebBatchOperation(web_operations[i]));
650 } 635 }
651 636
652 Send(new ServiceWorkerHostMsg_CacheBatch(CurrentWorkerId(), request_id, 637 Send(new CacheStorageHostMsg_CacheBatch(CurrentWorkerId(), request_id,
653 cache_id, operations)); 638 cache_id, operations));
654 } 639 }
655 640
656 void ServiceWorkerCacheStorageDispatcher::OnWebCacheDestruction(int cache_id) { 641 void CacheStorageDispatcher::OnWebCacheDestruction(int cache_id) {
657 web_caches_.Remove(cache_id); 642 web_caches_.Remove(cache_id);
658 Send(new ServiceWorkerHostMsg_CacheClosed(cache_id)); 643 Send(new CacheStorageHostMsg_CacheClosed(cache_id));
659 } 644 }
660 645
661 void ServiceWorkerCacheStorageDispatcher::PopulateWebResponseFromResponse( 646 void CacheStorageDispatcher::PopulateWebResponseFromResponse(
662 const ServiceWorkerResponse& response, 647 const ServiceWorkerResponse& response,
663 blink::WebServiceWorkerResponse* web_response) { 648 blink::WebServiceWorkerResponse* web_response) {
664 web_response->setURL(response.url); 649 web_response->setURL(response.url);
665 web_response->setStatus(response.status_code); 650 web_response->setStatus(response.status_code);
666 web_response->setStatusText(base::ASCIIToUTF16(response.status_text)); 651 web_response->setStatusText(base::ASCIIToUTF16(response.status_text));
667 web_response->setResponseType(response.response_type); 652 web_response->setResponseType(response.response_type);
668 653
669 for (const auto& i : response.headers) { 654 for (const auto& i : response.headers) {
670 web_response->setHeader(base::ASCIIToUTF16(i.first), 655 web_response->setHeader(base::ASCIIToUTF16(i.first),
671 base::ASCIIToUTF16(i.second)); 656 base::ASCIIToUTF16(i.second));
672 } 657 }
673 658
674 if (!response.blob_uuid.empty()) { 659 if (!response.blob_uuid.empty()) {
675 web_response->setBlob(blink::WebString::fromUTF8(response.blob_uuid), 660 web_response->setBlob(blink::WebString::fromUTF8(response.blob_uuid),
676 response.blob_size); 661 response.blob_size);
677 // Let the host know that it can release its reference to the blob. 662 // Let the host know that it can release its reference to the blob.
678 Send(new ServiceWorkerHostMsg_BlobDataHandled(response.blob_uuid)); 663 Send(new CacheStorageHostMsg_BlobDataHandled(response.blob_uuid));
679 } 664 }
680 } 665 }
681 666
682 blink::WebVector<blink::WebServiceWorkerResponse> 667 blink::WebVector<blink::WebServiceWorkerResponse>
683 ServiceWorkerCacheStorageDispatcher::WebResponsesFromResponses( 668 CacheStorageDispatcher::WebResponsesFromResponses(
684 const std::vector<ServiceWorkerResponse>& responses) { 669 const std::vector<ServiceWorkerResponse>& responses) {
685 blink::WebVector<blink::WebServiceWorkerResponse> web_responses( 670 blink::WebVector<blink::WebServiceWorkerResponse> web_responses(
686 responses.size()); 671 responses.size());
687 for (size_t i = 0; i < responses.size(); ++i) 672 for (size_t i = 0; i < responses.size(); ++i)
688 PopulateWebResponseFromResponse(responses[i], &(web_responses[i])); 673 PopulateWebResponseFromResponse(responses[i], &(web_responses[i]));
689 return web_responses; 674 return web_responses;
690 } 675 }
691 676
692 } // namespace content 677 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698