summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/mem_backend_impl.cc
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 20:41:30 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 20:41:30 +0000
commit658c173725ff824f22a103e2e984ef580260d593 (patch)
tree8fd52c1325e78c3f80b889fe8d9b2535e30442cd /net/disk_cache/mem_backend_impl.cc
parentaf97358f77a8cd000e37d05ec204f8d3f6cc62e7 (diff)
downloadchromium_src-658c173725ff824f22a103e2e984ef580260d593.zip
chromium_src-658c173725ff824f22a103e2e984ef580260d593.tar.gz
chromium_src-658c173725ff824f22a103e2e984ef580260d593.tar.bz2
Introduce parent and child entries for MemEntryImpl
Defines enums for kParentEntry and kChildEntry in MemEntryImpl. Also has code in MemBackendImpl to create a slave entry. Parent entries are non-sparse entries until sparse API are called on them, and they would start to keep a list of child entries. Child entries hold partial content and are not susposed to be accessible from the public and are managed by the parent entry that created it. Child entries are registered in the backend's ranking list to allow individual eviction. More details about how child entries are to be used are in the comments. TEST=DiskCacheEntryTest.MemoryOnlyEnumerationWithSlaveEntries Review URL: http://codereview.chromium.org/120004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/mem_backend_impl.cc')
-rw-r--r--net/disk_cache/mem_backend_impl.cc38
1 files changed, 22 insertions, 16 deletions
diff --git a/net/disk_cache/mem_backend_impl.cc b/net/disk_cache/mem_backend_impl.cc
index 0b8802a..c3d3a26 100644
--- a/net/disk_cache/mem_backend_impl.cc
+++ b/net/disk_cache/mem_backend_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -128,6 +128,9 @@ bool MemBackendImpl::DoomEntry(const std::string& key) {
}
void MemBackendImpl::InternalDoomEntry(MemEntryImpl* entry) {
+ // Only parent entries can be passed into this method.
+ DCHECK(entry->type() == MemEntryImpl::kParentEntry);
+
rankings_.Remove(entry);
EntryMap::iterator it = entries_.find(entry->GetKey());
if (it != entries_.end())
@@ -162,38 +165,33 @@ bool MemBackendImpl::DoomEntriesBetween(const Time initial_time,
if (node->GetLastUsed() < initial_time)
break;
- if (node->GetLastUsed() < end_time) {
+ if (node->GetLastUsed() < end_time)
node->Doom();
- }
}
return true;
}
-// We use OpenNextEntry to retrieve elements from the cache, until we get
-// entries that are too old.
bool MemBackendImpl::DoomEntriesSince(const Time initial_time) {
for (;;) {
- Entry* entry;
- void* iter = NULL;
- if (!OpenNextEntry(&iter, &entry))
- return true;
+ // Get the entry in the front.
+ Entry* entry = rankings_.GetNext(NULL);
- if (initial_time > entry->GetLastUsed()) {
- entry->Close();
- EndEnumeration(&iter);
+ // Break the loop when there are no more entries or the entry is too old.
+ if (!entry || entry->GetLastUsed() < initial_time)
return true;
- }
-
entry->Doom();
- entry->Close();
- EndEnumeration(&iter); // Dooming the entry invalidates the iterator.
}
}
bool MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry) {
MemEntryImpl* current = reinterpret_cast<MemEntryImpl*>(*iter);
MemEntryImpl* node = rankings_.GetNext(current);
+ // We should never return a child entry so iterate until we hit a parent
+ // entry.
+ while (node && node->type() != MemEntryImpl::kParentEntry) {
+ node = rankings_.GetNext(node);
+ }
*next_entry = node;
*iter = node;
@@ -252,4 +250,12 @@ int MemBackendImpl::MaxFileSize() const {
return max_size_ / 8;
}
+void MemBackendImpl::InsertIntoRankingList(MemEntryImpl* entry) {
+ rankings_.Insert(entry);
+}
+
+void MemBackendImpl::RemoveFromRankingList(MemEntryImpl* entry) {
+ rankings_.Remove(entry);
+}
+
} // namespace disk_cache