| 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/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 369 } |
| 370 | 370 |
| 371 cache_loader_->CreateCache( | 371 cache_loader_->CreateCache( |
| 372 cache_name, | 372 cache_name, |
| 373 base::Bind(&ServiceWorkerCacheStorage::CreateCacheDidCreateCache, | 373 base::Bind(&ServiceWorkerCacheStorage::CreateCacheDidCreateCache, |
| 374 weak_factory_.GetWeakPtr(), | 374 weak_factory_.GetWeakPtr(), |
| 375 cache_name, | 375 cache_name, |
| 376 callback)); | 376 callback)); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void ServiceWorkerCacheStorage::OpenCache( |
| 380 const std::string& cache_name, |
| 381 const CacheAndErrorCallback& callback) { |
| 382 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 383 |
| 384 if (!initialized_) { |
| 385 LazyInit(base::Bind(&ServiceWorkerCacheStorage::OpenCache, |
| 386 weak_factory_.GetWeakPtr(), |
| 387 cache_name, |
| 388 callback)); |
| 389 return; |
| 390 } |
| 391 |
| 392 scoped_refptr<ServiceWorkerCache> cache = GetLoadedCache(cache_name); |
| 393 if (cache.get()) { |
| 394 callback.Run(cache, CACHE_STORAGE_ERROR_NO_ERROR); |
| 395 return; |
| 396 } |
| 397 |
| 398 cache_loader_->CreateCache( |
| 399 cache_name, |
| 400 base::Bind(&ServiceWorkerCacheStorage::CreateCacheDidCreateCache, |
| 401 weak_factory_.GetWeakPtr(), |
| 402 cache_name, |
| 403 callback)); |
| 404 } |
| 405 |
| 379 void ServiceWorkerCacheStorage::GetCache( | 406 void ServiceWorkerCacheStorage::GetCache( |
| 380 const std::string& cache_name, | 407 const std::string& cache_name, |
| 381 const CacheAndErrorCallback& callback) { | 408 const CacheAndErrorCallback& callback) { |
| 382 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 409 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 383 | 410 |
| 384 if (!initialized_) { | 411 if (!initialized_) { |
| 385 LazyInit(base::Bind(&ServiceWorkerCacheStorage::GetCache, | 412 LazyInit(base::Bind(&ServiceWorkerCacheStorage::GetCache, |
| 386 weak_factory_.GetWeakPtr(), | 413 weak_factory_.GetWeakPtr(), |
| 387 cache_name, | 414 cache_name, |
| 388 callback)); | 415 callback)); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 scoped_refptr<ServiceWorkerCache> new_cache = | 613 scoped_refptr<ServiceWorkerCache> new_cache = |
| 587 cache_loader_->CreateServiceWorkerCache(cache_name); | 614 cache_loader_->CreateServiceWorkerCache(cache_name); |
| 588 map_iter->second = new_cache->AsWeakPtr(); | 615 map_iter->second = new_cache->AsWeakPtr(); |
| 589 return new_cache; | 616 return new_cache; |
| 590 } | 617 } |
| 591 | 618 |
| 592 return make_scoped_refptr(cache.get()); | 619 return make_scoped_refptr(cache.get()); |
| 593 } | 620 } |
| 594 | 621 |
| 595 } // namespace content | 622 } // namespace content |
| OLD | NEW |