OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/service_worker/service_worker_cache_storage.h" | 5 #include "content/browser/service_worker/service_worker_cache_storage.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 const std::string& cache_name, | 398 const std::string& cache_name, |
399 const CacheAndErrorCallback& callback) { | 399 const CacheAndErrorCallback& callback) { |
400 if (!initialized_) { | 400 if (!initialized_) { |
401 LazyInit(base::Bind(&ServiceWorkerCacheStorage::CreateCache, | 401 LazyInit(base::Bind(&ServiceWorkerCacheStorage::CreateCache, |
402 weak_factory_.GetWeakPtr(), | 402 weak_factory_.GetWeakPtr(), |
403 cache_name, | 403 cache_name, |
404 callback)); | 404 callback)); |
405 return; | 405 return; |
406 } | 406 } |
407 | 407 |
408 if (cache_name.empty()) { | |
409 callback.Run(kInvalidCacheID, CACHE_STORAGE_ERROR_EMPTY_KEY); | |
410 return; | |
411 } | |
412 | |
413 if (GetLoadedCache(cache_name)) { | 408 if (GetLoadedCache(cache_name)) { |
414 callback.Run(kInvalidCacheID, CACHE_STORAGE_ERROR_EXISTS); | 409 callback.Run(kInvalidCacheID, CACHE_STORAGE_ERROR_EXISTS); |
415 return; | 410 return; |
416 } | 411 } |
417 | 412 |
418 cache_loader_->CreateCache( | 413 cache_loader_->CreateCache( |
419 cache_name, | 414 cache_name, |
420 base::Bind(&ServiceWorkerCacheStorage::CreateCacheDidCreateCache, | 415 base::Bind(&ServiceWorkerCacheStorage::CreateCacheDidCreateCache, |
421 weak_factory_.GetWeakPtr(), | 416 weak_factory_.GetWeakPtr(), |
422 cache_name, | 417 cache_name, |
423 callback)); | 418 callback)); |
424 } | 419 } |
425 | 420 |
426 void ServiceWorkerCacheStorage::GetCache( | 421 void ServiceWorkerCacheStorage::GetCache( |
427 const std::string& cache_name, | 422 const std::string& cache_name, |
428 const CacheAndErrorCallback& callback) { | 423 const CacheAndErrorCallback& callback) { |
429 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 424 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
430 | 425 |
431 if (!initialized_) { | 426 if (!initialized_) { |
432 LazyInit(base::Bind(&ServiceWorkerCacheStorage::GetCache, | 427 LazyInit(base::Bind(&ServiceWorkerCacheStorage::GetCache, |
433 weak_factory_.GetWeakPtr(), | 428 weak_factory_.GetWeakPtr(), |
434 cache_name, | 429 cache_name, |
435 callback)); | 430 callback)); |
436 return; | 431 return; |
437 } | 432 } |
438 | 433 |
439 if (cache_name.empty()) { | |
440 callback.Run(kInvalidCacheID, CACHE_STORAGE_ERROR_EMPTY_KEY); | |
441 return; | |
442 } | |
443 | |
444 CacheContext* cache_context = GetLoadedCache(cache_name); | 434 CacheContext* cache_context = GetLoadedCache(cache_name); |
445 if (!cache_context) { | 435 if (!cache_context) { |
446 callback.Run(kInvalidCacheID, CACHE_STORAGE_ERROR_NOT_FOUND); | 436 callback.Run(kInvalidCacheID, CACHE_STORAGE_ERROR_NOT_FOUND); |
447 return; | 437 return; |
448 } | 438 } |
449 | 439 |
450 ServiceWorkerCache* cache = cache_context->cache.get(); | 440 ServiceWorkerCache* cache = cache_context->cache.get(); |
451 | 441 |
452 if (cache->HasCreatedBackend()) | 442 if (cache->HasCreatedBackend()) |
453 return callback.Run(cache_context->id, CACHE_STORAGE_ERROR_NO_ERROR); | 443 return callback.Run(cache_context->id, CACHE_STORAGE_ERROR_NO_ERROR); |
(...skipping 10 matching lines...) Expand all Loading... |
464 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 454 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
465 | 455 |
466 if (!initialized_) { | 456 if (!initialized_) { |
467 LazyInit(base::Bind(&ServiceWorkerCacheStorage::HasCache, | 457 LazyInit(base::Bind(&ServiceWorkerCacheStorage::HasCache, |
468 weak_factory_.GetWeakPtr(), | 458 weak_factory_.GetWeakPtr(), |
469 cache_name, | 459 cache_name, |
470 callback)); | 460 callback)); |
471 return; | 461 return; |
472 } | 462 } |
473 | 463 |
474 if (cache_name.empty()) { | |
475 callback.Run(false, CACHE_STORAGE_ERROR_EMPTY_KEY); | |
476 return; | |
477 } | |
478 | |
479 bool has_cache = GetLoadedCache(cache_name) != NULL; | 464 bool has_cache = GetLoadedCache(cache_name) != NULL; |
480 | 465 |
481 callback.Run(has_cache, CACHE_STORAGE_ERROR_NO_ERROR); | 466 callback.Run(has_cache, CACHE_STORAGE_ERROR_NO_ERROR); |
482 } | 467 } |
483 | 468 |
484 void ServiceWorkerCacheStorage::DeleteCache( | 469 void ServiceWorkerCacheStorage::DeleteCache( |
485 const std::string& cache_name, | 470 const std::string& cache_name, |
486 const BoolAndErrorCallback& callback) { | 471 const BoolAndErrorCallback& callback) { |
487 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 472 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
488 | 473 |
489 if (!initialized_) { | 474 if (!initialized_) { |
490 LazyInit(base::Bind(&ServiceWorkerCacheStorage::DeleteCache, | 475 LazyInit(base::Bind(&ServiceWorkerCacheStorage::DeleteCache, |
491 weak_factory_.GetWeakPtr(), | 476 weak_factory_.GetWeakPtr(), |
492 cache_name, | 477 cache_name, |
493 callback)); | 478 callback)); |
494 return; | 479 return; |
495 } | 480 } |
496 | 481 |
497 if (cache_name.empty()) { | |
498 callback.Run(false, CACHE_STORAGE_ERROR_EMPTY_KEY); | |
499 return; | |
500 } | |
501 | |
502 scoped_ptr<CacheContext> cache_context(GetLoadedCache(cache_name)); | 482 scoped_ptr<CacheContext> cache_context(GetLoadedCache(cache_name)); |
503 if (!cache_context) { | 483 if (!cache_context) { |
504 callback.Run(false, CACHE_STORAGE_ERROR_NOT_FOUND); | 484 callback.Run(false, CACHE_STORAGE_ERROR_NOT_FOUND); |
505 return; | 485 return; |
506 } | 486 } |
507 | 487 |
508 name_map_.erase(cache_name); | 488 name_map_.erase(cache_name); |
509 cache_map_.erase(cache_context->id); | 489 cache_map_.erase(cache_context->id); |
510 cache_context.reset(); | 490 cache_context.reset(); |
511 | 491 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 NameMap::const_iterator name_iter = name_map_.find(cache_name); | 704 NameMap::const_iterator name_iter = name_map_.find(cache_name); |
725 if (name_iter == name_map_.end()) | 705 if (name_iter == name_map_.end()) |
726 return NULL; | 706 return NULL; |
727 | 707 |
728 CacheMap::const_iterator map_iter = cache_map_.find(name_iter->second); | 708 CacheMap::const_iterator map_iter = cache_map_.find(name_iter->second); |
729 DCHECK(map_iter != cache_map_.end()); | 709 DCHECK(map_iter != cache_map_.end()); |
730 return map_iter->second; | 710 return map_iter->second; |
731 } | 711 } |
732 | 712 |
733 } // namespace content | 713 } // namespace content |
OLD | NEW |