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

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

Issue 1132683003: CacheStorage: Merge CacheStorage::CacheStorageError and CacheStorageCache::ErrorType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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/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 return blink::WebServiceWorkerCacheErrorNotFound; 35 return blink::WebServiceWorkerCacheErrorNotFound;
jkarlin 2015/05/08 12:38:19 Add a TODO that we need an ERROR_STORAGE WebServic
nhiroki 2015/05/08 14:15:10 Done.
36 case CacheStorage::CACHE_STORAGE_ERROR_EXISTS: 36 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; 37 return blink::WebServiceWorkerCacheErrorNotFound;
46 } 38 }
47 NOTREACHED(); 39 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; 40 return blink::WebServiceWorkerCacheErrorNotImplemented;
70 } 41 }
71 42
72 } // namespace 43 } // namespace
73 44
74 CacheStorageDispatcherHost::CacheStorageDispatcherHost() 45 CacheStorageDispatcherHost::CacheStorageDispatcherHost()
75 : BrowserMessageFilter(kFilteredMessageClasses, 46 : BrowserMessageFilter(kFilteredMessageClasses,
76 arraysize(kFilteredMessageClasses)) { 47 arraysize(kFilteredMessageClasses)) {
77 } 48 }
78 49
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 283 }
313 284
314 void CacheStorageDispatcherHost::OnBlobDataHandled(const std::string& uuid) { 285 void CacheStorageDispatcherHost::OnBlobDataHandled(const std::string& uuid) {
315 DropBlobDataHandle(uuid); 286 DropBlobDataHandle(uuid);
316 } 287 }
317 288
318 void CacheStorageDispatcherHost::OnCacheStorageHasCallback( 289 void CacheStorageDispatcherHost::OnCacheStorageHasCallback(
319 int thread_id, 290 int thread_id,
320 int request_id, 291 int request_id,
321 bool has_cache, 292 bool has_cache,
322 CacheStorage::CacheStorageError error) { 293 CacheStorageError error) {
323 if (error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { 294 if (error != CACHE_STORAGE_OK) {
324 Send(new CacheStorageMsg_CacheStorageHasError( 295 Send(new CacheStorageMsg_CacheStorageHasError(
325 thread_id, request_id, ToWebServiceWorkerCacheError(error))); 296 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
326 return; 297 return;
327 } 298 }
328 if (!has_cache) { 299 if (!has_cache) {
329 Send(new CacheStorageMsg_CacheStorageHasError( 300 Send(new CacheStorageMsg_CacheStorageHasError(
330 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); 301 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound));
331 return; 302 return;
332 } 303 }
333 Send(new CacheStorageMsg_CacheStorageHasSuccess(thread_id, request_id)); 304 Send(new CacheStorageMsg_CacheStorageHasSuccess(thread_id, request_id));
334 } 305 }
335 306
336 void CacheStorageDispatcherHost::OnCacheStorageOpenCallback( 307 void CacheStorageDispatcherHost::OnCacheStorageOpenCallback(
337 int thread_id, 308 int thread_id,
338 int request_id, 309 int request_id,
339 const scoped_refptr<CacheStorageCache>& cache, 310 const scoped_refptr<CacheStorageCache>& cache,
340 CacheStorage::CacheStorageError error) { 311 CacheStorageError error) {
341 if (error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { 312 if (error != CACHE_STORAGE_OK) {
342 Send(new CacheStorageMsg_CacheStorageOpenError( 313 Send(new CacheStorageMsg_CacheStorageOpenError(
343 thread_id, request_id, ToWebServiceWorkerCacheError(error))); 314 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
344 return; 315 return;
345 } 316 }
346 CacheID cache_id = StoreCacheReference(cache); 317 CacheID cache_id = StoreCacheReference(cache);
347 Send(new CacheStorageMsg_CacheStorageOpenSuccess(thread_id, request_id, 318 Send(new CacheStorageMsg_CacheStorageOpenSuccess(thread_id, request_id,
348 cache_id)); 319 cache_id));
349 } 320 }
350 321
351 void CacheStorageDispatcherHost::OnCacheStorageDeleteCallback( 322 void CacheStorageDispatcherHost::OnCacheStorageDeleteCallback(
352 int thread_id, 323 int thread_id,
353 int request_id, 324 int request_id,
354 bool deleted, 325 bool deleted,
355 CacheStorage::CacheStorageError error) { 326 CacheStorageError error) {
356 if (!deleted || error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { 327 if (!deleted || error != CACHE_STORAGE_OK) {
357 Send(new CacheStorageMsg_CacheStorageDeleteError( 328 Send(new CacheStorageMsg_CacheStorageDeleteError(
358 thread_id, request_id, ToWebServiceWorkerCacheError(error))); 329 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
359 return; 330 return;
360 } 331 }
361 Send(new CacheStorageMsg_CacheStorageDeleteSuccess(thread_id, request_id)); 332 Send(new CacheStorageMsg_CacheStorageDeleteSuccess(thread_id, request_id));
362 } 333 }
363 334
364 void CacheStorageDispatcherHost::OnCacheStorageKeysCallback( 335 void CacheStorageDispatcherHost::OnCacheStorageKeysCallback(
365 int thread_id, 336 int thread_id,
366 int request_id, 337 int request_id,
367 const std::vector<std::string>& strings, 338 const std::vector<std::string>& strings,
368 CacheStorage::CacheStorageError error) { 339 CacheStorageError error) {
369 if (error != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) { 340 if (error != CACHE_STORAGE_OK) {
370 Send(new CacheStorageMsg_CacheStorageKeysError( 341 Send(new CacheStorageMsg_CacheStorageKeysError(
371 thread_id, request_id, ToWebServiceWorkerCacheError(error))); 342 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
372 return; 343 return;
373 } 344 }
374 345
375 std::vector<base::string16> string16s; 346 std::vector<base::string16> string16s;
376 for (size_t i = 0, max = strings.size(); i < max; ++i) { 347 for (size_t i = 0, max = strings.size(); i < max; ++i) {
377 string16s.push_back(base::UTF8ToUTF16(strings[i])); 348 string16s.push_back(base::UTF8ToUTF16(strings[i]));
378 } 349 }
379 Send(new CacheStorageMsg_CacheStorageKeysSuccess(thread_id, request_id, 350 Send(new CacheStorageMsg_CacheStorageKeysSuccess(thread_id, request_id,
380 string16s)); 351 string16s));
381 } 352 }
382 353
383 void CacheStorageDispatcherHost::OnCacheStorageMatchCallback( 354 void CacheStorageDispatcherHost::OnCacheStorageMatchCallback(
384 int thread_id, 355 int thread_id,
385 int request_id, 356 int request_id,
386 CacheStorageCache::ErrorType error, 357 CacheStorageError error,
387 scoped_ptr<ServiceWorkerResponse> response, 358 scoped_ptr<ServiceWorkerResponse> response,
388 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { 359 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
389 if (error != CacheStorageCache::ERROR_TYPE_OK) { 360 if (error != CACHE_STORAGE_OK) {
390 Send(new CacheStorageMsg_CacheStorageMatchError( 361 Send(new CacheStorageMsg_CacheStorageMatchError(
391 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); 362 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
392 return; 363 return;
393 } 364 }
394 365
395 if (blob_data_handle) 366 if (blob_data_handle)
396 StoreBlobDataHandle(blob_data_handle.Pass()); 367 StoreBlobDataHandle(blob_data_handle.Pass());
397 368
398 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id, 369 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id,
399 *response)); 370 *response));
400 } 371 }
401 372
402 void CacheStorageDispatcherHost::OnCacheMatchCallback( 373 void CacheStorageDispatcherHost::OnCacheMatchCallback(
403 int thread_id, 374 int thread_id,
404 int request_id, 375 int request_id,
405 const scoped_refptr<CacheStorageCache>& cache, 376 const scoped_refptr<CacheStorageCache>& cache,
406 CacheStorageCache::ErrorType error, 377 CacheStorageError error,
407 scoped_ptr<ServiceWorkerResponse> response, 378 scoped_ptr<ServiceWorkerResponse> response,
408 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { 379 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
409 if (error != CacheStorageCache::ERROR_TYPE_OK) { 380 if (error != CACHE_STORAGE_OK) {
410 Send(new CacheStorageMsg_CacheMatchError( 381 Send(new CacheStorageMsg_CacheMatchError(
411 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); 382 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
412 return; 383 return;
413 } 384 }
414 385
415 if (blob_data_handle) 386 if (blob_data_handle)
416 StoreBlobDataHandle(blob_data_handle.Pass()); 387 StoreBlobDataHandle(blob_data_handle.Pass());
417 388
418 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response)); 389 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response));
419 } 390 }
420 391
421 void CacheStorageDispatcherHost::OnCacheKeysCallback( 392 void CacheStorageDispatcherHost::OnCacheKeysCallback(
422 int thread_id, 393 int thread_id,
423 int request_id, 394 int request_id,
424 const scoped_refptr<CacheStorageCache>& cache, 395 const scoped_refptr<CacheStorageCache>& cache,
425 CacheStorageCache::ErrorType error, 396 CacheStorageError error,
426 scoped_ptr<CacheStorageCache::Requests> requests) { 397 scoped_ptr<CacheStorageCache::Requests> requests) {
427 if (error != CacheStorageCache::ERROR_TYPE_OK) { 398 if (error != CACHE_STORAGE_OK) {
428 Send(new CacheStorageMsg_CacheKeysError( 399 Send(new CacheStorageMsg_CacheKeysError(
429 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); 400 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
430 return; 401 return;
431 } 402 }
432 403
433 CacheStorageCache::Requests out; 404 CacheStorageCache::Requests out;
434 405
435 for (CacheStorageCache::Requests::const_iterator it = requests->begin(); 406 for (CacheStorageCache::Requests::const_iterator it = requests->begin();
436 it != requests->end(); ++it) { 407 it != requests->end(); ++it) {
437 ServiceWorkerFetchRequest request(it->url, it->method, it->headers, 408 ServiceWorkerFetchRequest request(it->url, it->method, it->headers,
438 it->referrer, it->is_reload); 409 it->referrer, it->is_reload);
439 out.push_back(request); 410 out.push_back(request);
440 } 411 }
441 412
442 Send(new CacheStorageMsg_CacheKeysSuccess(thread_id, request_id, out)); 413 Send(new CacheStorageMsg_CacheKeysSuccess(thread_id, request_id, out));
443 } 414 }
444 415
445 void CacheStorageDispatcherHost::OnCacheBatchCallback( 416 void CacheStorageDispatcherHost::OnCacheBatchCallback(
446 int thread_id, 417 int thread_id,
447 int request_id, 418 int request_id,
448 const scoped_refptr<CacheStorageCache>& cache, 419 const scoped_refptr<CacheStorageCache>& cache,
449 CacheStorageCache::ErrorType error) { 420 CacheStorageError error) {
450 if (error != CacheStorageCache::ERROR_TYPE_OK) { 421 if (error != CACHE_STORAGE_OK) {
451 Send(new CacheStorageMsg_CacheBatchError( 422 Send(new CacheStorageMsg_CacheBatchError(
452 thread_id, request_id, CacheErrorToWebServiceWorkerCacheError(error))); 423 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
453 return; 424 return;
454 } 425 }
455 426
456 Send(new CacheStorageMsg_CacheBatchSuccess(thread_id, request_id)); 427 Send(new CacheStorageMsg_CacheBatchSuccess(thread_id, request_id));
457 } 428 }
458 429
459 CacheStorageDispatcherHost::CacheID 430 CacheStorageDispatcherHost::CacheID
460 CacheStorageDispatcherHost::StoreCacheReference( 431 CacheStorageDispatcherHost::StoreCacheReference(
461 const scoped_refptr<CacheStorageCache>& cache) { 432 const scoped_refptr<CacheStorageCache>& cache) {
462 int cache_id = next_cache_id_++; 433 int cache_id = next_cache_id_++;
(...skipping 18 matching lines...) Expand all
481 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); 452 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid);
482 if (it == blob_handle_store_.end()) 453 if (it == blob_handle_store_.end())
483 return; 454 return;
484 DCHECK(!it->second.empty()); 455 DCHECK(!it->second.empty());
485 it->second.pop_front(); 456 it->second.pop_front();
486 if (it->second.empty()) 457 if (it->second.empty())
487 blob_handle_store_.erase(it); 458 blob_handle_store_.erase(it);
488 } 459 }
489 460
490 } // namespace content 461 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698