diff options
-rw-r--r-- | net/disk_cache/entry_impl.cc | 50 | ||||
-rw-r--r-- | net/disk_cache/mem_entry_impl.cc | 128 | ||||
-rw-r--r-- | net/disk_cache/mem_entry_impl.h | 17 |
3 files changed, 101 insertions, 94 deletions
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc index 4b650d9..4854a49 100644 --- a/net/disk_cache/entry_impl.cc +++ b/net/disk_cache/entry_impl.cc @@ -384,6 +384,8 @@ int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start) { return sparse_->GetAvailableRange(offset, len, start); } +// ------------------------------------------------------------------------ + uint32 EntryImpl::GetHash() { return entry_.Data()->hash; } @@ -575,6 +577,31 @@ void EntryImpl::SetTimes(base::Time last_used, base::Time last_modified) { node_.set_modified(); } +void EntryImpl::ReportIOTime(Operation op, const base::Time& start) { + int group = backend_->GetSizeGroup(); + switch (op) { + case kRead: + CACHE_UMA(AGE_MS, "ReadTime", group, start); + break; + case kWrite: + CACHE_UMA(AGE_MS, "WriteTime", group, start); + break; + case kSparseRead: + CACHE_UMA(AGE_MS, "SparseReadTime", 0, start); + break; + case kSparseWrite: + CACHE_UMA(AGE_MS, "SparseWriteTime", 0, start); + break; + case kAsyncIO: + CACHE_UMA(AGE_MS, "AsyncIOTime", group, start); + break; + default: + NOTREACHED(); + } +} + +// ------------------------------------------------------------------------ + bool EntryImpl::CreateDataBlock(int index, int size) { DCHECK(index >= 0 && index < kNumStreams); @@ -868,29 +895,6 @@ void EntryImpl::GetData(int index, char** buffer, Addr* address) { } } -void EntryImpl::ReportIOTime(Operation op, const base::Time& start) { - int group = backend_->GetSizeGroup(); - switch (op) { - case kRead: - CACHE_UMA(AGE_MS, "ReadTime", group, start); - break; - case kWrite: - CACHE_UMA(AGE_MS, "WriteTime", group, start); - break; - case kSparseRead: - CACHE_UMA(AGE_MS, "SparseReadTime", 0, start); - break; - case kSparseWrite: - CACHE_UMA(AGE_MS, "SparseWriteTime", 0, start); - break; - case kAsyncIO: - CACHE_UMA(AGE_MS, "AsyncIOTime", group, start); - break; - default: - NOTREACHED(); - } -} - void EntryImpl::Log(const char* msg) { int dirty = 0; if (node_.HasData()) { 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); diff --git a/net/disk_cache/mem_entry_impl.h b/net/disk_cache/mem_entry_impl.h index 5f596bb..2463985 100644 --- a/net/disk_cache/mem_entry_impl.h +++ b/net/disk_cache/mem_entry_impl.h @@ -142,19 +142,18 @@ class MemEntryImpl : public Entry { int32 data_size_[NUM_STREAMS]; int ref_count_; - MemEntryImpl* next_; // Pointers for the LRU list. + int child_id_; // The ID of a child entry. + int child_first_pos_; // The position of the first byte in a child + // entry. + MemEntryImpl* next_; // Pointers for the LRU list. MemEntryImpl* prev_; - MemEntryImpl* parent_; // Pointer to the parent entry. + MemEntryImpl* parent_; // Pointer to the parent entry. scoped_ptr<EntryMap> children_; - int child_id_; // The ID of a child entry. - int child_first_pos_; // The position of the first byte in a child - // entry. - - base::Time last_modified_; // LRU information. + base::Time last_modified_; // LRU information. base::Time last_used_; - MemBackendImpl* backend_; // Back pointer to the cache. - bool doomed_; // True if this entry was removed from the cache. + MemBackendImpl* backend_; // Back pointer to the cache. + bool doomed_; // True if this entry was removed from the cache. DISALLOW_EVIL_CONSTRUCTORS(MemEntryImpl); }; |