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

Side by Side Diff: content/browser/cache_storage/cache_storage_dispatcher_host.cc

Issue 1107293002: CacheStorage: Merge CacheStorageListener into CacheStorageDispatcherHost (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@merge_cache_listener_and_dispatcher
Patch Set: Created 5 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/cache_storage/cache_storage_dispatcher_host.h" 5 #include "content/browser/cache_storage/cache_storage_dispatcher_host.h"
6 6
7 #include "base/bind.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/trace_event/trace_event.h"
12 #include "content/browser/cache_storage/cache_storage_cache.h"
10 #include "content/browser/cache_storage/cache_storage_context_impl.h" 13 #include "content/browser/cache_storage/cache_storage_context_impl.h"
11 #include "content/browser/cache_storage/cache_storage_listener.h"
12 #include "content/browser/cache_storage/cache_storage_manager.h" 14 #include "content/browser/cache_storage/cache_storage_manager.h"
13 #include "content/common/cache_storage/cache_storage_messages.h" 15 #include "content/common/cache_storage/cache_storage_messages.h"
14 #include "content/public/browser/content_browser_client.h" 16 #include "content/public/browser/content_browser_client.h"
15 #include "storage/browser/blob/blob_data_handle.h" 17 #include "storage/browser/blob/blob_data_handle.h"
16 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h" 18 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h"
17 19
18 namespace content { 20 namespace content {
19 21
20 namespace { 22 namespace {
21 23
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 97
96 bool handled = true; 98 bool handled = true;
97 IPC_BEGIN_MESSAGE_MAP(CacheStorageDispatcherHost, message) 99 IPC_BEGIN_MESSAGE_MAP(CacheStorageDispatcherHost, message)
98 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageHas, OnCacheStorageHas) 100 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageHas, OnCacheStorageHas)
99 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageOpen, OnCacheStorageOpen) 101 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageOpen, OnCacheStorageOpen)
100 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageDelete, 102 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageDelete,
101 OnCacheStorageDelete) 103 OnCacheStorageDelete)
102 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageKeys, OnCacheStorageKeys) 104 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageKeys, OnCacheStorageKeys)
103 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageMatch, 105 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheStorageMatch,
104 OnCacheStorageMatch) 106 OnCacheStorageMatch)
107 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheMatch, OnCacheMatch)
108 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheMatchAll, OnCacheMatchAll)
109 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheKeys, OnCacheKeys)
110 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheBatch, OnCacheBatch)
111 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_CacheClosed, OnCacheClosed)
112 IPC_MESSAGE_HANDLER(CacheStorageHostMsg_BlobDataHandled, OnBlobDataHandled)
105 IPC_MESSAGE_UNHANDLED(handled = false) 113 IPC_MESSAGE_UNHANDLED(handled = false)
106 IPC_END_MESSAGE_MAP() 114 IPC_END_MESSAGE_MAP()
107 if (handled)
108 return handled;
109 115
110 DCHECK(cache_listener_);
111 handled = cache_listener_->OnMessageReceived(message);
112 if (!handled) 116 if (!handled)
113 BadMessageReceived(); 117 BadMessageReceived();
114 return handled; 118 return handled;
115 } 119 }
116 120
117 void CacheStorageDispatcherHost::CreateCacheListener( 121 void CacheStorageDispatcherHost::CreateCacheListener(
118 CacheStorageContextImpl* context) { 122 CacheStorageContextImpl* context) {
119 DCHECK_CURRENTLY_ON(BrowserThread::IO); 123 DCHECK_CURRENTLY_ON(BrowserThread::IO);
120 cache_listener_.reset(new CacheStorageListener(this, context));
121 context_ = context; 124 context_ = context;
122 } 125 }
123 126
124 void CacheStorageDispatcherHost::OnCacheStorageHas( 127 void CacheStorageDispatcherHost::OnCacheStorageHas(
125 int thread_id, 128 int thread_id,
126 int request_id, 129 int request_id,
127 const GURL& origin, 130 const GURL& origin,
128 const base::string16& cache_name) { 131 const base::string16& cache_name) {
129 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas"); 132 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas");
130 context_->cache_manager()->HasCache( 133 context_->cache_manager()->HasCache(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, 193 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback,
191 this, thread_id, request_id)); 194 this, thread_id, request_id));
192 return; 195 return;
193 } 196 }
194 context_->cache_manager()->MatchCache( 197 context_->cache_manager()->MatchCache(
195 origin, base::UTF16ToUTF8(match_params.cache_name), scoped_request.Pass(), 198 origin, base::UTF16ToUTF8(match_params.cache_name), scoped_request.Pass(),
196 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this, 199 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this,
197 thread_id, request_id)); 200 thread_id, request_id));
198 } 201 }
199 202
203 void CacheStorageDispatcherHost::OnCacheMatch(
204 int thread_id,
205 int request_id,
206 int cache_id,
207 const ServiceWorkerFetchRequest& request,
208 const CacheStorageCacheQueryParams& match_params) {
209 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id);
210 if (it == id_to_cache_map_.end()) {
211 Send(new CacheStorageMsg_CacheMatchError(
212 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound));
213 return;
214 }
215
216 scoped_refptr<CacheStorageCache> cache = it->second;
217 scoped_ptr<ServiceWorkerFetchRequest> scoped_request(
218 new ServiceWorkerFetchRequest(request.url, request.method,
219 request.headers, request.referrer,
220 request.is_reload));
221 cache->Match(scoped_request.Pass(),
222 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback,
223 this, thread_id, request_id, cache));
224 }
225
226 void CacheStorageDispatcherHost::OnCacheMatchAll(
227 int thread_id,
228 int request_id,
229 int cache_id,
230 const ServiceWorkerFetchRequest& request,
231 const CacheStorageCacheQueryParams& match_params) {
232 // TODO(gavinp,jkarlin): Implement this method.
233 Send(new CacheStorageMsg_CacheMatchAllError(
234 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotImplemented));
235 }
236
237 void CacheStorageDispatcherHost::OnCacheKeys(
238 int thread_id,
239 int request_id,
240 int cache_id,
241 const ServiceWorkerFetchRequest& request,
242 const CacheStorageCacheQueryParams& match_params) {
243 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id);
244 if (it == id_to_cache_map_.end()) {
245 Send(new CacheStorageMsg_CacheKeysError(
246 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound));
247 return;
248 }
249
250 scoped_refptr<CacheStorageCache> cache = it->second;
251
252 cache->Keys(base::Bind(&CacheStorageDispatcherHost::OnCacheKeysCallback, this,
253 thread_id, request_id, cache));
254 }
255
256 void CacheStorageDispatcherHost::OnCacheBatch(
257 int thread_id,
258 int request_id,
259 int cache_id,
260 const std::vector<CacheStorageBatchOperation>& operations) {
261 if (operations.size() != 1u) {
262 Send(new CacheStorageMsg_CacheBatchError(
263 thread_id, request_id,
264 blink::WebServiceWorkerCacheErrorNotImplemented));
265 return;
266 }
267
268 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id);
269 if (it == id_to_cache_map_.end()) {
270 Send(new CacheStorageMsg_CacheBatchError(
271 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound));
272 return;
273 }
274
275 const CacheStorageBatchOperation& operation = operations[0];
276
277 scoped_refptr<CacheStorageCache> cache = it->second;
278 scoped_ptr<ServiceWorkerFetchRequest> scoped_request(
279 new ServiceWorkerFetchRequest(
280 operation.request.url, operation.request.method,
281 operation.request.headers, operation.request.referrer,
282 operation.request.is_reload));
283
284 if (operation.operation_type == CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE) {
285 cache->Delete(scoped_request.Pass(),
286 base::Bind(&CacheStorageDispatcherHost::OnCacheDeleteCallback,
287 this, thread_id, request_id, cache));
288 return;
289 }
290
291 if (operation.operation_type == CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT) {
292 // We don't support streaming for cache.
293 DCHECK(operation.response.stream_url.is_empty());
294 scoped_ptr<ServiceWorkerResponse> scoped_response(new ServiceWorkerResponse(
295 operation.response.url, operation.response.status_code,
296 operation.response.status_text, operation.response.response_type,
297 operation.response.headers, operation.response.blob_uuid,
298 operation.response.blob_size, operation.response.stream_url));
299 cache->Put(scoped_request.Pass(), scoped_response.Pass(),
300 base::Bind(&CacheStorageDispatcherHost::OnCachePutCallback, this,
301 thread_id, request_id, cache));
302
303 return;
304 }
305
306 Send(new CacheStorageMsg_CacheBatchError(
307 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotImplemented));
308 }
309
310 void CacheStorageDispatcherHost::OnCacheClosed(int cache_id) {
311 DropCacheReference(cache_id);
312 }
313
314 void CacheStorageDispatcherHost::OnBlobDataHandled(const std::string& uuid) {
315 DropBlobDataHandle(uuid);
316 }
317
200 void CacheStorageDispatcherHost::OnCacheStorageHasCallback( 318 void CacheStorageDispatcherHost::OnCacheStorageHasCallback(
201 int thread_id, 319 int thread_id,
202 int request_id, 320 int request_id,
203 bool has_cache, 321 bool has_cache,
204 CacheStorage::CacheStorageError error) { 322 CacheStorage::CacheStorageError error) {
205 if (error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { 323 if (error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) {
206 Send(new CacheStorageMsg_CacheStorageHasError( 324 Send(new CacheStorageMsg_CacheStorageHasError(
207 thread_id, request_id, ToWebServiceWorkerCacheError(error))); 325 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
208 return; 326 return;
209 } 327 }
210 if (!has_cache) { 328 if (!has_cache) {
211 Send(new CacheStorageMsg_CacheStorageHasError( 329 Send(new CacheStorageMsg_CacheStorageHasError(
212 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); 330 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound));
213 return; 331 return;
214 } 332 }
215 Send(new CacheStorageMsg_CacheStorageHasSuccess(thread_id, request_id)); 333 Send(new CacheStorageMsg_CacheStorageHasSuccess(thread_id, request_id));
216 } 334 }
217 335
218 void CacheStorageDispatcherHost::OnCacheStorageOpenCallback( 336 void CacheStorageDispatcherHost::OnCacheStorageOpenCallback(
219 int thread_id, 337 int thread_id,
220 int request_id, 338 int request_id,
221 const scoped_refptr<CacheStorageCache>& cache, 339 const scoped_refptr<CacheStorageCache>& cache,
222 CacheStorage::CacheStorageError error) { 340 CacheStorage::CacheStorageError error) {
223 if (error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { 341 if (error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) {
224 Send(new CacheStorageMsg_CacheStorageOpenError( 342 Send(new CacheStorageMsg_CacheStorageOpenError(
225 thread_id, request_id, ToWebServiceWorkerCacheError(error))); 343 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
226 return; 344 return;
227 } 345 }
228 CacheStorageListener::CacheID cache_id = 346 CacheID cache_id = StoreCacheReference(cache);
229 cache_listener_->StoreCacheReference(cache);
230 Send(new CacheStorageMsg_CacheStorageOpenSuccess(thread_id, request_id, 347 Send(new CacheStorageMsg_CacheStorageOpenSuccess(thread_id, request_id,
231 cache_id)); 348 cache_id));
232 } 349 }
233 350
234 void CacheStorageDispatcherHost::OnCacheStorageDeleteCallback( 351 void CacheStorageDispatcherHost::OnCacheStorageDeleteCallback(
235 int thread_id, 352 int thread_id,
236 int request_id, 353 int request_id,
237 bool deleted, 354 bool deleted,
238 CacheStorage::CacheStorageError error) { 355 CacheStorage::CacheStorageError error) {
239 if (!deleted || error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { 356 if (!deleted || error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) {
(...skipping 29 matching lines...) Expand all
269 CacheStorageCache::ErrorType error, 386 CacheStorageCache::ErrorType error,
270 scoped_ptr<ServiceWorkerResponse> response, 387 scoped_ptr<ServiceWorkerResponse> response,
271 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { 388 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
272 if (error != CacheStorageCache::ERROR_TYPE_OK) { 389 if (error != CacheStorageCache::ERROR_TYPE_OK) {
273 Send(new CacheStorageMsg_CacheStorageMatchError( 390 Send(new CacheStorageMsg_CacheStorageMatchError(
274 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); 391 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error)));
275 return; 392 return;
276 } 393 }
277 394
278 if (blob_data_handle) 395 if (blob_data_handle)
279 cache_listener_->StoreBlobDataHandle(blob_data_handle.Pass()); 396 StoreBlobDataHandle(blob_data_handle.Pass());
280 397
281 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id, 398 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id,
282 *response)); 399 *response));
283 } 400 }
284 401
402 void CacheStorageDispatcherHost::OnCacheMatchCallback(
403 int thread_id,
404 int request_id,
405 const scoped_refptr<CacheStorageCache>& cache,
406 CacheStorageCache::ErrorType error,
407 scoped_ptr<ServiceWorkerResponse> response,
408 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
409 if (error != CacheStorageCache::ERROR_TYPE_OK) {
410 Send(new CacheStorageMsg_CacheMatchError(
411 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error)));
412 return;
413 }
414
415 if (blob_data_handle)
416 StoreBlobDataHandle(blob_data_handle.Pass());
417
418 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response));
419 }
420
421 void CacheStorageDispatcherHost::OnCacheKeysCallback(
422 int thread_id,
423 int request_id,
424 const scoped_refptr<CacheStorageCache>& cache,
425 CacheStorageCache::ErrorType error,
426 scoped_ptr<CacheStorageCache::Requests> requests) {
427 if (error != CacheStorageCache::ERROR_TYPE_OK) {
428 Send(new CacheStorageMsg_CacheKeysError(
429 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error)));
430 return;
431 }
432
433 CacheStorageCache::Requests out;
434
435 for (CacheStorageCache::Requests::const_iterator it = requests->begin();
436 it != requests->end(); ++it) {
437 ServiceWorkerFetchRequest request(it->url, it->method, it->headers,
438 it->referrer, it->is_reload);
439 out.push_back(request);
440 }
441
442 Send(new CacheStorageMsg_CacheKeysSuccess(thread_id, request_id, out));
443 }
444
445 void CacheStorageDispatcherHost::OnCacheDeleteCallback(
446 int thread_id,
447 int request_id,
448 const scoped_refptr<CacheStorageCache>& cache,
449 CacheStorageCache::ErrorType error) {
450 if (error != CacheStorageCache::ERROR_TYPE_OK) {
451 Send(new CacheStorageMsg_CacheBatchError(
452 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error)));
453 return;
454 }
455
456 Send(new CacheStorageMsg_CacheBatchSuccess(
457 thread_id, request_id, std::vector<ServiceWorkerResponse>()));
458 }
459
460 void CacheStorageDispatcherHost::OnCachePutCallback(
461 int thread_id,
462 int request_id,
463 const scoped_refptr<CacheStorageCache>& cache,
464 CacheStorageCache::ErrorType error,
465 scoped_ptr<ServiceWorkerResponse> response,
466 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
467 if (error != CacheStorageCache::ERROR_TYPE_OK) {
468 Send(new CacheStorageMsg_CacheBatchError(
469 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error)));
470 return;
471 }
472
473 if (blob_data_handle)
474 StoreBlobDataHandle(blob_data_handle.Pass());
475
476 std::vector<ServiceWorkerResponse> responses;
477 responses.push_back(*response);
478 Send(new CacheStorageMsg_CacheBatchSuccess(thread_id, request_id, responses));
479 }
480
481 CacheStorageDispatcherHost::CacheID
482 CacheStorageDispatcherHost::StoreCacheReference(
483 const scoped_refptr<CacheStorageCache>& cache) {
484 int cache_id = next_cache_id_++;
485 id_to_cache_map_[cache_id] = cache;
486 return cache_id;
487 }
488
489 void CacheStorageDispatcherHost::DropCacheReference(CacheID cache_id) {
490 id_to_cache_map_.erase(cache_id);
491 }
492
493 void CacheStorageDispatcherHost::StoreBlobDataHandle(
494 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
495 DCHECK(blob_data_handle);
496 std::pair<UUIDToBlobDataHandleList::iterator, bool> rv =
497 blob_handle_store_.insert(std::make_pair(
498 blob_data_handle->uuid(), std::list<storage::BlobDataHandle>()));
499 rv.first->second.push_front(storage::BlobDataHandle(*blob_data_handle));
500 }
501
502 void CacheStorageDispatcherHost::DropBlobDataHandle(std::string uuid) {
503 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid);
504 if (it == blob_handle_store_.end())
505 return;
506 DCHECK(!it->second.empty());
507 it->second.pop_front();
508 if (it->second.empty())
509 blob_handle_store_.erase(it);
510 }
511
285 } // namespace content 512 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_dispatcher_host.h ('k') | content/browser/cache_storage/cache_storage_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698