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

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

Issue 2613183003: [CacheStorage] Updating cache size within the scheduled operation. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 if (rv != net::ERR_IO_PENDING) 931 if (rv != net::ERR_IO_PENDING)
932 write_side_data_callback.Run(rv); 932 write_side_data_callback.Run(rv);
933 } 933 }
934 934
935 void CacheStorageCache::WriteSideDataDidWrite(const ErrorCallback& callback, 935 void CacheStorageCache::WriteSideDataDidWrite(const ErrorCallback& callback,
936 disk_cache::ScopedEntryPtr entry, 936 disk_cache::ScopedEntryPtr entry,
937 int expected_bytes, 937 int expected_bytes,
938 int rv) { 938 int rv) {
939 if (rv != expected_bytes) { 939 if (rv != expected_bytes) {
940 entry->Doom(); 940 entry->Doom();
941 UpdateCacheSize(); 941 UpdateCacheSize(base::Bind(callback, CACHE_STORAGE_ERROR_NOT_FOUND));
942 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND);
943 return; 942 return;
944 } 943 }
945 944
946 UpdateCacheSize(); 945 UpdateCacheSize(base::Bind(callback, CACHE_STORAGE_OK));
947 callback.Run(CACHE_STORAGE_OK);
948 } 946 }
949 947
950 void CacheStorageCache::Put(const CacheStorageBatchOperation& operation, 948 void CacheStorageCache::Put(const CacheStorageBatchOperation& operation,
951 const ErrorCallback& callback) { 949 const ErrorCallback& callback) {
952 DCHECK(BACKEND_OPEN == backend_state_ || initializing_); 950 DCHECK(BACKEND_OPEN == backend_state_ || initializing_);
953 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT, operation.operation_type); 951 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT, operation.operation_type);
954 952
955 std::unique_ptr<ServiceWorkerFetchRequest> request( 953 std::unique_ptr<ServiceWorkerFetchRequest> request(
956 new ServiceWorkerFetchRequest( 954 new ServiceWorkerFetchRequest(
957 operation.request.url, operation.request.method, 955 operation.request.url, operation.request.method,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 if (rv != expected_bytes) { 1117 if (rv != expected_bytes) {
1120 put_context->cache_entry->Doom(); 1118 put_context->cache_entry->Doom();
1121 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); 1119 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE);
1122 return; 1120 return;
1123 } 1121 }
1124 1122
1125 // The metadata is written, now for the response content. The data is streamed 1123 // The metadata is written, now for the response content. The data is streamed
1126 // from the blob into the cache entry. 1124 // from the blob into the cache entry.
1127 1125
1128 if (put_context->response->blob_uuid.empty()) { 1126 if (put_context->response->blob_uuid.empty()) {
1129 UpdateCacheSize(); 1127 UpdateCacheSize(base::Bind(put_context->callback, CACHE_STORAGE_OK));
1130 put_context->callback.Run(CACHE_STORAGE_OK);
1131 return; 1128 return;
1132 } 1129 }
1133 1130
1134 DCHECK(put_context->blob_data_handle); 1131 DCHECK(put_context->blob_data_handle);
1135 1132
1136 disk_cache::ScopedEntryPtr entry(std::move(put_context->cache_entry)); 1133 disk_cache::ScopedEntryPtr entry(std::move(put_context->cache_entry));
1137 put_context->cache_entry = NULL; 1134 put_context->cache_entry = NULL;
1138 1135
1139 auto blob_to_cache = base::MakeUnique<CacheStorageBlobToDiskCache>(); 1136 auto blob_to_cache = base::MakeUnique<CacheStorageBlobToDiskCache>();
1140 CacheStorageBlobToDiskCache* blob_to_cache_raw = blob_to_cache.get(); 1137 CacheStorageBlobToDiskCache* blob_to_cache_raw = blob_to_cache.get();
(...skipping 20 matching lines...) Expand all
1161 put_context->cache_entry = std::move(entry); 1158 put_context->cache_entry = std::move(entry);
1162 1159
1163 active_blob_to_disk_cache_writers_.Remove(blob_to_cache_key); 1160 active_blob_to_disk_cache_writers_.Remove(blob_to_cache_key);
1164 1161
1165 if (!success) { 1162 if (!success) {
1166 put_context->cache_entry->Doom(); 1163 put_context->cache_entry->Doom();
1167 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); 1164 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE);
1168 return; 1165 return;
1169 } 1166 }
1170 1167
1171 UpdateCacheSize(); 1168 UpdateCacheSize(base::Bind(put_context->callback, CACHE_STORAGE_OK));
1172 put_context->callback.Run(CACHE_STORAGE_OK);
1173 } 1169 }
1174 1170
1175 void CacheStorageCache::UpdateCacheSize() { 1171 void CacheStorageCache::UpdateCacheSize(const base::Closure& callback) {
1176 if (backend_state_ != BACKEND_OPEN) 1172 if (backend_state_ != BACKEND_OPEN)
1177 return; 1173 return;
1178 1174
1179 // Note that the callback holds a cache handle to keep the cache alive during 1175 // Note that the callback holds a cache handle to keep the cache alive during
1180 // the operation since this UpdateCacheSize is often run after an operation 1176 // the operation since this UpdateCacheSize is often run after an operation
1181 // completes and runs its callback. 1177 // completes and runs its callback.
1182 int rv = backend_->CalculateSizeOfAllEntries(base::Bind( 1178 int rv = backend_->CalculateSizeOfAllEntries(
1183 &CacheStorageCache::UpdateCacheSizeGotSize, 1179 base::Bind(&CacheStorageCache::UpdateCacheSizeGotSize,
1184 weak_ptr_factory_.GetWeakPtr(), base::Passed(CreateCacheHandle()))); 1180 weak_ptr_factory_.GetWeakPtr(),
1181 base::Passed(CreateCacheHandle()), callback));
1185 1182
1186 if (rv != net::ERR_IO_PENDING) 1183 if (rv != net::ERR_IO_PENDING)
1187 UpdateCacheSizeGotSize(CreateCacheHandle(), rv); 1184 UpdateCacheSizeGotSize(CreateCacheHandle(), callback, rv);
1188 } 1185 }
1189 1186
1190 void CacheStorageCache::UpdateCacheSizeGotSize( 1187 void CacheStorageCache::UpdateCacheSizeGotSize(
1191 std::unique_ptr<CacheStorageCacheHandle> cache_handle, 1188 std::unique_ptr<CacheStorageCacheHandle> cache_handle,
1189 const base::Closure& callback,
1192 int current_cache_size) { 1190 int current_cache_size) {
1193 DCHECK_NE(current_cache_size, CacheStorage::kSizeUnknown); 1191 DCHECK_NE(current_cache_size, CacheStorage::kSizeUnknown);
1194 int64_t old_cache_size = cache_size_; 1192 int64_t old_cache_size = cache_size_;
1195 cache_size_ = current_cache_size; 1193 cache_size_ = current_cache_size;
1196 1194
1197 int64_t size_delta = current_cache_size - old_cache_size; 1195 int64_t size_delta = current_cache_size - old_cache_size;
1198 1196
1199 quota_manager_proxy_->NotifyStorageModified( 1197 quota_manager_proxy_->NotifyStorageModified(
1200 storage::QuotaClient::kServiceWorkerCache, origin_, 1198 storage::QuotaClient::kServiceWorkerCache, origin_,
1201 storage::kStorageTypeTemporary, size_delta); 1199 storage::kStorageTypeTemporary, size_delta);
1202 1200
1203 if (cache_observer_) 1201 if (cache_observer_)
1204 cache_observer_->CacheSizeUpdated(this, current_cache_size); 1202 cache_observer_->CacheSizeUpdated(this, current_cache_size);
1203
1204 callback.Run();
1205 } 1205 }
1206 1206
1207 void CacheStorageCache::Delete(const CacheStorageBatchOperation& operation, 1207 void CacheStorageCache::Delete(const CacheStorageBatchOperation& operation,
1208 const ErrorCallback& callback) { 1208 const ErrorCallback& callback) {
1209 DCHECK(BACKEND_OPEN == backend_state_ || initializing_); 1209 DCHECK(BACKEND_OPEN == backend_state_ || initializing_);
1210 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE, 1210 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE,
1211 operation.operation_type); 1211 operation.operation_type);
1212 1212
1213 std::unique_ptr<ServiceWorkerFetchRequest> request( 1213 std::unique_ptr<ServiceWorkerFetchRequest> request(
1214 new ServiceWorkerFetchRequest( 1214 new ServiceWorkerFetchRequest(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 if (query_cache_results->empty()) { 1249 if (query_cache_results->empty()) {
1250 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND); 1250 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND);
1251 return; 1251 return;
1252 } 1252 }
1253 1253
1254 for (auto& result : *query_cache_results) { 1254 for (auto& result : *query_cache_results) {
1255 disk_cache::ScopedEntryPtr entry = std::move(result.entry); 1255 disk_cache::ScopedEntryPtr entry = std::move(result.entry);
1256 entry->Doom(); 1256 entry->Doom();
1257 } 1257 }
1258 1258
1259 UpdateCacheSize(); 1259 UpdateCacheSize(base::Bind(callback, CACHE_STORAGE_OK));
1260 callback.Run(CACHE_STORAGE_OK);
1261 } 1260 }
1262 1261
1263 void CacheStorageCache::KeysImpl( 1262 void CacheStorageCache::KeysImpl(
1264 std::unique_ptr<ServiceWorkerFetchRequest> request, 1263 std::unique_ptr<ServiceWorkerFetchRequest> request,
1265 const CacheStorageCacheQueryParams& options, 1264 const CacheStorageCacheQueryParams& options,
1266 const RequestsCallback& callback) { 1265 const RequestsCallback& callback) {
1267 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 1266 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
1268 if (backend_state_ != BACKEND_OPEN) { 1267 if (backend_state_ != BACKEND_OPEN) {
1269 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>()); 1268 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>());
1270 return; 1269 return;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); 1480 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA);
1482 return blob_storage_context_->AddFinishedBlob(&blob_data); 1481 return blob_storage_context_->AddFinishedBlob(&blob_data);
1483 } 1482 }
1484 1483
1485 std::unique_ptr<CacheStorageCacheHandle> 1484 std::unique_ptr<CacheStorageCacheHandle>
1486 CacheStorageCache::CreateCacheHandle() { 1485 CacheStorageCache::CreateCacheHandle() {
1487 return cache_storage_->CreateCacheHandle(this); 1486 return cache_storage_->CreateCacheHandle(this);
1488 } 1487 }
1489 1488
1490 } // namespace content 1489 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698