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" |
11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "content/browser/cache_storage/cache_storage_cache.h" | 12 #include "content/browser/cache_storage/cache_storage_cache.h" |
13 #include "content/browser/cache_storage/cache_storage_context_impl.h" | 13 #include "content/browser/cache_storage/cache_storage_context_impl.h" |
14 #include "content/browser/cache_storage/cache_storage_manager.h" | 14 #include "content/browser/cache_storage/cache_storage_manager.h" |
15 #include "content/common/cache_storage/cache_storage_messages.h" | 15 #include "content/common/cache_storage/cache_storage_messages.h" |
16 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
17 #include "storage/browser/blob/blob_data_handle.h" | 17 #include "storage/browser/blob/blob_data_handle.h" |
18 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h" | 18 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const uint32 kFilteredMessageClasses[] = {CacheStorageMsgStart}; | 24 const uint32 kFilteredMessageClasses[] = {CacheStorageMsgStart}; |
25 | 25 |
26 blink::WebServiceWorkerCacheError ToWebServiceWorkerCacheError( | 26 blink::WebServiceWorkerCacheError ToWebServiceWorkerCacheError( |
27 CacheStorage::CacheStorageError err) { | 27 CacheStorageError err) { |
28 switch (err) { | 28 switch (err) { |
29 case CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR: | 29 case CACHE_STORAGE_OK: |
30 NOTREACHED(); | 30 NOTREACHED(); |
31 return blink::WebServiceWorkerCacheErrorNotImplemented; | 31 return blink::WebServiceWorkerCacheErrorNotImplemented; |
32 case CacheStorage::CACHE_STORAGE_ERROR_NOT_IMPLEMENTED: | 32 case CACHE_STORAGE_ERROR_EXISTS: |
33 return blink::WebServiceWorkerCacheErrorNotImplemented; | 33 return blink::WebServiceWorkerCacheErrorExists; |
34 case CacheStorage::CACHE_STORAGE_ERROR_NOT_FOUND: | 34 case CACHE_STORAGE_ERROR_STORAGE: |
| 35 // TODO(nhiroki): Add WebServiceWorkerCacheError equivalent to |
| 36 // CACHE_STORAGE_ERROR_STORAGE. |
35 return blink::WebServiceWorkerCacheErrorNotFound; | 37 return blink::WebServiceWorkerCacheErrorNotFound; |
36 case CacheStorage::CACHE_STORAGE_ERROR_EXISTS: | 38 case CACHE_STORAGE_ERROR_NOT_FOUND: |
37 return blink::WebServiceWorkerCacheErrorExists; | |
38 case CacheStorage::CACHE_STORAGE_ERROR_STORAGE: | |
39 // TODO(jkarlin): Change this to CACHE_STORAGE_ERROR_STORAGE once that's | |
40 // added. | |
41 return blink::WebServiceWorkerCacheErrorNotFound; | |
42 case CacheStorage::CACHE_STORAGE_ERROR_CLOSING: | |
43 // TODO(jkarlin): Update this to CACHE_STORAGE_ERROR_CLOSING once that's | |
44 // added. | |
45 return blink::WebServiceWorkerCacheErrorNotFound; | 39 return blink::WebServiceWorkerCacheErrorNotFound; |
46 } | 40 } |
47 NOTREACHED(); | 41 NOTREACHED(); |
48 return blink::WebServiceWorkerCacheErrorNotImplemented; | |
49 } | |
50 | |
51 // TODO(jkarlin): CacheStorageCache and CacheStorage should share | |
52 // an error enum type. | |
53 blink::WebServiceWorkerCacheError CacheErrorToWebServiceWorkerCacheError( | |
54 CacheStorageCache::ErrorType err) { | |
55 switch (err) { | |
56 case CacheStorageCache::ERROR_TYPE_OK: | |
57 NOTREACHED(); | |
58 return blink::WebServiceWorkerCacheErrorNotImplemented; | |
59 case CacheStorageCache::ERROR_TYPE_EXISTS: | |
60 return blink::WebServiceWorkerCacheErrorExists; | |
61 case CacheStorageCache::ERROR_TYPE_STORAGE: | |
62 // TODO(jkarlin): Change this to CACHE_STORAGE_ERROR_STORAGE once that's | |
63 // added. | |
64 return blink::WebServiceWorkerCacheErrorNotFound; | |
65 case CacheStorageCache::ERROR_TYPE_NOT_FOUND: | |
66 return blink::WebServiceWorkerCacheErrorNotFound; | |
67 } | |
68 NOTREACHED(); | |
69 return blink::WebServiceWorkerCacheErrorNotImplemented; | 42 return blink::WebServiceWorkerCacheErrorNotImplemented; |
70 } | 43 } |
71 | 44 |
72 } // namespace | 45 } // namespace |
73 | 46 |
74 CacheStorageDispatcherHost::CacheStorageDispatcherHost() | 47 CacheStorageDispatcherHost::CacheStorageDispatcherHost() |
75 : BrowserMessageFilter(kFilteredMessageClasses, | 48 : BrowserMessageFilter(kFilteredMessageClasses, |
76 arraysize(kFilteredMessageClasses)) { | 49 arraysize(kFilteredMessageClasses)) { |
77 } | 50 } |
78 | 51 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 } | 285 } |
313 | 286 |
314 void CacheStorageDispatcherHost::OnBlobDataHandled(const std::string& uuid) { | 287 void CacheStorageDispatcherHost::OnBlobDataHandled(const std::string& uuid) { |
315 DropBlobDataHandle(uuid); | 288 DropBlobDataHandle(uuid); |
316 } | 289 } |
317 | 290 |
318 void CacheStorageDispatcherHost::OnCacheStorageHasCallback( | 291 void CacheStorageDispatcherHost::OnCacheStorageHasCallback( |
319 int thread_id, | 292 int thread_id, |
320 int request_id, | 293 int request_id, |
321 bool has_cache, | 294 bool has_cache, |
322 CacheStorage::CacheStorageError error) { | 295 CacheStorageError error) { |
323 if (error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { | 296 if (error != CACHE_STORAGE_OK) { |
324 Send(new CacheStorageMsg_CacheStorageHasError( | 297 Send(new CacheStorageMsg_CacheStorageHasError( |
325 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 298 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
326 return; | 299 return; |
327 } | 300 } |
328 if (!has_cache) { | 301 if (!has_cache) { |
329 Send(new CacheStorageMsg_CacheStorageHasError( | 302 Send(new CacheStorageMsg_CacheStorageHasError( |
330 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 303 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
331 return; | 304 return; |
332 } | 305 } |
333 Send(new CacheStorageMsg_CacheStorageHasSuccess(thread_id, request_id)); | 306 Send(new CacheStorageMsg_CacheStorageHasSuccess(thread_id, request_id)); |
334 } | 307 } |
335 | 308 |
336 void CacheStorageDispatcherHost::OnCacheStorageOpenCallback( | 309 void CacheStorageDispatcherHost::OnCacheStorageOpenCallback( |
337 int thread_id, | 310 int thread_id, |
338 int request_id, | 311 int request_id, |
339 const scoped_refptr<CacheStorageCache>& cache, | 312 const scoped_refptr<CacheStorageCache>& cache, |
340 CacheStorage::CacheStorageError error) { | 313 CacheStorageError error) { |
341 if (error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { | 314 if (error != CACHE_STORAGE_OK) { |
342 Send(new CacheStorageMsg_CacheStorageOpenError( | 315 Send(new CacheStorageMsg_CacheStorageOpenError( |
343 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 316 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
344 return; | 317 return; |
345 } | 318 } |
346 CacheID cache_id = StoreCacheReference(cache); | 319 CacheID cache_id = StoreCacheReference(cache); |
347 Send(new CacheStorageMsg_CacheStorageOpenSuccess(thread_id, request_id, | 320 Send(new CacheStorageMsg_CacheStorageOpenSuccess(thread_id, request_id, |
348 cache_id)); | 321 cache_id)); |
349 } | 322 } |
350 | 323 |
351 void CacheStorageDispatcherHost::OnCacheStorageDeleteCallback( | 324 void CacheStorageDispatcherHost::OnCacheStorageDeleteCallback( |
352 int thread_id, | 325 int thread_id, |
353 int request_id, | 326 int request_id, |
354 bool deleted, | 327 bool deleted, |
355 CacheStorage::CacheStorageError error) { | 328 CacheStorageError error) { |
356 if (!deleted || error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { | 329 if (!deleted || error != CACHE_STORAGE_OK) { |
357 Send(new CacheStorageMsg_CacheStorageDeleteError( | 330 Send(new CacheStorageMsg_CacheStorageDeleteError( |
358 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 331 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
359 return; | 332 return; |
360 } | 333 } |
361 Send(new CacheStorageMsg_CacheStorageDeleteSuccess(thread_id, request_id)); | 334 Send(new CacheStorageMsg_CacheStorageDeleteSuccess(thread_id, request_id)); |
362 } | 335 } |
363 | 336 |
364 void CacheStorageDispatcherHost::OnCacheStorageKeysCallback( | 337 void CacheStorageDispatcherHost::OnCacheStorageKeysCallback( |
365 int thread_id, | 338 int thread_id, |
366 int request_id, | 339 int request_id, |
367 const std::vector<std::string>& strings, | 340 const std::vector<std::string>& strings, |
368 CacheStorage::CacheStorageError error) { | 341 CacheStorageError error) { |
369 if (error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { | 342 if (error != CACHE_STORAGE_OK) { |
370 Send(new CacheStorageMsg_CacheStorageKeysError( | 343 Send(new CacheStorageMsg_CacheStorageKeysError( |
371 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 344 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
372 return; | 345 return; |
373 } | 346 } |
374 | 347 |
375 std::vector<base::string16> string16s; | 348 std::vector<base::string16> string16s; |
376 for (size_t i = 0, max = strings.size(); i < max; ++i) { | 349 for (size_t i = 0, max = strings.size(); i < max; ++i) { |
377 string16s.push_back(base::UTF8ToUTF16(strings[i])); | 350 string16s.push_back(base::UTF8ToUTF16(strings[i])); |
378 } | 351 } |
379 Send(new CacheStorageMsg_CacheStorageKeysSuccess(thread_id, request_id, | 352 Send(new CacheStorageMsg_CacheStorageKeysSuccess(thread_id, request_id, |
380 string16s)); | 353 string16s)); |
381 } | 354 } |
382 | 355 |
383 void CacheStorageDispatcherHost::OnCacheStorageMatchCallback( | 356 void CacheStorageDispatcherHost::OnCacheStorageMatchCallback( |
384 int thread_id, | 357 int thread_id, |
385 int request_id, | 358 int request_id, |
386 CacheStorageCache::ErrorType error, | 359 CacheStorageError error, |
387 scoped_ptr<ServiceWorkerResponse> response, | 360 scoped_ptr<ServiceWorkerResponse> response, |
388 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 361 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
389 if (error != CacheStorageCache::ERROR_TYPE_OK) { | 362 if (error != CACHE_STORAGE_OK) { |
390 Send(new CacheStorageMsg_CacheStorageMatchError( | 363 Send(new CacheStorageMsg_CacheStorageMatchError( |
391 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); | 364 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
392 return; | 365 return; |
393 } | 366 } |
394 | 367 |
395 if (blob_data_handle) | 368 if (blob_data_handle) |
396 StoreBlobDataHandle(blob_data_handle.Pass()); | 369 StoreBlobDataHandle(blob_data_handle.Pass()); |
397 | 370 |
398 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id, | 371 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id, |
399 *response)); | 372 *response)); |
400 } | 373 } |
401 | 374 |
402 void CacheStorageDispatcherHost::OnCacheMatchCallback( | 375 void CacheStorageDispatcherHost::OnCacheMatchCallback( |
403 int thread_id, | 376 int thread_id, |
404 int request_id, | 377 int request_id, |
405 const scoped_refptr<CacheStorageCache>& cache, | 378 const scoped_refptr<CacheStorageCache>& cache, |
406 CacheStorageCache::ErrorType error, | 379 CacheStorageError error, |
407 scoped_ptr<ServiceWorkerResponse> response, | 380 scoped_ptr<ServiceWorkerResponse> response, |
408 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 381 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
409 if (error != CacheStorageCache::ERROR_TYPE_OK) { | 382 if (error != CACHE_STORAGE_OK) { |
410 Send(new CacheStorageMsg_CacheMatchError( | 383 Send(new CacheStorageMsg_CacheMatchError( |
411 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); | 384 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
412 return; | 385 return; |
413 } | 386 } |
414 | 387 |
415 if (blob_data_handle) | 388 if (blob_data_handle) |
416 StoreBlobDataHandle(blob_data_handle.Pass()); | 389 StoreBlobDataHandle(blob_data_handle.Pass()); |
417 | 390 |
418 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response)); | 391 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response)); |
419 } | 392 } |
420 | 393 |
421 void CacheStorageDispatcherHost::OnCacheKeysCallback( | 394 void CacheStorageDispatcherHost::OnCacheKeysCallback( |
422 int thread_id, | 395 int thread_id, |
423 int request_id, | 396 int request_id, |
424 const scoped_refptr<CacheStorageCache>& cache, | 397 const scoped_refptr<CacheStorageCache>& cache, |
425 CacheStorageCache::ErrorType error, | 398 CacheStorageError error, |
426 scoped_ptr<CacheStorageCache::Requests> requests) { | 399 scoped_ptr<CacheStorageCache::Requests> requests) { |
427 if (error != CacheStorageCache::ERROR_TYPE_OK) { | 400 if (error != CACHE_STORAGE_OK) { |
428 Send(new CacheStorageMsg_CacheKeysError( | 401 Send(new CacheStorageMsg_CacheKeysError( |
429 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); | 402 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
430 return; | 403 return; |
431 } | 404 } |
432 | 405 |
433 CacheStorageCache::Requests out; | 406 CacheStorageCache::Requests out; |
434 | 407 |
435 for (CacheStorageCache::Requests::const_iterator it = requests->begin(); | 408 for (CacheStorageCache::Requests::const_iterator it = requests->begin(); |
436 it != requests->end(); ++it) { | 409 it != requests->end(); ++it) { |
437 ServiceWorkerFetchRequest request(it->url, it->method, it->headers, | 410 ServiceWorkerFetchRequest request(it->url, it->method, it->headers, |
438 it->referrer, it->is_reload); | 411 it->referrer, it->is_reload); |
439 out.push_back(request); | 412 out.push_back(request); |
440 } | 413 } |
441 | 414 |
442 Send(new CacheStorageMsg_CacheKeysSuccess(thread_id, request_id, out)); | 415 Send(new CacheStorageMsg_CacheKeysSuccess(thread_id, request_id, out)); |
443 } | 416 } |
444 | 417 |
445 void CacheStorageDispatcherHost::OnCacheBatchCallback( | 418 void CacheStorageDispatcherHost::OnCacheBatchCallback( |
446 int thread_id, | 419 int thread_id, |
447 int request_id, | 420 int request_id, |
448 const scoped_refptr<CacheStorageCache>& cache, | 421 const scoped_refptr<CacheStorageCache>& cache, |
449 CacheStorageCache::ErrorType error) { | 422 CacheStorageError error) { |
450 if (error != CacheStorageCache::ERROR_TYPE_OK) { | 423 if (error != CACHE_STORAGE_OK) { |
451 Send(new CacheStorageMsg_CacheBatchError( | 424 Send(new CacheStorageMsg_CacheBatchError( |
452 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); | 425 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
453 return; | 426 return; |
454 } | 427 } |
455 | 428 |
456 Send(new CacheStorageMsg_CacheBatchSuccess(thread_id, request_id)); | 429 Send(new CacheStorageMsg_CacheBatchSuccess(thread_id, request_id)); |
457 } | 430 } |
458 | 431 |
459 CacheStorageDispatcherHost::CacheID | 432 CacheStorageDispatcherHost::CacheID |
460 CacheStorageDispatcherHost::StoreCacheReference( | 433 CacheStorageDispatcherHost::StoreCacheReference( |
461 const scoped_refptr<CacheStorageCache>& cache) { | 434 const scoped_refptr<CacheStorageCache>& cache) { |
462 int cache_id = next_cache_id_++; | 435 int cache_id = next_cache_id_++; |
(...skipping 18 matching lines...) Expand all Loading... |
481 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); | 454 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
482 if (it == blob_handle_store_.end()) | 455 if (it == blob_handle_store_.end()) |
483 return; | 456 return; |
484 DCHECK(!it->second.empty()); | 457 DCHECK(!it->second.empty()); |
485 it->second.pop_front(); | 458 it->second.pop_front(); |
486 if (it->second.empty()) | 459 if (it->second.empty()) |
487 blob_handle_store_.erase(it); | 460 blob_handle_store_.erase(it); |
488 } | 461 } |
489 | 462 |
490 } // namespace content | 463 } // namespace content |
OLD | NEW |