| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 Send(new CacheStorageMsg_CacheMatchError( | 220 Send(new CacheStorageMsg_CacheMatchError( |
| 221 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 221 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 | 224 |
| 225 scoped_refptr<CacheStorageCache> cache = it->second; | 225 scoped_refptr<CacheStorageCache> cache = it->second; |
| 226 std::unique_ptr<ServiceWorkerFetchRequest> scoped_request( | 226 std::unique_ptr<ServiceWorkerFetchRequest> scoped_request( |
| 227 new ServiceWorkerFetchRequest(request.url, request.method, | 227 new ServiceWorkerFetchRequest(request.url, request.method, |
| 228 request.headers, request.referrer, | 228 request.headers, request.referrer, |
| 229 request.is_reload)); | 229 request.is_reload)); |
| 230 cache->Match(std::move(scoped_request), | 230 |
| 231 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback, | 231 cache->Match( |
| 232 this, thread_id, request_id, cache)); | 232 std::move(scoped_request), |
| 233 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback, this, |
| 234 thread_id, request_id, StoreCacheReference(cache))); |
| 233 } | 235 } |
| 234 | 236 |
| 235 void CacheStorageDispatcherHost::OnCacheMatchAll( | 237 void CacheStorageDispatcherHost::OnCacheMatchAll( |
| 236 int thread_id, | 238 int thread_id, |
| 237 int request_id, | 239 int request_id, |
| 238 int cache_id, | 240 int cache_id, |
| 239 const ServiceWorkerFetchRequest& request, | 241 const ServiceWorkerFetchRequest& request, |
| 240 const CacheStorageCacheQueryParams& match_params) { | 242 const CacheStorageCacheQueryParams& match_params) { |
| 241 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); | 243 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
| 242 if (it == id_to_cache_map_.end()) { | 244 if (it == id_to_cache_map_.end()) { |
| 243 Send(new CacheStorageMsg_CacheMatchError( | 245 Send(new CacheStorageMsg_CacheMatchError( |
| 244 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 246 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
| 245 return; | 247 return; |
| 246 } | 248 } |
| 247 | 249 |
| 248 scoped_refptr<CacheStorageCache> cache = it->second; | 250 scoped_refptr<CacheStorageCache> cache = it->second; |
| 249 if (request.url.is_empty()) { | 251 if (request.url.is_empty()) { |
| 250 cache->MatchAll( | 252 cache->MatchAll( |
| 251 std::unique_ptr<ServiceWorkerFetchRequest>(), match_params, | 253 std::unique_ptr<ServiceWorkerFetchRequest>(), match_params, |
| 252 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this, | 254 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this, |
| 253 thread_id, request_id, cache)); | 255 thread_id, request_id, StoreCacheReference(cache))); |
| 254 return; | 256 return; |
| 255 } | 257 } |
| 256 | 258 |
| 257 std::unique_ptr<ServiceWorkerFetchRequest> scoped_request( | 259 std::unique_ptr<ServiceWorkerFetchRequest> scoped_request( |
| 258 new ServiceWorkerFetchRequest(request.url, request.method, | 260 new ServiceWorkerFetchRequest(request.url, request.method, |
| 259 request.headers, request.referrer, | 261 request.headers, request.referrer, |
| 260 request.is_reload)); | 262 request.is_reload)); |
| 261 if (match_params.ignore_search) { | 263 if (match_params.ignore_search) { |
| 262 cache->MatchAll( | 264 cache->MatchAll( |
| 263 std::move(scoped_request), match_params, | 265 std::move(scoped_request), match_params, |
| 264 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this, | 266 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this, |
| 265 thread_id, request_id, cache)); | 267 thread_id, request_id, StoreCacheReference(cache))); |
| 266 return; | 268 return; |
| 267 } | 269 } |
| 268 cache->Match( | 270 cache->Match( |
| 269 std::move(scoped_request), | 271 std::move(scoped_request), |
| 270 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter, | 272 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter, |
| 271 this, thread_id, request_id, cache)); | 273 this, thread_id, request_id, StoreCacheReference(cache))); |
| 272 } | 274 } |
| 273 | 275 |
| 274 void CacheStorageDispatcherHost::OnCacheKeys( | 276 void CacheStorageDispatcherHost::OnCacheKeys( |
| 275 int thread_id, | 277 int thread_id, |
| 276 int request_id, | 278 int request_id, |
| 277 int cache_id, | 279 int cache_id, |
| 278 const ServiceWorkerFetchRequest& request, | 280 const ServiceWorkerFetchRequest& request, |
| 279 const CacheStorageCacheQueryParams& match_params) { | 281 const CacheStorageCacheQueryParams& match_params) { |
| 280 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); | 282 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
| 281 if (it == id_to_cache_map_.end()) { | 283 if (it == id_to_cache_map_.end()) { |
| 282 Send(new CacheStorageMsg_CacheKeysError( | 284 Send(new CacheStorageMsg_CacheKeysError( |
| 283 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 285 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
| 284 return; | 286 return; |
| 285 } | 287 } |
| 286 | 288 |
| 287 scoped_refptr<CacheStorageCache> cache = it->second; | 289 scoped_refptr<CacheStorageCache> cache = it->second; |
| 288 | 290 |
| 289 cache->Keys(base::Bind(&CacheStorageDispatcherHost::OnCacheKeysCallback, this, | 291 cache->Keys(base::Bind(&CacheStorageDispatcherHost::OnCacheKeysCallback, this, |
| 290 thread_id, request_id, cache)); | 292 thread_id, request_id, StoreCacheReference(cache))); |
| 291 } | 293 } |
| 292 | 294 |
| 293 void CacheStorageDispatcherHost::OnCacheBatch( | 295 void CacheStorageDispatcherHost::OnCacheBatch( |
| 294 int thread_id, | 296 int thread_id, |
| 295 int request_id, | 297 int request_id, |
| 296 int cache_id, | 298 int cache_id, |
| 297 const std::vector<CacheStorageBatchOperation>& operations) { | 299 const std::vector<CacheStorageBatchOperation>& operations) { |
| 298 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); | 300 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
| 299 if (it == id_to_cache_map_.end()) { | 301 if (it == id_to_cache_map_.end()) { |
| 300 Send(new CacheStorageMsg_CacheBatchError( | 302 Send(new CacheStorageMsg_CacheBatchError( |
| 301 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 303 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
| 302 return; | 304 return; |
| 303 } | 305 } |
| 304 scoped_refptr<CacheStorageCache> cache = it->second; | 306 scoped_refptr<CacheStorageCache> cache = it->second; |
| 305 cache->BatchOperation( | 307 cache->BatchOperation( |
| 306 operations, base::Bind(&CacheStorageDispatcherHost::OnCacheBatchCallback, | 308 operations, |
| 307 this, thread_id, request_id, cache)); | 309 base::Bind(&CacheStorageDispatcherHost::OnCacheBatchCallback, this, |
| 310 thread_id, request_id, StoreCacheReference(cache))); |
| 308 } | 311 } |
| 309 | 312 |
| 310 void CacheStorageDispatcherHost::OnCacheClosed(int cache_id) { | 313 void CacheStorageDispatcherHost::OnCacheClosed(int cache_id) { |
| 311 DropCacheReference(cache_id); | 314 DropCacheReference(cache_id); |
| 312 } | 315 } |
| 313 | 316 |
| 314 void CacheStorageDispatcherHost::OnBlobDataHandled(const std::string& uuid) { | 317 void CacheStorageDispatcherHost::OnBlobDataHandled(const std::string& uuid) { |
| 315 DropBlobDataHandle(uuid); | 318 DropBlobDataHandle(uuid); |
| 316 } | 319 } |
| 317 | 320 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 if (blob_data_handle) | 398 if (blob_data_handle) |
| 396 StoreBlobDataHandle(*blob_data_handle); | 399 StoreBlobDataHandle(*blob_data_handle); |
| 397 | 400 |
| 398 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id, | 401 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id, |
| 399 *response)); | 402 *response)); |
| 400 } | 403 } |
| 401 | 404 |
| 402 void CacheStorageDispatcherHost::OnCacheMatchCallback( | 405 void CacheStorageDispatcherHost::OnCacheMatchCallback( |
| 403 int thread_id, | 406 int thread_id, |
| 404 int request_id, | 407 int request_id, |
| 405 scoped_refptr<CacheStorageCache> cache, | 408 CacheID cache_id, |
| 406 CacheStorageError error, | 409 CacheStorageError error, |
| 407 std::unique_ptr<ServiceWorkerResponse> response, | 410 std::unique_ptr<ServiceWorkerResponse> response, |
| 408 std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { | 411 std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { |
| 412 DropCacheReference(cache_id); |
| 409 if (error != CACHE_STORAGE_OK) { | 413 if (error != CACHE_STORAGE_OK) { |
| 410 Send(new CacheStorageMsg_CacheMatchError( | 414 Send(new CacheStorageMsg_CacheMatchError( |
| 411 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 415 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 412 return; | 416 return; |
| 413 } | 417 } |
| 414 | 418 |
| 415 if (blob_data_handle) | 419 if (blob_data_handle) |
| 416 StoreBlobDataHandle(*blob_data_handle); | 420 StoreBlobDataHandle(*blob_data_handle); |
| 417 | 421 |
| 418 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response)); | 422 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response)); |
| 419 } | 423 } |
| 420 | 424 |
| 421 void CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter( | 425 void CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter( |
| 422 int thread_id, | 426 int thread_id, |
| 423 int request_id, | 427 int request_id, |
| 424 scoped_refptr<CacheStorageCache> cache, | 428 CacheID cache_id, |
| 425 CacheStorageError error, | 429 CacheStorageError error, |
| 426 std::unique_ptr<ServiceWorkerResponse> response, | 430 std::unique_ptr<ServiceWorkerResponse> response, |
| 427 std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { | 431 std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { |
| 428 std::unique_ptr<CacheStorageCache::Responses> responses( | 432 std::unique_ptr<CacheStorageCache::Responses> responses( |
| 429 new CacheStorageCache::Responses); | 433 new CacheStorageCache::Responses); |
| 430 std::unique_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles( | 434 std::unique_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles( |
| 431 new CacheStorageCache::BlobDataHandles); | 435 new CacheStorageCache::BlobDataHandles); |
| 432 if (error == CACHE_STORAGE_OK) { | 436 if (error == CACHE_STORAGE_OK) { |
| 433 DCHECK(response); | 437 DCHECK(response); |
| 434 responses->push_back(*response); | 438 responses->push_back(*response); |
| 435 if (blob_data_handle) | 439 if (blob_data_handle) |
| 436 blob_data_handles->push_back(*blob_data_handle); | 440 blob_data_handles->push_back(*blob_data_handle); |
| 437 } | 441 } |
| 438 OnCacheMatchAllCallback(thread_id, request_id, std::move(cache), error, | 442 OnCacheMatchAllCallback(thread_id, request_id, cache_id, error, |
| 439 std::move(responses), std::move(blob_data_handles)); | 443 std::move(responses), std::move(blob_data_handles)); |
| 440 } | 444 } |
| 441 | 445 |
| 442 void CacheStorageDispatcherHost::OnCacheMatchAllCallback( | 446 void CacheStorageDispatcherHost::OnCacheMatchAllCallback( |
| 443 int thread_id, | 447 int thread_id, |
| 444 int request_id, | 448 int request_id, |
| 445 scoped_refptr<CacheStorageCache> cache, | 449 CacheID cache_id, |
| 446 CacheStorageError error, | 450 CacheStorageError error, |
| 447 std::unique_ptr<CacheStorageCache::Responses> responses, | 451 std::unique_ptr<CacheStorageCache::Responses> responses, |
| 448 std::unique_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles) { | 452 std::unique_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles) { |
| 453 DropCacheReference(cache_id); |
| 449 if (error != CACHE_STORAGE_OK && error != CACHE_STORAGE_ERROR_NOT_FOUND) { | 454 if (error != CACHE_STORAGE_OK && error != CACHE_STORAGE_ERROR_NOT_FOUND) { |
| 450 Send(new CacheStorageMsg_CacheMatchAllError( | 455 Send(new CacheStorageMsg_CacheMatchAllError( |
| 451 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 456 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 452 return; | 457 return; |
| 453 } | 458 } |
| 454 | 459 |
| 455 for (const storage::BlobDataHandle& handle : *blob_data_handles) | 460 for (const storage::BlobDataHandle& handle : *blob_data_handles) |
| 456 StoreBlobDataHandle(handle); | 461 StoreBlobDataHandle(handle); |
| 457 | 462 |
| 458 Send(new CacheStorageMsg_CacheMatchAllSuccess(thread_id, request_id, | 463 Send(new CacheStorageMsg_CacheMatchAllSuccess(thread_id, request_id, |
| 459 *responses)); | 464 *responses)); |
| 460 } | 465 } |
| 461 | 466 |
| 462 void CacheStorageDispatcherHost::OnCacheKeysCallback( | 467 void CacheStorageDispatcherHost::OnCacheKeysCallback( |
| 463 int thread_id, | 468 int thread_id, |
| 464 int request_id, | 469 int request_id, |
| 465 scoped_refptr<CacheStorageCache> cache, | 470 CacheID cache_id, |
| 466 CacheStorageError error, | 471 CacheStorageError error, |
| 467 std::unique_ptr<CacheStorageCache::Requests> requests) { | 472 std::unique_ptr<CacheStorageCache::Requests> requests) { |
| 473 DropCacheReference(cache_id); |
| 468 if (error != CACHE_STORAGE_OK) { | 474 if (error != CACHE_STORAGE_OK) { |
| 469 Send(new CacheStorageMsg_CacheKeysError( | 475 Send(new CacheStorageMsg_CacheKeysError( |
| 470 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 476 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 471 return; | 477 return; |
| 472 } | 478 } |
| 473 | 479 |
| 474 CacheStorageCache::Requests out; | 480 CacheStorageCache::Requests out; |
| 475 | 481 |
| 476 for (CacheStorageCache::Requests::const_iterator it = requests->begin(); | 482 for (CacheStorageCache::Requests::const_iterator it = requests->begin(); |
| 477 it != requests->end(); ++it) { | 483 it != requests->end(); ++it) { |
| 478 ServiceWorkerFetchRequest request(it->url, it->method, it->headers, | 484 ServiceWorkerFetchRequest request(it->url, it->method, it->headers, |
| 479 it->referrer, it->is_reload); | 485 it->referrer, it->is_reload); |
| 480 out.push_back(request); | 486 out.push_back(request); |
| 481 } | 487 } |
| 482 | 488 |
| 483 Send(new CacheStorageMsg_CacheKeysSuccess(thread_id, request_id, out)); | 489 Send(new CacheStorageMsg_CacheKeysSuccess(thread_id, request_id, out)); |
| 484 } | 490 } |
| 485 | 491 |
| 486 void CacheStorageDispatcherHost::OnCacheBatchCallback( | 492 void CacheStorageDispatcherHost::OnCacheBatchCallback(int thread_id, |
| 487 int thread_id, | 493 int request_id, |
| 488 int request_id, | 494 CacheID cache_id, |
| 489 scoped_refptr<CacheStorageCache> cache, | 495 CacheStorageError error) { |
| 490 CacheStorageError error) { | 496 DropCacheReference(cache_id); |
| 491 if (error != CACHE_STORAGE_OK) { | 497 if (error != CACHE_STORAGE_OK) { |
| 492 Send(new CacheStorageMsg_CacheBatchError( | 498 Send(new CacheStorageMsg_CacheBatchError( |
| 493 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 499 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 494 return; | 500 return; |
| 495 } | 501 } |
| 496 | 502 |
| 497 Send(new CacheStorageMsg_CacheBatchSuccess(thread_id, request_id)); | 503 Send(new CacheStorageMsg_CacheBatchSuccess(thread_id, request_id)); |
| 498 } | 504 } |
| 499 | 505 |
| 500 CacheStorageDispatcherHost::CacheID | 506 CacheStorageDispatcherHost::CacheID |
| (...skipping 20 matching lines...) Expand all Loading... |
| 521 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); | 527 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
| 522 if (it == blob_handle_store_.end()) | 528 if (it == blob_handle_store_.end()) |
| 523 return; | 529 return; |
| 524 DCHECK(!it->second.empty()); | 530 DCHECK(!it->second.empty()); |
| 525 it->second.pop_front(); | 531 it->second.pop_front(); |
| 526 if (it->second.empty()) | 532 if (it->second.empty()) |
| 527 blob_handle_store_.erase(it); | 533 blob_handle_store_.erase(it); |
| 528 } | 534 } |
| 529 | 535 |
| 530 } // namespace content | 536 } // namespace content |
| OLD | NEW |