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

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

Issue 1681653002: [CacheStorage] Use backend size to determine change in cache size in put and delete (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Delta from last report Created 4 years, 10 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 <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 scoped_ptr<CacheMetadata> metadata(new CacheMetadata()); 173 scoped_ptr<CacheMetadata> metadata(new CacheMetadata());
174 174
175 if (!metadata->ParseFromArray(buffer->data(), buffer->size())) { 175 if (!metadata->ParseFromArray(buffer->data(), buffer->size())) {
176 callback.Run(scoped_ptr<CacheMetadata>()); 176 callback.Run(scoped_ptr<CacheMetadata>());
177 return; 177 return;
178 } 178 }
179 179
180 callback.Run(std::move(metadata)); 180 callback.Run(std::move(metadata));
181 } 181 }
182 182
183 void SizeDidGetCacheSize(const CacheStorageCache::SizeCallback& callback,
184 int size) {
185 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
186 base::Bind(callback, size));
187 }
188
189 } // namespace 183 } // namespace
190 184
191 // The state needed to iterate all entries in the cache. 185 // The state needed to iterate all entries in the cache.
192 struct CacheStorageCache::OpenAllEntriesContext { 186 struct CacheStorageCache::OpenAllEntriesContext {
193 OpenAllEntriesContext() : enumerated_entry(nullptr) {} 187 OpenAllEntriesContext() : enumerated_entry(nullptr) {}
194 ~OpenAllEntriesContext() { 188 ~OpenAllEntriesContext() {
195 for (size_t i = 0, max = entries.size(); i < max; ++i) { 189 for (size_t i = 0, max = entries.size(); i < max; ++i) {
196 if (entries[i]) 190 if (entries[i])
197 entries[i]->Close(); 191 entries[i]->Close();
198 } 192 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 241
248 // The context holding open entries. 242 // The context holding open entries.
249 scoped_ptr<OpenAllEntriesContext> entries_context; 243 scoped_ptr<OpenAllEntriesContext> entries_context;
250 244
251 private: 245 private:
252 DISALLOW_COPY_AND_ASSIGN(KeysContext); 246 DISALLOW_COPY_AND_ASSIGN(KeysContext);
253 }; 247 };
254 248
255 // The state needed to pass between CacheStorageCache::Put callbacks. 249 // The state needed to pass between CacheStorageCache::Put callbacks.
256 struct CacheStorageCache::PutContext { 250 struct CacheStorageCache::PutContext {
257 PutContext( 251 PutContext(scoped_ptr<ServiceWorkerFetchRequest> request,
258 const GURL& origin, 252 scoped_ptr<ServiceWorkerResponse> response,
259 scoped_ptr<ServiceWorkerFetchRequest> request, 253 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
260 scoped_ptr<ServiceWorkerResponse> response, 254 const CacheStorageCache::ErrorCallback& callback)
261 scoped_ptr<storage::BlobDataHandle> blob_data_handle, 255 : request(std::move(request)),
michaeln 2016/02/12 02:06:04 nice that this got simpler!
262 const CacheStorageCache::ErrorCallback& callback,
263 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
264 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy)
265 : origin(origin),
266 request(std::move(request)),
267 response(std::move(response)), 256 response(std::move(response)),
268 blob_data_handle(std::move(blob_data_handle)), 257 blob_data_handle(std::move(blob_data_handle)),
269 callback(callback), 258 callback(callback) {}
270 request_context_getter(request_context_getter),
271 quota_manager_proxy(quota_manager_proxy) {}
272 259
273 // Input parameters to the Put function. 260 // Input parameters to the Put function.
274 GURL origin;
275 scoped_ptr<ServiceWorkerFetchRequest> request; 261 scoped_ptr<ServiceWorkerFetchRequest> request;
276 scoped_ptr<ServiceWorkerResponse> response; 262 scoped_ptr<ServiceWorkerResponse> response;
277 scoped_ptr<storage::BlobDataHandle> blob_data_handle; 263 scoped_ptr<storage::BlobDataHandle> blob_data_handle;
278 CacheStorageCache::ErrorCallback callback; 264 CacheStorageCache::ErrorCallback callback;
279 scoped_refptr<net::URLRequestContextGetter> request_context_getter;
280 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy;
281 disk_cache::ScopedEntryPtr cache_entry; 265 disk_cache::ScopedEntryPtr cache_entry;
282 int64_t available_bytes = 0; 266 int64_t available_bytes = 0;
283 267
284 private: 268 private:
285 DISALLOW_COPY_AND_ASSIGN(PutContext); 269 DISALLOW_COPY_AND_ASSIGN(PutContext);
286 }; 270 };
287 271
288 // static 272 // static
289 scoped_refptr<CacheStorageCache> CacheStorageCache::CreateMemoryCache( 273 scoped_refptr<CacheStorageCache> CacheStorageCache::CreateMemoryCache(
290 const GURL& origin, 274 const GURL& origin,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 const GURL& origin, 444 const GURL& origin,
461 const base::FilePath& path, 445 const base::FilePath& path,
462 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 446 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
463 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 447 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
464 base::WeakPtr<storage::BlobStorageContext> blob_context) 448 base::WeakPtr<storage::BlobStorageContext> blob_context)
465 : origin_(origin), 449 : origin_(origin),
466 path_(path), 450 path_(path),
467 request_context_getter_(request_context_getter), 451 request_context_getter_(request_context_getter),
468 quota_manager_proxy_(quota_manager_proxy), 452 quota_manager_proxy_(quota_manager_proxy),
469 blob_storage_context_(blob_context), 453 blob_storage_context_(blob_context),
470 backend_state_(BACKEND_UNINITIALIZED),
471 scheduler_(new CacheStorageScheduler()), 454 scheduler_(new CacheStorageScheduler()),
472 initializing_(false),
473 memory_only_(path.empty()), 455 memory_only_(path.empty()),
474 weak_ptr_factory_(this) { 456 weak_ptr_factory_(this) {
475 } 457 }
476 458
477 bool CacheStorageCache::LazyInitialize() { 459 bool CacheStorageCache::LazyInitialize() {
478 switch (backend_state_) { 460 switch (backend_state_) {
479 case BACKEND_UNINITIALIZED: 461 case BACKEND_UNINITIALIZED:
480 InitBackend(); 462 InitBackend();
481 return true; 463 return true;
482 case BACKEND_CLOSED: 464 case BACKEND_CLOSED:
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 callback.Run(CACHE_STORAGE_ERROR_STORAGE); 738 callback.Run(CACHE_STORAGE_ERROR_STORAGE);
757 return; 739 return;
758 } 740 }
759 } 741 }
760 742
761 ErrorCallback pending_callback = 743 ErrorCallback pending_callback =
762 base::Bind(&CacheStorageCache::PendingErrorCallback, 744 base::Bind(&CacheStorageCache::PendingErrorCallback,
763 weak_ptr_factory_.GetWeakPtr(), callback); 745 weak_ptr_factory_.GetWeakPtr(), callback);
764 746
765 scoped_ptr<PutContext> put_context( 747 scoped_ptr<PutContext> put_context(
766 new PutContext(origin_, std::move(request), std::move(response), 748 new PutContext(std::move(request), std::move(response),
767 std::move(blob_data_handle), pending_callback, 749 std::move(blob_data_handle), pending_callback));
768 request_context_getter_, quota_manager_proxy_));
769 750
770 scheduler_->ScheduleOperation( 751 scheduler_->ScheduleOperation(
771 base::Bind(&CacheStorageCache::PutImpl, weak_ptr_factory_.GetWeakPtr(), 752 base::Bind(&CacheStorageCache::PutImpl, weak_ptr_factory_.GetWeakPtr(),
772 base::Passed(std::move(put_context)))); 753 base::Passed(std::move(put_context))));
773 } 754 }
774 755
775 void CacheStorageCache::PutImpl(scoped_ptr<PutContext> put_context) { 756 void CacheStorageCache::PutImpl(scoped_ptr<PutContext> put_context) {
776 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 757 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
777 if (backend_state_ != BACKEND_OPEN) { 758 if (backend_state_ != BACKEND_OPEN) {
778 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); 759 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 if (rv != expected_bytes) { 894 if (rv != expected_bytes) {
914 put_context->cache_entry->Doom(); 895 put_context->cache_entry->Doom();
915 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); 896 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE);
916 return; 897 return;
917 } 898 }
918 899
919 // The metadata is written, now for the response content. The data is streamed 900 // The metadata is written, now for the response content. The data is streamed
920 // from the blob into the cache entry. 901 // from the blob into the cache entry.
921 902
922 if (put_context->response->blob_uuid.empty()) { 903 if (put_context->response->blob_uuid.empty()) {
923 if (put_context->quota_manager_proxy.get()) { 904 UpdateCacheSize(base::Bind(put_context->callback, CACHE_STORAGE_OK));
924 put_context->quota_manager_proxy->NotifyStorageModified(
925 storage::QuotaClient::kServiceWorkerCache, put_context->origin,
926 storage::kStorageTypeTemporary,
927 put_context->cache_entry->GetDataSize(INDEX_HEADERS));
928 }
929
930 put_context->callback.Run(CACHE_STORAGE_OK);
931 return; 905 return;
932 } 906 }
933 907
934 DCHECK(put_context->blob_data_handle); 908 DCHECK(put_context->blob_data_handle);
935 909
936 disk_cache::ScopedEntryPtr entry(std::move(put_context->cache_entry)); 910 disk_cache::ScopedEntryPtr entry(std::move(put_context->cache_entry));
937 put_context->cache_entry = NULL; 911 put_context->cache_entry = NULL;
938 912
939 CacheStorageBlobToDiskCache* blob_to_cache = 913 CacheStorageBlobToDiskCache* blob_to_cache =
940 new CacheStorageBlobToDiskCache(); 914 new CacheStorageBlobToDiskCache();
941 BlobToDiskCacheIDMap::KeyType blob_to_cache_key = 915 BlobToDiskCacheIDMap::KeyType blob_to_cache_key =
942 active_blob_to_disk_cache_writers_.Add(blob_to_cache); 916 active_blob_to_disk_cache_writers_.Add(blob_to_cache);
943 917
944 // Grab some pointers before passing put_context in Bind.
945 scoped_refptr<net::URLRequestContextGetter> request_context_getter =
946 put_context->request_context_getter;
947 scoped_ptr<storage::BlobDataHandle> blob_data_handle = 918 scoped_ptr<storage::BlobDataHandle> blob_data_handle =
948 std::move(put_context->blob_data_handle); 919 std::move(put_context->blob_data_handle);
949 920
950 blob_to_cache->StreamBlobToCache( 921 blob_to_cache->StreamBlobToCache(
951 std::move(entry), INDEX_RESPONSE_BODY, request_context_getter, 922 std::move(entry), INDEX_RESPONSE_BODY, request_context_getter_,
952 std::move(blob_data_handle), 923 std::move(blob_data_handle),
953 base::Bind(&CacheStorageCache::PutDidWriteBlobToCache, 924 base::Bind(&CacheStorageCache::PutDidWriteBlobToCache,
954 weak_ptr_factory_.GetWeakPtr(), 925 weak_ptr_factory_.GetWeakPtr(),
955 base::Passed(std::move(put_context)), blob_to_cache_key)); 926 base::Passed(std::move(put_context)), blob_to_cache_key));
956 } 927 }
957 928
958 void CacheStorageCache::PutDidWriteBlobToCache( 929 void CacheStorageCache::PutDidWriteBlobToCache(
959 scoped_ptr<PutContext> put_context, 930 scoped_ptr<PutContext> put_context,
960 BlobToDiskCacheIDMap::KeyType blob_to_cache_key, 931 BlobToDiskCacheIDMap::KeyType blob_to_cache_key,
961 disk_cache::ScopedEntryPtr entry, 932 disk_cache::ScopedEntryPtr entry,
962 bool success) { 933 bool success) {
963 DCHECK(entry); 934 DCHECK(entry);
964 put_context->cache_entry = std::move(entry); 935 put_context->cache_entry = std::move(entry);
965 936
966 active_blob_to_disk_cache_writers_.Remove(blob_to_cache_key); 937 active_blob_to_disk_cache_writers_.Remove(blob_to_cache_key);
967 938
968 if (!success) { 939 if (!success) {
969 put_context->cache_entry->Doom(); 940 put_context->cache_entry->Doom();
970 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); 941 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE);
971 return; 942 return;
972 } 943 }
973 944
974 if (put_context->quota_manager_proxy.get()) { 945 UpdateCacheSize(base::Bind(put_context->callback, CACHE_STORAGE_OK));
975 put_context->quota_manager_proxy->NotifyStorageModified( 946 }
976 storage::QuotaClient::kServiceWorkerCache, put_context->origin, 947
977 storage::kStorageTypeTemporary, 948 void CacheStorageCache::UpdateCacheSize(const base::Closure& callback) {
978 put_context->cache_entry->GetDataSize(INDEX_HEADERS) + 949 if (backend_state_ != BACKEND_OPEN) {
979 put_context->cache_entry->GetDataSize(INDEX_RESPONSE_BODY)); 950 callback.Run();
951 return;
980 } 952 }
981 953
982 put_context->callback.Run(CACHE_STORAGE_OK); 954 int rv = backend_->CalculateSizeOfAllEntries(
955 base::Bind(&CacheStorageCache::UpdateCacheSizeGotSize,
956 weak_ptr_factory_.GetWeakPtr(), callback));
957
958 if (rv != net::ERR_IO_PENDING)
959 UpdateCacheSizeGotSize(callback, rv);
960 }
961
962 void CacheStorageCache::UpdateCacheSizeGotSize(const base::Closure& callback,
963 int current_cache_size) {
964 int64_t old_cache_size = cache_size_;
965 cache_size_ = current_cache_size;
966
967 quota_manager_proxy_->NotifyStorageModified(
968 storage::QuotaClient::kServiceWorkerCache, origin_,
969 storage::kStorageTypeTemporary, current_cache_size - old_cache_size);
970
971 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
983 } 972 }
984 973
985 void CacheStorageCache::Delete(const CacheStorageBatchOperation& operation, 974 void CacheStorageCache::Delete(const CacheStorageBatchOperation& operation,
986 const ErrorCallback& callback) { 975 const ErrorCallback& callback) {
987 DCHECK(BACKEND_OPEN == backend_state_ || initializing_); 976 DCHECK(BACKEND_OPEN == backend_state_ || initializing_);
988 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE, 977 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE,
989 operation.operation_type); 978 operation.operation_type);
990 979
991 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( 980 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest(
992 operation.request.url, operation.request.method, 981 operation.request.url, operation.request.method,
(...skipping 18 matching lines...) Expand all
1011 } 1000 }
1012 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); 1001 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*);
1013 1002
1014 disk_cache::Entry** entry_ptr = entry.get(); 1003 disk_cache::Entry** entry_ptr = entry.get();
1015 1004
1016 ServiceWorkerFetchRequest* request_ptr = request.get(); 1005 ServiceWorkerFetchRequest* request_ptr = request.get();
1017 1006
1018 net::CompletionCallback open_entry_callback = base::Bind( 1007 net::CompletionCallback open_entry_callback = base::Bind(
1019 &CacheStorageCache::DeleteDidOpenEntry, weak_ptr_factory_.GetWeakPtr(), 1008 &CacheStorageCache::DeleteDidOpenEntry, weak_ptr_factory_.GetWeakPtr(),
1020 origin_, base::Passed(std::move(request)), callback, 1009 origin_, base::Passed(std::move(request)), callback,
1021 base::Passed(std::move(entry)), quota_manager_proxy_); 1010 base::Passed(std::move(entry)));
1022 1011
1023 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, 1012 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr,
1024 open_entry_callback); 1013 open_entry_callback);
1025 if (rv != net::ERR_IO_PENDING) 1014 if (rv != net::ERR_IO_PENDING)
1026 open_entry_callback.Run(rv); 1015 open_entry_callback.Run(rv);
1027 } 1016 }
1028 1017
1029 void CacheStorageCache::DeleteDidOpenEntry( 1018 void CacheStorageCache::DeleteDidOpenEntry(
1030 const GURL& origin, 1019 const GURL& origin,
1031 scoped_ptr<ServiceWorkerFetchRequest> request, 1020 scoped_ptr<ServiceWorkerFetchRequest> request,
1032 const CacheStorageCache::ErrorCallback& callback, 1021 const CacheStorageCache::ErrorCallback& callback,
1033 scoped_ptr<disk_cache::Entry*> entry_ptr, 1022 scoped_ptr<disk_cache::Entry*> entry_ptr,
1034 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
1035 int rv) { 1023 int rv) {
1036 if (rv != net::OK) { 1024 if (rv != net::OK) {
1037 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND); 1025 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND);
1038 return; 1026 return;
1039 } 1027 }
1040 1028
1041 DCHECK(entry_ptr); 1029 DCHECK(entry_ptr);
1042 disk_cache::ScopedEntryPtr entry(*entry_ptr); 1030 disk_cache::ScopedEntryPtr entry(*entry_ptr);
1043 1031
1044 if (quota_manager_proxy.get()) { 1032 entry->Doom();
1045 quota_manager_proxy->NotifyStorageModified( 1033 entry.reset();
1046 storage::QuotaClient::kServiceWorkerCache, origin,
1047 storage::kStorageTypeTemporary,
1048 -1 * (entry->GetDataSize(INDEX_HEADERS) +
1049 entry->GetDataSize(INDEX_RESPONSE_BODY)));
1050 }
1051 1034
1052 entry->Doom(); 1035 UpdateCacheSize(base::Bind(callback, CACHE_STORAGE_OK));
michaeln 2016/02/12 02:06:04 Do you have to defer completing the put|delete ope
jkarlin 2016/02/12 16:33:12 Done. I didn't earlier because I was concerned abo
1053 callback.Run(CACHE_STORAGE_OK);
1054 } 1036 }
1055 1037
1056 void CacheStorageCache::KeysImpl(const RequestsCallback& callback) { 1038 void CacheStorageCache::KeysImpl(const RequestsCallback& callback) {
1057 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 1039 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
1058 if (backend_state_ != BACKEND_OPEN) { 1040 if (backend_state_ != BACKEND_OPEN) {
1059 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Requests>()); 1041 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Requests>());
1060 return; 1042 return;
1061 } 1043 }
1062 1044
1063 // 1. Iterate through all of the entries, open them, and add them to a vector. 1045 // 1. Iterate through all of the entries, open them, and add them to a vector.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 DCHECK_NE(BACKEND_CLOSED, backend_state_); 1117 DCHECK_NE(BACKEND_CLOSED, backend_state_);
1136 1118
1137 backend_state_ = BACKEND_CLOSED; 1119 backend_state_ = BACKEND_CLOSED;
1138 backend_.reset(); 1120 backend_.reset();
1139 callback.Run(); 1121 callback.Run();
1140 } 1122 }
1141 1123
1142 void CacheStorageCache::SizeImpl(const SizeCallback& callback) { 1124 void CacheStorageCache::SizeImpl(const SizeCallback& callback) {
1143 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 1125 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
1144 1126
1145 if (backend_state_ != BACKEND_OPEN) { 1127 int64_t size = backend_state_ == BACKEND_OPEN ? cache_size_ : 0;
1146 // Backend is closed for deletion, don't count its size. 1128 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
1147 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 1129 base::Bind(callback, size));
1148 base::Bind(callback, 0));
1149 return;
1150 }
1151
1152 int rv = backend_->CalculateSizeOfAllEntries(
1153 base::Bind(&SizeDidGetCacheSize, callback));
1154 if (rv != net::ERR_IO_PENDING)
1155 SizeDidGetCacheSize(callback, rv);
1156 } 1130 }
1157 1131
1158 void CacheStorageCache::CreateBackend(const ErrorCallback& callback) { 1132 void CacheStorageCache::CreateBackend(const ErrorCallback& callback) {
1159 DCHECK(!backend_); 1133 DCHECK(!backend_);
1160 1134
1161 // Use APP_CACHE as opposed to DISK_CACHE to prevent cache eviction. 1135 // Use APP_CACHE as opposed to DISK_CACHE to prevent cache eviction.
1162 net::CacheType cache_type = memory_only_ ? net::MEMORY_CACHE : net::APP_CACHE; 1136 net::CacheType cache_type = memory_only_ ? net::MEMORY_CACHE : net::APP_CACHE;
1163 1137
1164 scoped_ptr<ScopedBackendPtr> backend_ptr(new ScopedBackendPtr()); 1138 scoped_ptr<ScopedBackendPtr> backend_ptr(new ScopedBackendPtr());
1165 1139
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 DCHECK_EQ(BACKEND_UNINITIALIZED, backend_state_); 1173 DCHECK_EQ(BACKEND_UNINITIALIZED, backend_state_);
1200 1174
1201 if (initializing_) 1175 if (initializing_)
1202 return; 1176 return;
1203 1177
1204 DCHECK(!scheduler_->ScheduledOperations()); 1178 DCHECK(!scheduler_->ScheduledOperations());
1205 initializing_ = true; 1179 initializing_ = true;
1206 1180
1207 scheduler_->ScheduleOperation(base::Bind( 1181 scheduler_->ScheduleOperation(base::Bind(
1208 &CacheStorageCache::CreateBackend, weak_ptr_factory_.GetWeakPtr(), 1182 &CacheStorageCache::CreateBackend, weak_ptr_factory_.GetWeakPtr(),
1209 base::Bind(&CacheStorageCache::InitDone, 1183 base::Bind(&CacheStorageCache::InitDidCreateBackend,
1210 weak_ptr_factory_.GetWeakPtr()))); 1184 weak_ptr_factory_.GetWeakPtr())));
1211 } 1185 }
1212 1186
1213 void CacheStorageCache::InitDone(CacheStorageError error) { 1187 void CacheStorageCache::InitDidCreateBackend(
1188 CacheStorageError cache_create_error) {
1189 if (cache_create_error != CACHE_STORAGE_OK) {
1190 InitGotCacheSize(cache_create_error, 0);
1191 return;
1192 }
1193
1194 int rv = backend_->CalculateSizeOfAllEntries(
1195 base::Bind(&CacheStorageCache::InitGotCacheSize,
1196 weak_ptr_factory_.GetWeakPtr(), cache_create_error));
1197
1198 if (rv != net::ERR_IO_PENDING)
1199 InitGotCacheSize(cache_create_error, rv);
1200 }
1201
1202 void CacheStorageCache::InitGotCacheSize(CacheStorageError cache_create_error,
1203 int cache_size) {
1204 cache_size_ = cache_size;
1214 initializing_ = false; 1205 initializing_ = false;
1215 backend_state_ = (error == CACHE_STORAGE_OK && backend_ && 1206 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ &&
1216 backend_state_ == BACKEND_UNINITIALIZED) 1207 backend_state_ == BACKEND_UNINITIALIZED)
1217 ? BACKEND_OPEN 1208 ? BACKEND_OPEN
1218 : BACKEND_CLOSED; 1209 : BACKEND_CLOSED;
1219 1210
1220 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult", error, 1211 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult",
1221 CACHE_STORAGE_ERROR_LAST + 1); 1212 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1);
1222 1213
1223 scheduler_->CompleteOperationAndRunNext(); 1214 scheduler_->CompleteOperationAndRunNext();
1224 } 1215 }
1225 1216
1226 void CacheStorageCache::PendingClosure(const base::Closure& callback) { 1217 void CacheStorageCache::PendingClosure(const base::Closure& callback) {
1227 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); 1218 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr();
1228 1219
1229 callback.Run(); 1220 callback.Run();
1230 if (cache) 1221 if (cache)
1231 scheduler_->CompleteOperationAndRunNext(); 1222 scheduler_->CompleteOperationAndRunNext();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 storage::BlobDataBuilder blob_data(response->blob_uuid); 1304 storage::BlobDataBuilder blob_data(response->blob_uuid);
1314 1305
1315 disk_cache::Entry* temp_entry = entry.get(); 1306 disk_cache::Entry* temp_entry = entry.get();
1316 blob_data.AppendDiskCacheEntry( 1307 blob_data.AppendDiskCacheEntry(
1317 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, 1308 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry,
1318 INDEX_RESPONSE_BODY); 1309 INDEX_RESPONSE_BODY);
1319 return blob_storage_context_->AddFinishedBlob(&blob_data); 1310 return blob_storage_context_->AddFinishedBlob(&blob_data);
1320 } 1311 }
1321 1312
1322 } // namespace content 1313 } // 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