Chromium Code Reviews| 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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 void CacheStorageCache::PutImpl(scoped_ptr<PutContext> put_context) { | 789 void CacheStorageCache::PutImpl(scoped_ptr<PutContext> put_context) { |
| 790 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); | 790 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); |
| 791 if (backend_state_ != BACKEND_OPEN) { | 791 if (backend_state_ != BACKEND_OPEN) { |
| 792 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 792 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
| 793 return; | 793 return; |
| 794 } | 794 } |
| 795 | 795 |
| 796 scoped_ptr<ServiceWorkerFetchRequest> request_copy( | 796 scoped_ptr<ServiceWorkerFetchRequest> request_copy( |
| 797 new ServiceWorkerFetchRequest(*put_context->request)); | 797 new ServiceWorkerFetchRequest(*put_context->request)); |
| 798 | 798 |
| 799 DeleteImpl(std::move(request_copy), | 799 DeleteImpl(std::move(request_copy), CacheStorageCacheQueryParams(), |
| 800 base::Bind(&CacheStorageCache::PutDidDelete, | 800 base::Bind(&CacheStorageCache::PutDidDelete, |
| 801 weak_ptr_factory_.GetWeakPtr(), | 801 weak_ptr_factory_.GetWeakPtr(), |
| 802 base::Passed(std::move(put_context)))); | 802 base::Passed(std::move(put_context)))); |
| 803 } | 803 } |
| 804 | 804 |
| 805 void CacheStorageCache::PutDidDelete(scoped_ptr<PutContext> put_context, | 805 void CacheStorageCache::PutDidDelete(scoped_ptr<PutContext> put_context, |
| 806 CacheStorageError delete_error) { | 806 CacheStorageError delete_error) { |
| 807 if (backend_state_ != BACKEND_OPEN) { | 807 if (backend_state_ != BACKEND_OPEN) { |
| 808 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 808 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
| 809 return; | 809 return; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1011 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( | 1011 scoped_ptr<ServiceWorkerFetchRequest> request(new ServiceWorkerFetchRequest( |
| 1012 operation.request.url, operation.request.method, | 1012 operation.request.url, operation.request.method, |
| 1013 operation.request.headers, operation.request.referrer, | 1013 operation.request.headers, operation.request.referrer, |
| 1014 operation.request.is_reload)); | 1014 operation.request.is_reload)); |
| 1015 | 1015 |
| 1016 ErrorCallback pending_callback = | 1016 ErrorCallback pending_callback = |
| 1017 base::Bind(&CacheStorageCache::PendingErrorCallback, | 1017 base::Bind(&CacheStorageCache::PendingErrorCallback, |
| 1018 weak_ptr_factory_.GetWeakPtr(), callback); | 1018 weak_ptr_factory_.GetWeakPtr(), callback); |
| 1019 scheduler_->ScheduleOperation( | 1019 scheduler_->ScheduleOperation( |
| 1020 base::Bind(&CacheStorageCache::DeleteImpl, weak_ptr_factory_.GetWeakPtr(), | 1020 base::Bind(&CacheStorageCache::DeleteImpl, weak_ptr_factory_.GetWeakPtr(), |
| 1021 base::Passed(std::move(request)), pending_callback)); | 1021 base::Passed(std::move(request)), operation.match_params, |
| 1022 pending_callback)); | |
| 1022 } | 1023 } |
| 1023 | 1024 |
| 1024 void CacheStorageCache::DeleteImpl( | 1025 void CacheStorageCache::DeleteImpl( |
| 1025 scoped_ptr<ServiceWorkerFetchRequest> request, | 1026 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 1027 const CacheStorageCacheQueryParams& match_params, | |
| 1026 const ErrorCallback& callback) { | 1028 const ErrorCallback& callback) { |
| 1027 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); | 1029 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); |
| 1028 if (backend_state_ != BACKEND_OPEN) { | 1030 if (backend_state_ != BACKEND_OPEN) { |
| 1029 callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 1031 callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
| 1030 return; | 1032 return; |
| 1031 } | 1033 } |
| 1034 | |
| 1035 if (match_params.ignore_search) { | |
| 1036 OpenAllEntries(base::Bind(&CacheStorageCache::DeleteDidOpenAllEntries, | |
| 1037 weak_ptr_factory_.GetWeakPtr(), | |
| 1038 RemoveQueryParam(request->url), callback)); | |
|
nhiroki
2016/02/16 08:47:23
I'd prefer to lazily remove the query param at lin
zino
2016/02/16 09:23:09
Yeah.. I can't understand why I did that..
Done.
| |
| 1039 return; | |
| 1040 } | |
| 1041 | |
| 1032 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); | 1042 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); |
| 1033 | 1043 |
| 1034 disk_cache::Entry** entry_ptr = entry.get(); | 1044 disk_cache::Entry** entry_ptr = entry.get(); |
| 1035 | 1045 |
| 1036 ServiceWorkerFetchRequest* request_ptr = request.get(); | 1046 ServiceWorkerFetchRequest* request_ptr = request.get(); |
| 1037 | 1047 |
| 1038 net::CompletionCallback open_entry_callback = base::Bind( | 1048 net::CompletionCallback open_entry_callback = base::Bind( |
| 1039 &CacheStorageCache::DeleteDidOpenEntry, weak_ptr_factory_.GetWeakPtr(), | 1049 &CacheStorageCache::DeleteDidOpenEntry, weak_ptr_factory_.GetWeakPtr(), |
| 1040 origin_, base::Passed(std::move(request)), callback, | 1050 origin_, base::Passed(std::move(request)), callback, |
| 1041 base::Passed(std::move(entry))); | 1051 base::Passed(std::move(entry))); |
| 1042 | 1052 |
| 1043 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, | 1053 int rv = backend_->OpenEntry(request_ptr->url.spec(), entry_ptr, |
| 1044 open_entry_callback); | 1054 open_entry_callback); |
| 1045 if (rv != net::ERR_IO_PENDING) | 1055 if (rv != net::ERR_IO_PENDING) |
| 1046 open_entry_callback.Run(rv); | 1056 open_entry_callback.Run(rv); |
| 1047 } | 1057 } |
| 1048 | 1058 |
| 1059 void CacheStorageCache::DeleteDidOpenAllEntries( | |
| 1060 const GURL& request_url_without_query, | |
| 1061 const ErrorCallback& callback, | |
| 1062 scoped_ptr<OpenAllEntriesContext> entries_context, | |
| 1063 CacheStorageError error) { | |
| 1064 if (error != CACHE_STORAGE_OK) { | |
| 1065 callback.Run(error); | |
| 1066 return; | |
| 1067 } | |
| 1068 | |
| 1069 for (Entries::iterator iter = entries_context->entries.begin(); | |
| 1070 iter != entries_context->entries.end(); iter++) { | |
| 1071 disk_cache::Entry* entry(*iter); | |
| 1072 if (request_url_without_query == RemoveQueryParam(GURL(entry->GetKey()))) | |
| 1073 entry->Doom(); | |
| 1074 } | |
| 1075 | |
| 1076 UpdateCacheSize(); | |
| 1077 callback.Run(CACHE_STORAGE_OK); | |
| 1078 } | |
| 1079 | |
| 1049 void CacheStorageCache::DeleteDidOpenEntry( | 1080 void CacheStorageCache::DeleteDidOpenEntry( |
| 1050 const GURL& origin, | 1081 const GURL& origin, |
| 1051 scoped_ptr<ServiceWorkerFetchRequest> request, | 1082 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 1052 const CacheStorageCache::ErrorCallback& callback, | 1083 const CacheStorageCache::ErrorCallback& callback, |
| 1053 scoped_ptr<disk_cache::Entry*> entry_ptr, | 1084 scoped_ptr<disk_cache::Entry*> entry_ptr, |
| 1054 int rv) { | 1085 int rv) { |
| 1055 if (rv != net::OK) { | 1086 if (rv != net::OK) { |
| 1056 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND); | 1087 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND); |
| 1057 return; | 1088 return; |
| 1058 } | 1089 } |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1336 storage::BlobDataBuilder blob_data(response->blob_uuid); | 1367 storage::BlobDataBuilder blob_data(response->blob_uuid); |
| 1337 | 1368 |
| 1338 disk_cache::Entry* temp_entry = entry.get(); | 1369 disk_cache::Entry* temp_entry = entry.get(); |
| 1339 blob_data.AppendDiskCacheEntry( | 1370 blob_data.AppendDiskCacheEntry( |
| 1340 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, | 1371 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, |
| 1341 INDEX_RESPONSE_BODY); | 1372 INDEX_RESPONSE_BODY); |
| 1342 return blob_storage_context_->AddFinishedBlob(&blob_data); | 1373 return blob_storage_context_->AddFinishedBlob(&blob_data); |
| 1343 } | 1374 } |
| 1344 | 1375 |
| 1345 } // namespace content | 1376 } // namespace content |
| OLD | NEW |