| 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 <algorithm> | 8 #include <algorithm> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 &CacheStorageCache::UpdateCacheSizeGotSize, | 1183 &CacheStorageCache::UpdateCacheSizeGotSize, |
| 1184 weak_ptr_factory_.GetWeakPtr(), base::Passed(CreateCacheHandle()))); | 1184 weak_ptr_factory_.GetWeakPtr(), base::Passed(CreateCacheHandle()))); |
| 1185 | 1185 |
| 1186 if (rv != net::ERR_IO_PENDING) | 1186 if (rv != net::ERR_IO_PENDING) |
| 1187 UpdateCacheSizeGotSize(CreateCacheHandle(), rv); | 1187 UpdateCacheSizeGotSize(CreateCacheHandle(), rv); |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 void CacheStorageCache::UpdateCacheSizeGotSize( | 1190 void CacheStorageCache::UpdateCacheSizeGotSize( |
| 1191 std::unique_ptr<CacheStorageCacheHandle> cache_handle, | 1191 std::unique_ptr<CacheStorageCacheHandle> cache_handle, |
| 1192 int current_cache_size) { | 1192 int current_cache_size) { |
| 1193 DCHECK_NE(current_cache_size, CacheStorage::kSizeUnknown); | 1193 DCHECK_NE(current_cache_size, kCacheStorageSizeUnknown); |
| 1194 int64_t old_cache_size = cache_size_; | 1194 int64_t old_cache_size = cache_size_; |
| 1195 cache_size_ = current_cache_size; | 1195 cache_size_ = current_cache_size; |
| 1196 | 1196 |
| 1197 int64_t size_delta = current_cache_size - old_cache_size; | 1197 int64_t size_delta = current_cache_size - old_cache_size; |
| 1198 | 1198 |
| 1199 quota_manager_proxy_->NotifyStorageModified( | 1199 quota_manager_proxy_->NotifyStorageModified( |
| 1200 storage::QuotaClient::kServiceWorkerCache, origin_, | 1200 storage::QuotaClient::kServiceWorkerCache, origin_, |
| 1201 storage::kStorageTypeTemporary, size_delta); | 1201 storage::kStorageTypeTemporary, size_delta); |
| 1202 | 1202 |
| 1203 if (cache_observer_) | 1203 if (cache_observer_) |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1383 InitGotCacheSize(callback, cache_create_error, rv); | 1383 InitGotCacheSize(callback, cache_create_error, rv); |
| 1384 } | 1384 } |
| 1385 | 1385 |
| 1386 void CacheStorageCache::InitGotCacheSize(const base::Closure& callback, | 1386 void CacheStorageCache::InitGotCacheSize(const base::Closure& callback, |
| 1387 CacheStorageError cache_create_error, | 1387 CacheStorageError cache_create_error, |
| 1388 int cache_size) { | 1388 int cache_size) { |
| 1389 // Now that we know the cache size either 1) the cache size should be unknown | 1389 // Now that we know the cache size either 1) the cache size should be unknown |
| 1390 // (which is why the size was calculated), or 2) it must match the current | 1390 // (which is why the size was calculated), or 2) it must match the current |
| 1391 // size. If the sizes aren't equal then there is a bug in how the cache size | 1391 // size. If the sizes aren't equal then there is a bug in how the cache size |
| 1392 // is saved in the store's index. | 1392 // is saved in the store's index. |
| 1393 if (cache_size_ != CacheStorage::kSizeUnknown && cache_size_ != cache_size) { | 1393 if (cache_size_ != kCacheStorageSizeUnknown && cache_size_ != cache_size) { |
| 1394 // TODO(cmumford): Add UMA for this. | 1394 // TODO(cmumford): Add UMA for this. |
| 1395 LOG(ERROR) << "Cache size/index mismatch"; | 1395 LOG(ERROR) << "Cache size/index mismatch"; |
| 1396 DCHECK_EQ(cache_size_, cache_size); | 1396 DCHECK_EQ(cache_size_, cache_size); |
| 1397 } | 1397 } |
| 1398 cache_size_ = cache_size; | 1398 cache_size_ = cache_size; |
| 1399 initializing_ = false; | 1399 initializing_ = false; |
| 1400 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ && | 1400 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ && |
| 1401 backend_state_ == BACKEND_UNINITIALIZED) | 1401 backend_state_ == BACKEND_UNINITIALIZED) |
| 1402 ? BACKEND_OPEN | 1402 ? BACKEND_OPEN |
| 1403 : BACKEND_CLOSED; | 1403 : BACKEND_CLOSED; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); | 1481 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); |
| 1482 return blob_storage_context_->AddFinishedBlob(&blob_data); | 1482 return blob_storage_context_->AddFinishedBlob(&blob_data); |
| 1483 } | 1483 } |
| 1484 | 1484 |
| 1485 std::unique_ptr<CacheStorageCacheHandle> | 1485 std::unique_ptr<CacheStorageCacheHandle> |
| 1486 CacheStorageCache::CreateCacheHandle() { | 1486 CacheStorageCache::CreateCacheHandle() { |
| 1487 return cache_storage_->CreateCacheHandle(this); | 1487 return cache_storage_->CreateCacheHandle(this); |
| 1488 } | 1488 } |
| 1489 | 1489 |
| 1490 } // namespace content | 1490 } // namespace content |
| OLD | NEW |