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_cache_listener.h" | 5 #include "content/browser/service_worker/service_worker_cache_listener.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "content/browser/service_worker/cache_storage_context_impl.h" | |
10 #include "content/browser/service_worker/service_worker_cache.h" | 11 #include "content/browser/service_worker/service_worker_cache.h" |
11 #include "content/browser/service_worker/service_worker_cache_storage_manager.h" | 12 #include "content/browser/service_worker/service_worker_cache_storage_manager.h" |
12 #include "content/browser/service_worker/service_worker_context_core.h" | 13 #include "content/common/service_worker/cache_storage_messages.h" |
13 #include "content/browser/service_worker/service_worker_version.h" | |
14 #include "content/common/service_worker/service_worker_messages.h" | |
15 #include "storage/browser/blob/blob_data_handle.h" | 14 #include "storage/browser/blob/blob_data_handle.h" |
16 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h" | 15 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h" |
17 | 16 |
18 namespace content { | 17 namespace content { |
19 | 18 |
20 using blink::WebServiceWorkerCacheError; | 19 using blink::WebServiceWorkerCacheError; |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
24 WebServiceWorkerCacheError ToWebServiceWorkerCacheError( | 23 WebServiceWorkerCacheError ToWebServiceWorkerCacheError( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 case ServiceWorkerCache::ErrorTypeNotFound: | 62 case ServiceWorkerCache::ErrorTypeNotFound: |
64 return blink::WebServiceWorkerCacheErrorNotFound; | 63 return blink::WebServiceWorkerCacheErrorNotFound; |
65 } | 64 } |
66 NOTREACHED(); | 65 NOTREACHED(); |
67 return blink::WebServiceWorkerCacheErrorNotImplemented; | 66 return blink::WebServiceWorkerCacheErrorNotImplemented; |
68 } | 67 } |
69 | 68 |
70 } // namespace | 69 } // namespace |
71 | 70 |
72 ServiceWorkerCacheListener::ServiceWorkerCacheListener( | 71 ServiceWorkerCacheListener::ServiceWorkerCacheListener( |
73 ServiceWorkerVersion* version, | 72 CacheStorageDispatcherHost* dispatcher, |
74 base::WeakPtr<ServiceWorkerContextCore> context) | 73 CacheStorageContextImpl* context) |
75 : version_(version), | 74 : dispatcher_(dispatcher), context_(context), weak_factory_(this) { |
76 context_(context), | |
77 next_cache_id_(0), | |
78 weak_factory_(this) { | |
79 version_->embedded_worker()->AddListener(this); | |
80 } | 75 } |
81 | 76 |
82 ServiceWorkerCacheListener::~ServiceWorkerCacheListener() { | 77 ServiceWorkerCacheListener::~ServiceWorkerCacheListener() { |
83 version_->embedded_worker()->RemoveListener(this); | |
84 } | 78 } |
85 | 79 |
86 bool ServiceWorkerCacheListener::OnMessageReceived( | 80 bool ServiceWorkerCacheListener::OnMessageReceived( |
87 const IPC::Message& message) { | 81 const IPC::Message& message) { |
88 bool handled = true; | 82 bool handled = true; |
89 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerCacheListener, message) | 83 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerCacheListener, message) |
90 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageHas, | 84 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageHas, |
91 OnCacheStorageHas) | 85 OnCacheStorageHas) |
92 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageOpen, | 86 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageOpen, |
93 OnCacheStorageOpen) | 87 OnCacheStorageOpen) |
(...skipping 14 matching lines...) Expand all Loading... | |
108 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheClosed, | 102 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheClosed, |
109 OnCacheClosed) | 103 OnCacheClosed) |
110 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_BlobDataHandled, OnBlobDataHandled) | 104 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_BlobDataHandled, OnBlobDataHandled) |
111 IPC_MESSAGE_UNHANDLED(handled = false) | 105 IPC_MESSAGE_UNHANDLED(handled = false) |
112 IPC_END_MESSAGE_MAP() | 106 IPC_END_MESSAGE_MAP() |
113 | 107 |
114 return handled; | 108 return handled; |
115 } | 109 } |
116 | 110 |
117 void ServiceWorkerCacheListener::OnCacheStorageHas( | 111 void ServiceWorkerCacheListener::OnCacheStorageHas( |
112 int thread_id, | |
118 int request_id, | 113 int request_id, |
114 const GURL& origin, | |
119 const base::string16& cache_name) { | 115 const base::string16& cache_name) { |
120 TRACE_EVENT0("ServiceWorker", | 116 TRACE_EVENT0("ServiceWorker", |
121 "ServiceWorkerCacheListener::OnCacheStorageHas"); | 117 "ServiceWorkerCacheListener::OnCacheStorageHas"); |
122 context_->cache_manager()->HasCache( | 118 context_->cache_manager()->HasCache( |
123 version_->scope().GetOrigin(), | 119 origin, base::UTF16ToUTF8(cache_name), |
124 base::UTF16ToUTF8(cache_name), | |
125 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageHasCallback, | 120 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageHasCallback, |
126 weak_factory_.GetWeakPtr(), | 121 weak_factory_.GetWeakPtr(), thread_id, request_id)); |
127 request_id)); | |
128 } | 122 } |
129 | 123 |
130 void ServiceWorkerCacheListener::OnCacheStorageOpen( | 124 void ServiceWorkerCacheListener::OnCacheStorageOpen( |
125 int thread_id, | |
131 int request_id, | 126 int request_id, |
127 const GURL& origin, | |
132 const base::string16& cache_name) { | 128 const base::string16& cache_name) { |
133 TRACE_EVENT0("ServiceWorker", | 129 TRACE_EVENT0("ServiceWorker", |
134 "ServiceWorkerCacheListener::OnCacheStorageOpen"); | 130 "ServiceWorkerCacheListener::OnCacheStorageOpen"); |
135 context_->cache_manager()->OpenCache( | 131 context_->cache_manager()->OpenCache( |
136 version_->scope().GetOrigin(), | 132 origin, base::UTF16ToUTF8(cache_name), |
137 base::UTF16ToUTF8(cache_name), | |
138 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageOpenCallback, | 133 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageOpenCallback, |
139 weak_factory_.GetWeakPtr(), | 134 weak_factory_.GetWeakPtr(), thread_id, request_id)); |
140 request_id)); | |
141 } | 135 } |
142 | 136 |
143 void ServiceWorkerCacheListener::OnCacheStorageDelete( | 137 void ServiceWorkerCacheListener::OnCacheStorageDelete( |
138 int thread_id, | |
144 int request_id, | 139 int request_id, |
140 const GURL& origin, | |
145 const base::string16& cache_name) { | 141 const base::string16& cache_name) { |
146 TRACE_EVENT0("ServiceWorker", | 142 TRACE_EVENT0("ServiceWorker", |
147 "ServiceWorkerCacheListener::OnCacheStorageDelete"); | 143 "ServiceWorkerCacheListener::OnCacheStorageDelete"); |
148 context_->cache_manager()->DeleteCache( | 144 context_->cache_manager()->DeleteCache( |
149 version_->scope().GetOrigin(), | 145 origin, base::UTF16ToUTF8(cache_name), |
150 base::UTF16ToUTF8(cache_name), | |
151 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageDeleteCallback, | 146 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageDeleteCallback, |
152 weak_factory_.GetWeakPtr(), | 147 weak_factory_.GetWeakPtr(), thread_id, request_id)); |
153 request_id)); | |
154 } | 148 } |
155 | 149 |
156 void ServiceWorkerCacheListener::OnCacheStorageKeys(int request_id) { | 150 void ServiceWorkerCacheListener::OnCacheStorageKeys(int thread_id, |
151 int request_id, | |
152 const GURL& origin) { | |
157 TRACE_EVENT0("ServiceWorker", | 153 TRACE_EVENT0("ServiceWorker", |
158 "ServiceWorkerCacheListener::OnCacheStorageKeys"); | 154 "ServiceWorkerCacheListener::OnCacheStorageKeys"); |
159 context_->cache_manager()->EnumerateCaches( | 155 context_->cache_manager()->EnumerateCaches( |
160 version_->scope().GetOrigin(), | 156 origin, |
161 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageKeysCallback, | 157 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageKeysCallback, |
162 weak_factory_.GetWeakPtr(), | 158 weak_factory_.GetWeakPtr(), thread_id, request_id)); |
163 request_id)); | |
164 } | 159 } |
165 | 160 |
166 void ServiceWorkerCacheListener::OnCacheStorageMatch( | 161 void ServiceWorkerCacheListener::OnCacheStorageMatch( |
162 int thread_id, | |
167 int request_id, | 163 int request_id, |
164 const GURL& origin, | |
168 const ServiceWorkerFetchRequest& request, | 165 const ServiceWorkerFetchRequest& request, |
169 const ServiceWorkerCacheQueryParams& match_params) { | 166 const ServiceWorkerCacheQueryParams& match_params) { |
170 TRACE_EVENT0("ServiceWorker", | 167 TRACE_EVENT0("ServiceWorker", |
171 "ServiceWorkerCacheListener::OnCacheStorageMatch"); | 168 "ServiceWorkerCacheListener::OnCacheStorageMatch"); |
172 | 169 |
173 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( | 170 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( |
174 new ServiceWorkerFetchRequest(request.url, request.method, | 171 new ServiceWorkerFetchRequest(request.url, request.method, |
175 request.headers, request.referrer, | 172 request.headers, request.referrer, |
176 request.is_reload)); | 173 request.is_reload)); |
177 | 174 |
178 if (match_params.cache_name.empty()) { | 175 if (match_params.cache_name.empty()) { |
179 context_->cache_manager()->MatchAllCaches( | 176 context_->cache_manager()->MatchAllCaches( |
180 version_->scope().GetOrigin(), scoped_request.Pass(), | 177 origin, scoped_request.Pass(), |
181 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageMatchCallback, | 178 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageMatchCallback, |
182 weak_factory_.GetWeakPtr(), request_id)); | 179 weak_factory_.GetWeakPtr(), thread_id, request_id)); |
183 return; | 180 return; |
184 } | 181 } |
185 context_->cache_manager()->MatchCache( | 182 context_->cache_manager()->MatchCache( |
186 version_->scope().GetOrigin(), base::UTF16ToUTF8(match_params.cache_name), | 183 origin, base::UTF16ToUTF8(match_params.cache_name), scoped_request.Pass(), |
187 scoped_request.Pass(), | |
188 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageMatchCallback, | 184 base::Bind(&ServiceWorkerCacheListener::OnCacheStorageMatchCallback, |
189 weak_factory_.GetWeakPtr(), request_id)); | 185 weak_factory_.GetWeakPtr(), thread_id, request_id)); |
190 } | 186 } |
191 | 187 |
192 void ServiceWorkerCacheListener::OnCacheMatch( | 188 void ServiceWorkerCacheListener::OnCacheMatch( |
189 int thread_id, | |
193 int request_id, | 190 int request_id, |
194 int cache_id, | 191 int cache_id, |
195 const ServiceWorkerFetchRequest& request, | 192 const ServiceWorkerFetchRequest& request, |
196 const ServiceWorkerCacheQueryParams& match_params) { | 193 const ServiceWorkerCacheQueryParams& match_params) { |
197 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); | 194 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
198 if (it == id_to_cache_map_.end()) { | 195 if (it == id_to_cache_map_.end()) { |
199 Send(ServiceWorkerMsg_CacheMatchError( | 196 Send(new ServiceWorkerMsg_CacheMatchError( |
michaeln
2015/03/12 02:03:43
this compiled before? Oh, a different Send() metho
| |
200 request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 197 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
201 return; | 198 return; |
202 } | 199 } |
203 | 200 |
204 scoped_refptr<ServiceWorkerCache> cache = it->second; | 201 scoped_refptr<ServiceWorkerCache> cache = it->second; |
205 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( | 202 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( |
206 new ServiceWorkerFetchRequest(request.url, | 203 new ServiceWorkerFetchRequest(request.url, |
207 request.method, | 204 request.method, |
208 request.headers, | 205 request.headers, |
209 request.referrer, | 206 request.referrer, |
210 request.is_reload)); | 207 request.is_reload)); |
211 cache->Match(scoped_request.Pass(), | 208 cache->Match( |
212 base::Bind(&ServiceWorkerCacheListener::OnCacheMatchCallback, | 209 scoped_request.Pass(), |
213 weak_factory_.GetWeakPtr(), | 210 base::Bind(&ServiceWorkerCacheListener::OnCacheMatchCallback, |
214 request_id, | 211 weak_factory_.GetWeakPtr(), thread_id, request_id, cache)); |
215 cache)); | |
216 } | 212 } |
217 | 213 |
218 void ServiceWorkerCacheListener::OnCacheMatchAll( | 214 void ServiceWorkerCacheListener::OnCacheMatchAll( |
215 int thread_id, | |
219 int request_id, | 216 int request_id, |
220 int cache_id, | 217 int cache_id, |
221 const ServiceWorkerFetchRequest& request, | 218 const ServiceWorkerFetchRequest& request, |
222 const ServiceWorkerCacheQueryParams& match_params) { | 219 const ServiceWorkerCacheQueryParams& match_params) { |
223 // TODO(gavinp,jkarlin): Implement this method. | 220 // TODO(gavinp,jkarlin): Implement this method. |
224 Send(ServiceWorkerMsg_CacheMatchAllError( | 221 Send(new ServiceWorkerMsg_CacheMatchAllError( |
225 request_id, blink::WebServiceWorkerCacheErrorNotImplemented)); | 222 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotImplemented)); |
226 } | 223 } |
227 | 224 |
228 void ServiceWorkerCacheListener::OnCacheKeys( | 225 void ServiceWorkerCacheListener::OnCacheKeys( |
226 int thread_id, | |
229 int request_id, | 227 int request_id, |
230 int cache_id, | 228 int cache_id, |
231 const ServiceWorkerFetchRequest& request, | 229 const ServiceWorkerFetchRequest& request, |
232 const ServiceWorkerCacheQueryParams& match_params) { | 230 const ServiceWorkerCacheQueryParams& match_params) { |
233 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); | 231 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
234 if (it == id_to_cache_map_.end()) { | 232 if (it == id_to_cache_map_.end()) { |
235 Send(ServiceWorkerMsg_CacheKeysError( | 233 Send(new ServiceWorkerMsg_CacheKeysError( |
236 request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 234 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
237 return; | 235 return; |
238 } | 236 } |
239 | 237 |
240 scoped_refptr<ServiceWorkerCache> cache = it->second; | 238 scoped_refptr<ServiceWorkerCache> cache = it->second; |
241 | 239 |
242 cache->Keys(base::Bind(&ServiceWorkerCacheListener::OnCacheKeysCallback, | 240 cache->Keys(base::Bind(&ServiceWorkerCacheListener::OnCacheKeysCallback, |
243 weak_factory_.GetWeakPtr(), | 241 weak_factory_.GetWeakPtr(), thread_id, request_id, |
244 request_id, | |
245 cache)); | 242 cache)); |
246 } | 243 } |
247 | 244 |
248 void ServiceWorkerCacheListener::OnCacheBatch( | 245 void ServiceWorkerCacheListener::OnCacheBatch( |
246 int thread_id, | |
249 int request_id, | 247 int request_id, |
250 int cache_id, | 248 int cache_id, |
251 const std::vector<ServiceWorkerBatchOperation>& operations) { | 249 const std::vector<ServiceWorkerBatchOperation>& operations) { |
252 if (operations.size() != 1u) { | 250 if (operations.size() != 1u) { |
253 Send(ServiceWorkerMsg_CacheBatchError( | 251 Send(new ServiceWorkerMsg_CacheBatchError( |
254 request_id, blink::WebServiceWorkerCacheErrorNotImplemented)); | 252 thread_id, request_id, |
253 blink::WebServiceWorkerCacheErrorNotImplemented)); | |
255 return; | 254 return; |
256 } | 255 } |
257 | 256 |
258 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); | 257 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
259 if (it == id_to_cache_map_.end()) { | 258 if (it == id_to_cache_map_.end()) { |
260 Send(ServiceWorkerMsg_CacheBatchError( | 259 Send(new ServiceWorkerMsg_CacheBatchError( |
261 request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 260 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
262 return; | 261 return; |
263 } | 262 } |
264 | 263 |
265 const ServiceWorkerBatchOperation& operation = operations[0]; | 264 const ServiceWorkerBatchOperation& operation = operations[0]; |
266 | 265 |
267 scoped_refptr<ServiceWorkerCache> cache = it->second; | 266 scoped_refptr<ServiceWorkerCache> cache = it->second; |
268 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( | 267 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( |
269 new ServiceWorkerFetchRequest(operation.request.url, | 268 new ServiceWorkerFetchRequest(operation.request.url, |
270 operation.request.method, | 269 operation.request.method, |
271 operation.request.headers, | 270 operation.request.headers, |
272 operation.request.referrer, | 271 operation.request.referrer, |
273 operation.request.is_reload)); | 272 operation.request.is_reload)); |
274 | 273 |
275 if (operation.operation_type == SERVICE_WORKER_CACHE_OPERATION_TYPE_DELETE) { | 274 if (operation.operation_type == SERVICE_WORKER_CACHE_OPERATION_TYPE_DELETE) { |
276 cache->Delete(scoped_request.Pass(), | 275 cache->Delete( |
277 base::Bind(&ServiceWorkerCacheListener::OnCacheDeleteCallback, | 276 scoped_request.Pass(), |
278 weak_factory_.GetWeakPtr(), | 277 base::Bind(&ServiceWorkerCacheListener::OnCacheDeleteCallback, |
279 request_id, | 278 weak_factory_.GetWeakPtr(), thread_id, request_id, cache)); |
280 cache)); | |
281 return; | 279 return; |
282 } | 280 } |
283 | 281 |
284 if (operation.operation_type == SERVICE_WORKER_CACHE_OPERATION_TYPE_PUT) { | 282 if (operation.operation_type == SERVICE_WORKER_CACHE_OPERATION_TYPE_PUT) { |
285 // We don't support streaming for cache. | 283 // We don't support streaming for cache. |
286 DCHECK(operation.response.stream_url.is_empty()); | 284 DCHECK(operation.response.stream_url.is_empty()); |
287 scoped_ptr<ServiceWorkerResponse> scoped_response( | 285 scoped_ptr<ServiceWorkerResponse> scoped_response( |
288 new ServiceWorkerResponse(operation.response.url, | 286 new ServiceWorkerResponse(operation.response.url, |
289 operation.response.status_code, | 287 operation.response.status_code, |
290 operation.response.status_text, | 288 operation.response.status_text, |
291 operation.response.response_type, | 289 operation.response.response_type, |
292 operation.response.headers, | 290 operation.response.headers, |
293 operation.response.blob_uuid, | 291 operation.response.blob_uuid, |
294 operation.response.blob_size, | 292 operation.response.blob_size, |
295 operation.response.stream_url)); | 293 operation.response.stream_url)); |
296 cache->Put(scoped_request.Pass(), | 294 cache->Put( |
297 scoped_response.Pass(), | 295 scoped_request.Pass(), scoped_response.Pass(), |
298 base::Bind(&ServiceWorkerCacheListener::OnCachePutCallback, | 296 base::Bind(&ServiceWorkerCacheListener::OnCachePutCallback, |
299 weak_factory_.GetWeakPtr(), | 297 weak_factory_.GetWeakPtr(), thread_id, request_id, cache)); |
300 request_id, | |
301 cache)); | |
302 | 298 |
303 return; | 299 return; |
304 } | 300 } |
305 | 301 |
306 Send(ServiceWorkerMsg_CacheBatchError( | 302 Send(new ServiceWorkerMsg_CacheBatchError( |
307 request_id, blink::WebServiceWorkerCacheErrorNotImplemented)); | 303 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotImplemented)); |
308 } | 304 } |
309 | 305 |
310 void ServiceWorkerCacheListener::OnCacheClosed(int cache_id) { | 306 void ServiceWorkerCacheListener::OnCacheClosed(int cache_id) { |
311 DropCacheReference(cache_id); | 307 DropCacheReference(cache_id); |
312 } | 308 } |
313 | 309 |
314 void ServiceWorkerCacheListener::OnBlobDataHandled(const std::string& uuid) { | 310 void ServiceWorkerCacheListener::OnBlobDataHandled(const std::string& uuid) { |
315 DropBlobDataHandle(uuid); | 311 DropBlobDataHandle(uuid); |
316 } | 312 } |
317 | 313 |
318 void ServiceWorkerCacheListener::Send(const IPC::Message& message) { | 314 void ServiceWorkerCacheListener::Send(IPC::Message* message) { |
319 version_->embedded_worker()->SendMessage(message); | 315 dispatcher_->Send(message); |
320 } | 316 } |
321 | 317 |
322 void ServiceWorkerCacheListener::OnCacheStorageHasCallback( | 318 void ServiceWorkerCacheListener::OnCacheStorageHasCallback( |
319 int thread_id, | |
323 int request_id, | 320 int request_id, |
324 bool has_cache, | 321 bool has_cache, |
325 ServiceWorkerCacheStorage::CacheStorageError error) { | 322 ServiceWorkerCacheStorage::CacheStorageError error) { |
326 if (error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { | 323 if (error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { |
327 Send(ServiceWorkerMsg_CacheStorageHasError( | 324 Send(new ServiceWorkerMsg_CacheStorageHasError( |
328 request_id, ToWebServiceWorkerCacheError(error))); | 325 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
329 return; | 326 return; |
330 } | 327 } |
331 if (!has_cache) { | 328 if (!has_cache) { |
332 Send(ServiceWorkerMsg_CacheStorageHasError( | 329 Send(new ServiceWorkerMsg_CacheStorageHasError( |
333 request_id, | 330 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
334 blink::WebServiceWorkerCacheErrorNotFound)); | |
335 return; | 331 return; |
336 } | 332 } |
337 Send(ServiceWorkerMsg_CacheStorageHasSuccess(request_id)); | 333 Send(new ServiceWorkerMsg_CacheStorageHasSuccess(thread_id, request_id)); |
338 } | 334 } |
339 | 335 |
340 void ServiceWorkerCacheListener::OnCacheStorageOpenCallback( | 336 void ServiceWorkerCacheListener::OnCacheStorageOpenCallback( |
337 int thread_id, | |
341 int request_id, | 338 int request_id, |
342 const scoped_refptr<ServiceWorkerCache>& cache, | 339 const scoped_refptr<ServiceWorkerCache>& cache, |
343 ServiceWorkerCacheStorage::CacheStorageError error) { | 340 ServiceWorkerCacheStorage::CacheStorageError error) { |
344 if (error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { | 341 if (error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { |
345 Send(ServiceWorkerMsg_CacheStorageOpenError( | 342 Send(new ServiceWorkerMsg_CacheStorageOpenError( |
346 request_id, ToWebServiceWorkerCacheError(error))); | 343 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
347 return; | 344 return; |
348 } | 345 } |
349 CacheID cache_id = StoreCacheReference(cache); | 346 CacheID cache_id = StoreCacheReference(cache); |
350 Send(ServiceWorkerMsg_CacheStorageOpenSuccess(request_id, cache_id)); | 347 Send(new ServiceWorkerMsg_CacheStorageOpenSuccess(thread_id, request_id, |
348 cache_id)); | |
351 } | 349 } |
352 | 350 |
353 void ServiceWorkerCacheListener::OnCacheStorageDeleteCallback( | 351 void ServiceWorkerCacheListener::OnCacheStorageDeleteCallback( |
352 int thread_id, | |
354 int request_id, | 353 int request_id, |
355 bool deleted, | 354 bool deleted, |
356 ServiceWorkerCacheStorage::CacheStorageError error) { | 355 ServiceWorkerCacheStorage::CacheStorageError error) { |
357 if (!deleted || | 356 if (!deleted || |
358 error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { | 357 error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { |
359 Send(ServiceWorkerMsg_CacheStorageDeleteError( | 358 Send(new ServiceWorkerMsg_CacheStorageDeleteError( |
360 request_id, ToWebServiceWorkerCacheError(error))); | 359 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
361 return; | 360 return; |
362 } | 361 } |
363 Send(ServiceWorkerMsg_CacheStorageDeleteSuccess(request_id)); | 362 Send(new ServiceWorkerMsg_CacheStorageDeleteSuccess(thread_id, request_id)); |
364 } | 363 } |
365 | 364 |
366 void ServiceWorkerCacheListener::OnCacheStorageKeysCallback( | 365 void ServiceWorkerCacheListener::OnCacheStorageKeysCallback( |
366 int thread_id, | |
367 int request_id, | 367 int request_id, |
368 const std::vector<std::string>& strings, | 368 const std::vector<std::string>& strings, |
369 ServiceWorkerCacheStorage::CacheStorageError error) { | 369 ServiceWorkerCacheStorage::CacheStorageError error) { |
370 if (error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { | 370 if (error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { |
371 Send(ServiceWorkerMsg_CacheStorageKeysError( | 371 Send(new ServiceWorkerMsg_CacheStorageKeysError( |
372 request_id, ToWebServiceWorkerCacheError(error))); | 372 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
373 return; | 373 return; |
374 } | 374 } |
375 | 375 |
376 std::vector<base::string16> string16s; | 376 std::vector<base::string16> string16s; |
377 for (size_t i = 0, max = strings.size(); i < max; ++i) { | 377 for (size_t i = 0, max = strings.size(); i < max; ++i) { |
378 string16s.push_back(base::UTF8ToUTF16(strings[i])); | 378 string16s.push_back(base::UTF8ToUTF16(strings[i])); |
379 } | 379 } |
380 Send(ServiceWorkerMsg_CacheStorageKeysSuccess(request_id, string16s)); | 380 Send(new ServiceWorkerMsg_CacheStorageKeysSuccess(thread_id, request_id, |
381 string16s)); | |
381 } | 382 } |
382 | 383 |
383 void ServiceWorkerCacheListener::OnCacheStorageMatchCallback( | 384 void ServiceWorkerCacheListener::OnCacheStorageMatchCallback( |
385 int thread_id, | |
384 int request_id, | 386 int request_id, |
385 ServiceWorkerCache::ErrorType error, | 387 ServiceWorkerCache::ErrorType error, |
386 scoped_ptr<ServiceWorkerResponse> response, | 388 scoped_ptr<ServiceWorkerResponse> response, |
387 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 389 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
388 if (error != ServiceWorkerCache::ErrorTypeOK) { | 390 if (error != ServiceWorkerCache::ErrorTypeOK) { |
389 Send(ServiceWorkerMsg_CacheStorageMatchError( | 391 Send(new ServiceWorkerMsg_CacheStorageMatchError( |
390 request_id, CacheErrorToWebServiceWorkerCacheError(error))); | 392 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); |
391 return; | 393 return; |
392 } | 394 } |
393 | 395 |
394 if (blob_data_handle) | 396 if (blob_data_handle) |
395 StoreBlobDataHandle(blob_data_handle.Pass()); | 397 StoreBlobDataHandle(blob_data_handle.Pass()); |
396 | 398 |
397 Send(ServiceWorkerMsg_CacheStorageMatchSuccess(request_id, *response)); | 399 Send(new ServiceWorkerMsg_CacheStorageMatchSuccess(thread_id, request_id, |
400 *response)); | |
398 } | 401 } |
399 | 402 |
400 void ServiceWorkerCacheListener::OnCacheMatchCallback( | 403 void ServiceWorkerCacheListener::OnCacheMatchCallback( |
404 int thread_id, | |
401 int request_id, | 405 int request_id, |
402 const scoped_refptr<ServiceWorkerCache>& cache, | 406 const scoped_refptr<ServiceWorkerCache>& cache, |
403 ServiceWorkerCache::ErrorType error, | 407 ServiceWorkerCache::ErrorType error, |
404 scoped_ptr<ServiceWorkerResponse> response, | 408 scoped_ptr<ServiceWorkerResponse> response, |
405 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 409 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
406 if (error != ServiceWorkerCache::ErrorTypeOK) { | 410 if (error != ServiceWorkerCache::ErrorTypeOK) { |
407 Send(ServiceWorkerMsg_CacheMatchError( | 411 Send(new ServiceWorkerMsg_CacheMatchError( |
408 request_id, CacheErrorToWebServiceWorkerCacheError(error))); | 412 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); |
409 return; | 413 return; |
410 } | 414 } |
411 | 415 |
412 if (blob_data_handle) | 416 if (blob_data_handle) |
413 StoreBlobDataHandle(blob_data_handle.Pass()); | 417 StoreBlobDataHandle(blob_data_handle.Pass()); |
414 | 418 |
415 Send(ServiceWorkerMsg_CacheMatchSuccess(request_id, *response)); | 419 Send( |
420 new ServiceWorkerMsg_CacheMatchSuccess(thread_id, request_id, *response)); | |
416 } | 421 } |
417 | 422 |
418 void ServiceWorkerCacheListener::OnCacheKeysCallback( | 423 void ServiceWorkerCacheListener::OnCacheKeysCallback( |
424 int thread_id, | |
419 int request_id, | 425 int request_id, |
420 const scoped_refptr<ServiceWorkerCache>& cache, | 426 const scoped_refptr<ServiceWorkerCache>& cache, |
421 ServiceWorkerCache::ErrorType error, | 427 ServiceWorkerCache::ErrorType error, |
422 scoped_ptr<ServiceWorkerCache::Requests> requests) { | 428 scoped_ptr<ServiceWorkerCache::Requests> requests) { |
423 if (error != ServiceWorkerCache::ErrorTypeOK) { | 429 if (error != ServiceWorkerCache::ErrorTypeOK) { |
424 Send(ServiceWorkerMsg_CacheKeysError( | 430 Send(new ServiceWorkerMsg_CacheKeysError( |
425 request_id, CacheErrorToWebServiceWorkerCacheError(error))); | 431 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); |
426 return; | 432 return; |
427 } | 433 } |
428 | 434 |
429 ServiceWorkerCache::Requests out; | 435 ServiceWorkerCache::Requests out; |
430 | 436 |
431 for (ServiceWorkerCache::Requests::const_iterator it = requests->begin(); | 437 for (ServiceWorkerCache::Requests::const_iterator it = requests->begin(); |
432 it != requests->end(); | 438 it != requests->end(); |
433 ++it) { | 439 ++it) { |
434 ServiceWorkerFetchRequest request( | 440 ServiceWorkerFetchRequest request( |
435 it->url, it->method, it->headers, it->referrer, it->is_reload); | 441 it->url, it->method, it->headers, it->referrer, it->is_reload); |
436 out.push_back(request); | 442 out.push_back(request); |
437 } | 443 } |
438 | 444 |
439 Send(ServiceWorkerMsg_CacheKeysSuccess(request_id, out)); | 445 Send(new ServiceWorkerMsg_CacheKeysSuccess(thread_id, request_id, out)); |
440 } | 446 } |
441 | 447 |
442 void ServiceWorkerCacheListener::OnCacheDeleteCallback( | 448 void ServiceWorkerCacheListener::OnCacheDeleteCallback( |
449 int thread_id, | |
443 int request_id, | 450 int request_id, |
444 const scoped_refptr<ServiceWorkerCache>& cache, | 451 const scoped_refptr<ServiceWorkerCache>& cache, |
445 ServiceWorkerCache::ErrorType error) { | 452 ServiceWorkerCache::ErrorType error) { |
446 if (error != ServiceWorkerCache::ErrorTypeOK) { | 453 if (error != ServiceWorkerCache::ErrorTypeOK) { |
447 Send(ServiceWorkerMsg_CacheBatchError( | 454 Send(new ServiceWorkerMsg_CacheBatchError( |
448 request_id, CacheErrorToWebServiceWorkerCacheError(error))); | 455 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); |
449 return; | 456 return; |
450 } | 457 } |
451 | 458 |
452 Send(ServiceWorkerMsg_CacheBatchSuccess( | 459 Send(new ServiceWorkerMsg_CacheBatchSuccess( |
453 request_id, std::vector<ServiceWorkerResponse>())); | 460 thread_id, request_id, std::vector<ServiceWorkerResponse>())); |
454 } | 461 } |
455 | 462 |
456 void ServiceWorkerCacheListener::OnCachePutCallback( | 463 void ServiceWorkerCacheListener::OnCachePutCallback( |
464 int thread_id, | |
457 int request_id, | 465 int request_id, |
458 const scoped_refptr<ServiceWorkerCache>& cache, | 466 const scoped_refptr<ServiceWorkerCache>& cache, |
459 ServiceWorkerCache::ErrorType error, | 467 ServiceWorkerCache::ErrorType error, |
460 scoped_ptr<ServiceWorkerResponse> response, | 468 scoped_ptr<ServiceWorkerResponse> response, |
461 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 469 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
462 if (error != ServiceWorkerCache::ErrorTypeOK) { | 470 if (error != ServiceWorkerCache::ErrorTypeOK) { |
463 Send(ServiceWorkerMsg_CacheBatchError( | 471 Send(new ServiceWorkerMsg_CacheBatchError( |
464 request_id, CacheErrorToWebServiceWorkerCacheError(error))); | 472 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); |
465 return; | 473 return; |
466 } | 474 } |
467 | 475 |
468 if (blob_data_handle) | 476 if (blob_data_handle) |
469 StoreBlobDataHandle(blob_data_handle.Pass()); | 477 StoreBlobDataHandle(blob_data_handle.Pass()); |
470 | 478 |
471 std::vector<ServiceWorkerResponse> responses; | 479 std::vector<ServiceWorkerResponse> responses; |
472 responses.push_back(*response); | 480 responses.push_back(*response); |
473 Send(ServiceWorkerMsg_CacheBatchSuccess(request_id, responses)); | 481 Send( |
482 new ServiceWorkerMsg_CacheBatchSuccess(thread_id, request_id, responses)); | |
474 } | 483 } |
475 | 484 |
476 ServiceWorkerCacheListener::CacheID | 485 ServiceWorkerCacheListener::CacheID |
477 ServiceWorkerCacheListener::StoreCacheReference( | 486 ServiceWorkerCacheListener::StoreCacheReference( |
478 const scoped_refptr<ServiceWorkerCache>& cache) { | 487 const scoped_refptr<ServiceWorkerCache>& cache) { |
479 int cache_id = next_cache_id_++; | 488 int cache_id = next_cache_id_++; |
480 id_to_cache_map_[cache_id] = cache; | 489 id_to_cache_map_[cache_id] = cache; |
481 return cache_id; | 490 return cache_id; |
482 } | 491 } |
483 | 492 |
(...skipping 14 matching lines...) Expand all Loading... | |
498 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); | 507 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
499 if (it == blob_handle_store_.end()) | 508 if (it == blob_handle_store_.end()) |
500 return; | 509 return; |
501 DCHECK(!it->second.empty()); | 510 DCHECK(!it->second.empty()); |
502 it->second.pop_front(); | 511 it->second.pop_front(); |
503 if (it->second.empty()) | 512 if (it->second.empty()) |
504 blob_handle_store_.erase(it); | 513 blob_handle_store_.erase(it); |
505 } | 514 } |
506 | 515 |
507 } // namespace content | 516 } // namespace content |
OLD | NEW |