diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-31 17:35:14 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-31 17:35:14 +0000 |
commit | 18995e2487e6e894e24601c4714a050797d9f1ef (patch) | |
tree | bc3569b97ccc8ce9bb827ec904b262ab7e4748e7 /net/disk_cache/mem_entry_impl.cc | |
parent | 76543b9c43515c8c68413b25d682b7c15a151905 (diff) | |
download | chromium_src-18995e2487e6e894e24601c4714a050797d9f1ef.zip chromium_src-18995e2487e6e894e24601c4714a050797d9f1ef.tar.gz chromium_src-18995e2487e6e894e24601c4714a050797d9f1ef.tar.bz2 |
Disk Cache: Function re-ordering. No code change.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/182023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24900 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/mem_entry_impl.cc')
-rw-r--r-- | net/disk_cache/mem_entry_impl.cc | 128 |
1 files changed, 66 insertions, 62 deletions
diff --git a/net/disk_cache/mem_entry_impl.cc b/net/disk_cache/mem_entry_impl.cc index 7b15446..dcab54b 100644 --- a/net/disk_cache/mem_entry_impl.cc +++ b/net/disk_cache/mem_entry_impl.cc @@ -54,45 +54,6 @@ MemEntryImpl::~MemEntryImpl() { backend_->ModifyStorageSize(static_cast<int32>(key_.size()), 0); } -bool MemEntryImpl::CreateEntry(const std::string& key) { - key_ = key; - last_modified_ = Time::Now(); - last_used_ = Time::Now(); - Open(); - backend_->ModifyStorageSize(0, static_cast<int32>(key.size())); - return true; -} - -void MemEntryImpl::Close() { - // Only a parent entry can be closed. - DCHECK(type() == kParentEntry); - ref_count_--; - DCHECK(ref_count_ >= 0); - if (!ref_count_ && doomed_) - InternalDoom(); -} - -void MemEntryImpl::Open() { - // Only a parent entry can be opened. - // TODO(hclam): make sure it's correct to not apply the concept of ref - // counting to child entry. - DCHECK(type() == kParentEntry); - ref_count_++; - DCHECK(ref_count_ >= 0); - DCHECK(!doomed_); -} - -bool MemEntryImpl::InUse() { - if (type() == kParentEntry) { - return ref_count_ > 0; - } else { - // A child entry is always not in use. The consequence is that a child entry - // can always be evicted while the associated parent entry is currently in - // used (i.e. opened). - return false; - } -} - void MemEntryImpl::Doom() { if (doomed_) return; @@ -106,29 +67,13 @@ void MemEntryImpl::Doom() { } } -void MemEntryImpl::InternalDoom() { - doomed_ = true; - if (!ref_count_) { - if (type() == kParentEntry) { - // If this is a parent entry, we need to doom all the child entries. - if (children_.get()) { - EntryMap children; - children.swap(*children_); - for (EntryMap::iterator i = children.begin(); - i != children.end(); ++i) { - // Since a pointer to this object is also saved in the map, avoid - // dooming it. - if (i->second != this) - i->second->Doom(); - } - DCHECK(children_->size() == 0); - } - } else { - // If this is a child entry, detach it from the parent. - parent_->DetachChild(child_id_); - } - delete this; - } +void MemEntryImpl::Close() { + // Only a parent entry can be closed. + DCHECK(type() == kParentEntry); + ref_count_--; + DCHECK(ref_count_ >= 0); + if (!ref_count_ && doomed_) + InternalDoom(); } std::string MemEntryImpl::GetKey() const { @@ -374,6 +319,65 @@ int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start) { return 0; } +// ------------------------------------------------------------------------ + +bool MemEntryImpl::CreateEntry(const std::string& key) { + key_ = key; + last_modified_ = Time::Now(); + last_used_ = Time::Now(); + Open(); + backend_->ModifyStorageSize(0, static_cast<int32>(key.size())); + return true; +} + +void MemEntryImpl::InternalDoom() { + doomed_ = true; + if (!ref_count_) { + if (type() == kParentEntry) { + // If this is a parent entry, we need to doom all the child entries. + if (children_.get()) { + EntryMap children; + children.swap(*children_); + for (EntryMap::iterator i = children.begin(); + i != children.end(); ++i) { + // Since a pointer to this object is also saved in the map, avoid + // dooming it. + if (i->second != this) + i->second->Doom(); + } + DCHECK(children_->size() == 0); + } + } else { + // If this is a child entry, detach it from the parent. + parent_->DetachChild(child_id_); + } + delete this; + } +} + +void MemEntryImpl::Open() { + // Only a parent entry can be opened. + // TODO(hclam): make sure it's correct to not apply the concept of ref + // counting to child entry. + DCHECK(type() == kParentEntry); + ref_count_++; + DCHECK(ref_count_ >= 0); + DCHECK(!doomed_); +} + +bool MemEntryImpl::InUse() { + if (type() == kParentEntry) { + return ref_count_ > 0; + } else { + // A child entry is always not in use. The consequence is that a child entry + // can always be evicted while the associated parent entry is currently in + // used (i.e. opened). + return false; + } +} + +// ------------------------------------------------------------------------ + void MemEntryImpl::PrepareTarget(int index, int offset, int buf_len) { int entry_size = GetDataSize(index); |