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

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: Rebase 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
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)),
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 base::ThreadTaskRunnerHandle::Get()->PostTask(
924 put_context->quota_manager_proxy->NotifyStorageModified( 905 FROM_HERE, base::Bind(put_context->callback, CACHE_STORAGE_OK));
michaeln 2016/02/12 20:16:53 at first i didn't understand why you wanted the Po
jkarlin 2016/02/12 20:25:49 yes
jkarlin 2016/02/12 20:28:29 By that I meant generally safer. In this case I do
925 storage::QuotaClient::kServiceWorkerCache, put_context->origin, 906 UpdateCacheSize();
926 storage::kStorageTypeTemporary,
927 put_context->cache_entry->GetDataSize(INDEX_HEADERS));
928 }
929
930 put_context->callback.Run(CACHE_STORAGE_OK);
931 return; 907 return;
932 } 908 }
933 909
934 DCHECK(put_context->blob_data_handle); 910 DCHECK(put_context->blob_data_handle);
935 911
936 disk_cache::ScopedEntryPtr entry(std::move(put_context->cache_entry)); 912 disk_cache::ScopedEntryPtr entry(std::move(put_context->cache_entry));
937 put_context->cache_entry = NULL; 913 put_context->cache_entry = NULL;
938 914
939 CacheStorageBlobToDiskCache* blob_to_cache = 915 CacheStorageBlobToDiskCache* blob_to_cache =
940 new CacheStorageBlobToDiskCache(); 916 new CacheStorageBlobToDiskCache();
941 BlobToDiskCacheIDMap::KeyType blob_to_cache_key = 917 BlobToDiskCacheIDMap::KeyType blob_to_cache_key =
942 active_blob_to_disk_cache_writers_.Add(blob_to_cache); 918 active_blob_to_disk_cache_writers_.Add(blob_to_cache);
943 919
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 = 920 scoped_ptr<storage::BlobDataHandle> blob_data_handle =
948 std::move(put_context->blob_data_handle); 921 std::move(put_context->blob_data_handle);
949 922
950 blob_to_cache->StreamBlobToCache( 923 blob_to_cache->StreamBlobToCache(
951 std::move(entry), INDEX_RESPONSE_BODY, request_context_getter, 924 std::move(entry), INDEX_RESPONSE_BODY, request_context_getter_,
952 std::move(blob_data_handle), 925 std::move(blob_data_handle),
953 base::Bind(&CacheStorageCache::PutDidWriteBlobToCache, 926 base::Bind(&CacheStorageCache::PutDidWriteBlobToCache,
954 weak_ptr_factory_.GetWeakPtr(), 927 weak_ptr_factory_.GetWeakPtr(),
955 base::Passed(std::move(put_context)), blob_to_cache_key)); 928 base::Passed(std::move(put_context)), blob_to_cache_key));
956 } 929 }
957 930
958 void CacheStorageCache::PutDidWriteBlobToCache( 931 void CacheStorageCache::PutDidWriteBlobToCache(
959 scoped_ptr<PutContext> put_context, 932 scoped_ptr<PutContext> put_context,
960 BlobToDiskCacheIDMap::KeyType blob_to_cache_key, 933 BlobToDiskCacheIDMap::KeyType blob_to_cache_key,
961 disk_cache::ScopedEntryPtr entry, 934 disk_cache::ScopedEntryPtr entry,
962 bool success) { 935 bool success) {
963 DCHECK(entry); 936 DCHECK(entry);
964 put_context->cache_entry = std::move(entry); 937 put_context->cache_entry = std::move(entry);
965 938
966 active_blob_to_disk_cache_writers_.Remove(blob_to_cache_key); 939 active_blob_to_disk_cache_writers_.Remove(blob_to_cache_key);
967 940
968 if (!success) { 941 if (!success) {
969 put_context->cache_entry->Doom(); 942 put_context->cache_entry->Doom();
970 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); 943 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE);
971 return; 944 return;
972 } 945 }
973 946
974 if (put_context->quota_manager_proxy.get()) { 947 base::ThreadTaskRunnerHandle::Get()->PostTask(
975 put_context->quota_manager_proxy->NotifyStorageModified( 948 FROM_HERE, base::Bind(put_context->callback, CACHE_STORAGE_OK));
976 storage::QuotaClient::kServiceWorkerCache, put_context->origin, 949 UpdateCacheSize();
977 storage::kStorageTypeTemporary, 950 }
978 put_context->cache_entry->GetDataSize(INDEX_HEADERS) +
979 put_context->cache_entry->GetDataSize(INDEX_RESPONSE_BODY));
980 }
981 951
982 put_context->callback.Run(CACHE_STORAGE_OK); 952 void CacheStorageCache::UpdateCacheSize() {
953 if (backend_state_ != BACKEND_OPEN)
954 return;
955
956 // Note that the callback holds a refptr to |this| since UpdateCacheSize is
957 // often called after an operation completes and the cache might be freed.
958 int rv = backend_->CalculateSizeOfAllEntries(
michaeln 2016/02/12 20:16:53 i was wondering how expensive this was in the back
jkarlin 2016/02/12 20:25:49 Definitely. It does posttask to get there though.
959 base::Bind(&CacheStorageCache::UpdateCacheSizeGotSize, this));
960
961 if (rv != net::ERR_IO_PENDING)
962 UpdateCacheSizeGotSize(rv);
963 }
964
965 void CacheStorageCache::UpdateCacheSizeGotSize(int current_cache_size) {
966 int64_t old_cache_size = cache_size_;
967 cache_size_ = current_cache_size;
968
969 quota_manager_proxy_->NotifyStorageModified(
970 storage::QuotaClient::kServiceWorkerCache, origin_,
971 storage::kStorageTypeTemporary, current_cache_size - old_cache_size);
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 base::ThreadTaskRunnerHandle::Get()->PostTask(
1053 callback.Run(CACHE_STORAGE_OK); 1036 FROM_HERE, base::Bind(callback, CACHE_STORAGE_OK));
1037 UpdateCacheSize();
1054 } 1038 }
1055 1039
1056 void CacheStorageCache::KeysImpl(const RequestsCallback& callback) { 1040 void CacheStorageCache::KeysImpl(const RequestsCallback& callback) {
1057 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 1041 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
1058 if (backend_state_ != BACKEND_OPEN) { 1042 if (backend_state_ != BACKEND_OPEN) {
1059 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Requests>()); 1043 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Requests>());
1060 return; 1044 return;
1061 } 1045 }
1062 1046
1063 // 1. Iterate through all of the entries, open them, and add them to a vector. 1047 // 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_); 1119 DCHECK_NE(BACKEND_CLOSED, backend_state_);
1136 1120
1137 backend_state_ = BACKEND_CLOSED; 1121 backend_state_ = BACKEND_CLOSED;
1138 backend_.reset(); 1122 backend_.reset();
1139 callback.Run(); 1123 callback.Run();
1140 } 1124 }
1141 1125
1142 void CacheStorageCache::SizeImpl(const SizeCallback& callback) { 1126 void CacheStorageCache::SizeImpl(const SizeCallback& callback) {
1143 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 1127 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
1144 1128
1145 if (backend_state_ != BACKEND_OPEN) { 1129 int64_t size = backend_state_ == BACKEND_OPEN ? cache_size_ : 0;
1146 // Backend is closed for deletion, don't count its size. 1130 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
1147 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 1131 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 } 1132 }
1157 1133
1158 void CacheStorageCache::CreateBackend(const ErrorCallback& callback) { 1134 void CacheStorageCache::CreateBackend(const ErrorCallback& callback) {
1159 DCHECK(!backend_); 1135 DCHECK(!backend_);
1160 1136
1161 // Use APP_CACHE as opposed to DISK_CACHE to prevent cache eviction. 1137 // 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; 1138 net::CacheType cache_type = memory_only_ ? net::MEMORY_CACHE : net::APP_CACHE;
1163 1139
1164 scoped_ptr<ScopedBackendPtr> backend_ptr(new ScopedBackendPtr()); 1140 scoped_ptr<ScopedBackendPtr> backend_ptr(new ScopedBackendPtr());
1165 1141
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 DCHECK_EQ(BACKEND_UNINITIALIZED, backend_state_); 1175 DCHECK_EQ(BACKEND_UNINITIALIZED, backend_state_);
1200 1176
1201 if (initializing_) 1177 if (initializing_)
1202 return; 1178 return;
1203 1179
1204 DCHECK(!scheduler_->ScheduledOperations()); 1180 DCHECK(!scheduler_->ScheduledOperations());
1205 initializing_ = true; 1181 initializing_ = true;
1206 1182
1207 scheduler_->ScheduleOperation(base::Bind( 1183 scheduler_->ScheduleOperation(base::Bind(
1208 &CacheStorageCache::CreateBackend, weak_ptr_factory_.GetWeakPtr(), 1184 &CacheStorageCache::CreateBackend, weak_ptr_factory_.GetWeakPtr(),
1209 base::Bind(&CacheStorageCache::InitDone, 1185 base::Bind(&CacheStorageCache::InitDidCreateBackend,
1210 weak_ptr_factory_.GetWeakPtr()))); 1186 weak_ptr_factory_.GetWeakPtr())));
1211 } 1187 }
1212 1188
1213 void CacheStorageCache::InitDone(CacheStorageError error) { 1189 void CacheStorageCache::InitDidCreateBackend(
1190 CacheStorageError cache_create_error) {
1191 if (cache_create_error != CACHE_STORAGE_OK) {
1192 InitGotCacheSize(cache_create_error, 0);
1193 return;
1194 }
1195
1196 int rv = backend_->CalculateSizeOfAllEntries(
1197 base::Bind(&CacheStorageCache::InitGotCacheSize,
1198 weak_ptr_factory_.GetWeakPtr(), cache_create_error));
1199
1200 if (rv != net::ERR_IO_PENDING)
1201 InitGotCacheSize(cache_create_error, rv);
1202 }
1203
1204 void CacheStorageCache::InitGotCacheSize(CacheStorageError cache_create_error,
1205 int cache_size) {
1206 cache_size_ = cache_size;
1214 initializing_ = false; 1207 initializing_ = false;
1215 backend_state_ = (error == CACHE_STORAGE_OK && backend_ && 1208 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ &&
1216 backend_state_ == BACKEND_UNINITIALIZED) 1209 backend_state_ == BACKEND_UNINITIALIZED)
1217 ? BACKEND_OPEN 1210 ? BACKEND_OPEN
1218 : BACKEND_CLOSED; 1211 : BACKEND_CLOSED;
1219 1212
1220 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult", error, 1213 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult",
1221 CACHE_STORAGE_ERROR_LAST + 1); 1214 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1);
1222 1215
1223 scheduler_->CompleteOperationAndRunNext(); 1216 scheduler_->CompleteOperationAndRunNext();
1224 } 1217 }
1225 1218
1226 void CacheStorageCache::PendingClosure(const base::Closure& callback) { 1219 void CacheStorageCache::PendingClosure(const base::Closure& callback) {
1227 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); 1220 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr();
1228 1221
1229 callback.Run(); 1222 callback.Run();
1230 if (cache) 1223 if (cache)
1231 scheduler_->CompleteOperationAndRunNext(); 1224 scheduler_->CompleteOperationAndRunNext();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 storage::BlobDataBuilder blob_data(response->blob_uuid); 1306 storage::BlobDataBuilder blob_data(response->blob_uuid);
1314 1307
1315 disk_cache::Entry* temp_entry = entry.get(); 1308 disk_cache::Entry* temp_entry = entry.get();
1316 blob_data.AppendDiskCacheEntry( 1309 blob_data.AppendDiskCacheEntry(
1317 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, 1310 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry,
1318 INDEX_RESPONSE_BODY); 1311 INDEX_RESPONSE_BODY);
1319 return blob_storage_context_->AddFinishedBlob(&blob_data); 1312 return blob_storage_context_->AddFinishedBlob(&blob_data);
1320 } 1313 }
1321 1314
1322 } // namespace content 1315 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.h ('k') | content/browser/cache_storage/cache_storage_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698