| 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/cache_storage/cache_storage_cache.h" | 5 #include "content/browser/cache_storage/cache_storage_cache.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 } | 438 } |
| 439 | 439 |
| 440 void CacheStorageCache::Size(const SizeCallback& callback) { | 440 void CacheStorageCache::Size(const SizeCallback& callback) { |
| 441 if (!LazyInitialize()) { | 441 if (!LazyInitialize()) { |
| 442 // TODO(jkarlin): Delete caches that can't be initialized. | 442 // TODO(jkarlin): Delete caches that can't be initialized. |
| 443 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 443 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 444 base::Bind(callback, 0)); | 444 base::Bind(callback, 0)); |
| 445 return; | 445 return; |
| 446 } | 446 } |
| 447 | 447 |
| 448 // If the cache isn't already initialized, wait for it. | |
| 449 if (initializing_) { | 448 if (initializing_) { |
| 450 SizeCallback pending_callback = | 449 // Note that Size doesn't use the scheduler, see header comments for why. |
| 451 base::Bind(&CacheStorageCache::PendingSizeCallback, | 450 pending_size_callbacks_.push_back(callback); |
| 452 weak_ptr_factory_.GetWeakPtr(), callback); | |
| 453 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::SizeImpl, | |
| 454 weak_ptr_factory_.GetWeakPtr(), | |
| 455 pending_callback)); | |
| 456 return; | 451 return; |
| 457 } | 452 } |
| 458 | 453 |
| 459 // Run immediately so that we don't deadlock on | 454 // Run immediately so that we don't deadlock on |
| 460 // CacheStorageCache::PutDidDelete's call to | 455 // CacheStorageCache::PutDidDelete's call to |
| 461 // quota_manager_proxy_->GetUsageAndQuota. | 456 // quota_manager_proxy_->GetUsageAndQuota. |
| 462 SizeImpl(callback); | 457 SizeImpl(callback); |
| 463 } | 458 } |
| 464 | 459 |
| 465 void CacheStorageCache::GetSizeThenClose(const SizeCallback& callback) { | 460 void CacheStorageCache::GetSizeThenClose(const SizeCallback& callback) { |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 | 1296 |
| 1302 void CacheStorageCache::InitGotCacheSize(CacheStorageError cache_create_error, | 1297 void CacheStorageCache::InitGotCacheSize(CacheStorageError cache_create_error, |
| 1303 int cache_size) { | 1298 int cache_size) { |
| 1304 cache_size_ = cache_size; | 1299 cache_size_ = cache_size; |
| 1305 initializing_ = false; | 1300 initializing_ = false; |
| 1306 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ && | 1301 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ && |
| 1307 backend_state_ == BACKEND_UNINITIALIZED) | 1302 backend_state_ == BACKEND_UNINITIALIZED) |
| 1308 ? BACKEND_OPEN | 1303 ? BACKEND_OPEN |
| 1309 : BACKEND_CLOSED; | 1304 : BACKEND_CLOSED; |
| 1310 | 1305 |
| 1306 for (const SizeCallback& callback : pending_size_callbacks_) |
| 1307 SizeImpl(callback); |
| 1308 pending_size_callbacks_.clear(); |
| 1309 |
| 1311 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult", | 1310 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult", |
| 1312 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1); | 1311 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1); |
| 1313 | 1312 |
| 1314 scheduler_->CompleteOperationAndRunNext(); | 1313 scheduler_->CompleteOperationAndRunNext(); |
| 1315 } | 1314 } |
| 1316 | 1315 |
| 1317 void CacheStorageCache::PendingClosure(const base::Closure& callback) { | 1316 void CacheStorageCache::PendingClosure(const base::Closure& callback) { |
| 1318 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | 1317 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); |
| 1319 | 1318 |
| 1320 callback.Run(); | 1319 callback.Run(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 storage::BlobDataBuilder blob_data(response->blob_uuid); | 1405 storage::BlobDataBuilder blob_data(response->blob_uuid); |
| 1407 | 1406 |
| 1408 disk_cache::Entry* temp_entry = entry.get(); | 1407 disk_cache::Entry* temp_entry = entry.get(); |
| 1409 blob_data.AppendDiskCacheEntry( | 1408 blob_data.AppendDiskCacheEntry( |
| 1410 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, | 1409 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, |
| 1411 INDEX_RESPONSE_BODY); | 1410 INDEX_RESPONSE_BODY); |
| 1412 return blob_storage_context_->AddFinishedBlob(&blob_data); | 1411 return blob_storage_context_->AddFinishedBlob(&blob_data); |
| 1413 } | 1412 } |
| 1414 | 1413 |
| 1415 } // namespace content | 1414 } // namespace content |
| OLD | NEW |