OLD | NEW |
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/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback, | 196 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback, |
197 this, thread_id, request_id, cache)); | 197 this, thread_id, request_id, cache)); |
198 } | 198 } |
199 | 199 |
200 void CacheStorageDispatcherHost::OnCacheMatchAll( | 200 void CacheStorageDispatcherHost::OnCacheMatchAll( |
201 int thread_id, | 201 int thread_id, |
202 int request_id, | 202 int request_id, |
203 int cache_id, | 203 int cache_id, |
204 const ServiceWorkerFetchRequest& request, | 204 const ServiceWorkerFetchRequest& request, |
205 const CacheStorageCacheQueryParams& match_params) { | 205 const CacheStorageCacheQueryParams& match_params) { |
206 // TODO(gavinp,jkarlin): Implement this method. | 206 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
207 Send(new CacheStorageMsg_CacheMatchAllError( | 207 if (it == id_to_cache_map_.end()) { |
208 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotImplemented)); | 208 Send(new CacheStorageMsg_CacheMatchError( |
| 209 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
| 210 return; |
| 211 } |
| 212 |
| 213 scoped_refptr<CacheStorageCache> cache = it->second; |
| 214 if (request.url.is_empty()) { |
| 215 cache->MatchAll( |
| 216 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this, |
| 217 thread_id, request_id, cache)); |
| 218 return; |
| 219 } |
| 220 |
| 221 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( |
| 222 new ServiceWorkerFetchRequest(request.url, request.method, |
| 223 request.headers, request.referrer, |
| 224 request.is_reload)); |
| 225 cache->Match( |
| 226 scoped_request.Pass(), |
| 227 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter, |
| 228 this, thread_id, request_id, cache)); |
209 } | 229 } |
210 | 230 |
211 void CacheStorageDispatcherHost::OnCacheKeys( | 231 void CacheStorageDispatcherHost::OnCacheKeys( |
212 int thread_id, | 232 int thread_id, |
213 int request_id, | 233 int request_id, |
214 int cache_id, | 234 int cache_id, |
215 const ServiceWorkerFetchRequest& request, | 235 const ServiceWorkerFetchRequest& request, |
216 const CacheStorageCacheQueryParams& match_params) { | 236 const CacheStorageCacheQueryParams& match_params) { |
217 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); | 237 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
218 if (it == id_to_cache_map_.end()) { | 238 if (it == id_to_cache_map_.end()) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 CacheStorageError error, | 343 CacheStorageError error, |
324 scoped_ptr<ServiceWorkerResponse> response, | 344 scoped_ptr<ServiceWorkerResponse> response, |
325 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 345 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
326 if (error != CACHE_STORAGE_OK) { | 346 if (error != CACHE_STORAGE_OK) { |
327 Send(new CacheStorageMsg_CacheStorageMatchError( | 347 Send(new CacheStorageMsg_CacheStorageMatchError( |
328 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 348 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
329 return; | 349 return; |
330 } | 350 } |
331 | 351 |
332 if (blob_data_handle) | 352 if (blob_data_handle) |
333 StoreBlobDataHandle(blob_data_handle.Pass()); | 353 StoreBlobDataHandle(*blob_data_handle); |
334 | 354 |
335 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id, | 355 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id, |
336 *response)); | 356 *response)); |
337 } | 357 } |
338 | 358 |
339 void CacheStorageDispatcherHost::OnCacheMatchCallback( | 359 void CacheStorageDispatcherHost::OnCacheMatchCallback( |
340 int thread_id, | 360 int thread_id, |
341 int request_id, | 361 int request_id, |
342 const scoped_refptr<CacheStorageCache>& cache, | 362 const scoped_refptr<CacheStorageCache>& cache, |
343 CacheStorageError error, | 363 CacheStorageError error, |
344 scoped_ptr<ServiceWorkerResponse> response, | 364 scoped_ptr<ServiceWorkerResponse> response, |
345 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 365 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
346 if (error != CACHE_STORAGE_OK) { | 366 if (error != CACHE_STORAGE_OK) { |
347 Send(new CacheStorageMsg_CacheMatchError( | 367 Send(new CacheStorageMsg_CacheMatchError( |
348 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 368 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
349 return; | 369 return; |
350 } | 370 } |
351 | 371 |
352 if (blob_data_handle) | 372 if (blob_data_handle) |
353 StoreBlobDataHandle(blob_data_handle.Pass()); | 373 StoreBlobDataHandle(*blob_data_handle); |
354 | 374 |
355 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response)); | 375 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response)); |
356 } | 376 } |
357 | 377 |
| 378 void CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter( |
| 379 int thread_id, |
| 380 int request_id, |
| 381 const scoped_refptr<CacheStorageCache>& cache, |
| 382 CacheStorageError error, |
| 383 scoped_ptr<ServiceWorkerResponse> response, |
| 384 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
| 385 scoped_ptr<CacheStorageCache::Responses> responses( |
| 386 new CacheStorageCache::Responses); |
| 387 scoped_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles( |
| 388 new CacheStorageCache::BlobDataHandles); |
| 389 if (error == CACHE_STORAGE_OK) { |
| 390 DCHECK(response); |
| 391 responses->push_back(*response); |
| 392 if (blob_data_handle) |
| 393 blob_data_handles->push_back(*blob_data_handle); |
| 394 } |
| 395 OnCacheMatchAllCallback(thread_id, request_id, cache, error, responses.Pass(), |
| 396 blob_data_handles.Pass()); |
| 397 } |
| 398 |
| 399 void CacheStorageDispatcherHost::OnCacheMatchAllCallback( |
| 400 int thread_id, |
| 401 int request_id, |
| 402 const scoped_refptr<CacheStorageCache>& cache, |
| 403 CacheStorageError error, |
| 404 scoped_ptr<CacheStorageCache::Responses> responses, |
| 405 scoped_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles) { |
| 406 if (error != CACHE_STORAGE_OK && error != CACHE_STORAGE_ERROR_NOT_FOUND) { |
| 407 Send(new CacheStorageMsg_CacheMatchAllError( |
| 408 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 409 return; |
| 410 } |
| 411 |
| 412 for (const storage::BlobDataHandle& handle : *blob_data_handles) |
| 413 StoreBlobDataHandle(handle); |
| 414 |
| 415 Send(new CacheStorageMsg_CacheMatchAllSuccess(thread_id, request_id, |
| 416 *responses)); |
| 417 } |
| 418 |
358 void CacheStorageDispatcherHost::OnCacheKeysCallback( | 419 void CacheStorageDispatcherHost::OnCacheKeysCallback( |
359 int thread_id, | 420 int thread_id, |
360 int request_id, | 421 int request_id, |
361 const scoped_refptr<CacheStorageCache>& cache, | 422 const scoped_refptr<CacheStorageCache>& cache, |
362 CacheStorageError error, | 423 CacheStorageError error, |
363 scoped_ptr<CacheStorageCache::Requests> requests) { | 424 scoped_ptr<CacheStorageCache::Requests> requests) { |
364 if (error != CACHE_STORAGE_OK) { | 425 if (error != CACHE_STORAGE_OK) { |
365 Send(new CacheStorageMsg_CacheKeysError( | 426 Send(new CacheStorageMsg_CacheKeysError( |
366 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 427 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
367 return; | 428 return; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 int cache_id = next_cache_id_++; | 460 int cache_id = next_cache_id_++; |
400 id_to_cache_map_[cache_id] = cache; | 461 id_to_cache_map_[cache_id] = cache; |
401 return cache_id; | 462 return cache_id; |
402 } | 463 } |
403 | 464 |
404 void CacheStorageDispatcherHost::DropCacheReference(CacheID cache_id) { | 465 void CacheStorageDispatcherHost::DropCacheReference(CacheID cache_id) { |
405 id_to_cache_map_.erase(cache_id); | 466 id_to_cache_map_.erase(cache_id); |
406 } | 467 } |
407 | 468 |
408 void CacheStorageDispatcherHost::StoreBlobDataHandle( | 469 void CacheStorageDispatcherHost::StoreBlobDataHandle( |
409 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 470 const storage::BlobDataHandle& blob_data_handle) { |
410 DCHECK(blob_data_handle); | |
411 std::pair<UUIDToBlobDataHandleList::iterator, bool> rv = | 471 std::pair<UUIDToBlobDataHandleList::iterator, bool> rv = |
412 blob_handle_store_.insert(std::make_pair( | 472 blob_handle_store_.insert(std::make_pair( |
413 blob_data_handle->uuid(), std::list<storage::BlobDataHandle>())); | 473 blob_data_handle.uuid(), std::list<storage::BlobDataHandle>())); |
414 rv.first->second.push_front(storage::BlobDataHandle(*blob_data_handle)); | 474 rv.first->second.push_front(storage::BlobDataHandle(blob_data_handle)); |
415 } | 475 } |
416 | 476 |
417 void CacheStorageDispatcherHost::DropBlobDataHandle(std::string uuid) { | 477 void CacheStorageDispatcherHost::DropBlobDataHandle(const std::string& uuid) { |
418 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); | 478 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
419 if (it == blob_handle_store_.end()) | 479 if (it == blob_handle_store_.end()) |
420 return; | 480 return; |
421 DCHECK(!it->second.empty()); | 481 DCHECK(!it->second.empty()); |
422 it->second.pop_front(); | 482 it->second.pop_front(); |
423 if (it->second.empty()) | 483 if (it->second.empty()) |
424 blob_handle_store_.erase(it); | 484 blob_handle_store_.erase(it); |
425 } | 485 } |
426 | 486 |
427 } // namespace content | 487 } // namespace content |
OLD | NEW |