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

Unified Diff: net/disk_cache/simple/simple_backend_impl.cc

Issue 533293002: Delete enumerations at Simple Cache backend deletion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lint Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/disk_cache/simple/simple_backend_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_backend_impl.cc
diff --git a/net/disk_cache/simple/simple_backend_impl.cc b/net/disk_cache/simple/simple_backend_impl.cc
index ffdc9b185b366ef95a2f1b6ca91a89714e6423f5..2e165760b779f69a5807f3476e50561f7eb3d3aa 100644
--- a/net/disk_cache/simple/simple_backend_impl.cc
+++ b/net/disk_cache/simple/simple_backend_impl.cc
@@ -483,9 +483,7 @@ int SimpleBackendImpl::OpenNextEntry(void** iter,
}
void SimpleBackendImpl::EndEnumeration(void** iter) {
- SimpleIndex::HashList* entry_list =
- static_cast<SimpleIndex::HashList*>(*iter);
- delete entry_list;
+ active_enumerations_.Remove(IteratorToEnumerationId(iter));
*iter = NULL;
}
@@ -501,6 +499,27 @@ void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) {
index_->UseIfExists(simple_util::GetEntryHashKey(key));
}
+// static
+SimpleBackendImpl::ActiveEnumerationMap::KeyType
+ SimpleBackendImpl::IteratorToEnumerationId(void** iter) {
+ COMPILE_ASSERT(sizeof(ptrdiff_t) >= sizeof(*iter),
+ integer_type_must_fit_ptr_type_for_cast_to_be_reversible);
+ const ptrdiff_t ptrdiff_enumeration_id = reinterpret_cast<ptrdiff_t>(*iter);
+ const ActiveEnumerationMap::KeyType enumeration_id = ptrdiff_enumeration_id;
+ DCHECK_EQ(enumeration_id, ptrdiff_enumeration_id);
+ return enumeration_id;
+}
+
+// static
+void* SimpleBackendImpl::EnumerationIdToIterator(
+ ActiveEnumerationMap::KeyType enumeration_id) {
+ const ptrdiff_t ptrdiff_enumeration_id = enumeration_id;
+ DCHECK_EQ(enumeration_id, ptrdiff_enumeration_id);
+ COMPILE_ASSERT(sizeof(ptrdiff_t) >= sizeof(void*),
+ integer_type_must_fit_ptr_type_for_cast_to_be_reversible);
+ return reinterpret_cast<void*>(ptrdiff_enumeration_id);
+}
+
void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback,
const DiskStatResult& result) {
if (result.net_error == net::OK) {
@@ -623,11 +642,15 @@ void SimpleBackendImpl::GetNextEntryInIterator(
callback.Run(error_code);
return;
}
+ std::vector<uint64>* entry_list = NULL;
if (*iter == NULL) {
- *iter = index()->GetAllHashes().release();
+ const ActiveEnumerationMap::KeyType new_enumeration_id =
+ active_enumerations_.Add(
+ entry_list = index()->GetAllHashes().release());
+ *iter = EnumerationIdToIterator(new_enumeration_id);
+ } else {
+ entry_list = active_enumerations_.Lookup(IteratorToEnumerationId(iter));
}
- SimpleIndex::HashList* entry_list =
- static_cast<SimpleIndex::HashList*>(*iter);
while (entry_list->size() > 0) {
uint64 entry_hash = entry_list->back();
entry_list->pop_back();
« no previous file with comments | « net/disk_cache/simple/simple_backend_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698