| Index: net/disk_cache/simple/simple_index.cc
|
| diff --git a/net/disk_cache/simple/simple_index.cc b/net/disk_cache/simple/simple_index.cc
|
| index 1f316a59ed65d198ac732d7beb634089be54912e..a86a47cf8659d24a44f39ec60dc4d9b44b913293 100644
|
| --- a/net/disk_cache/simple/simple_index.cc
|
| +++ b/net/disk_cache/simple/simple_index.cc
|
| @@ -52,16 +52,18 @@ const uint32 kBytesInKb = 1024;
|
| class CompareHashesForTimestamp {
|
| typedef disk_cache::SimpleIndex SimpleIndex;
|
| typedef disk_cache::SimpleIndex::EntrySet EntrySet;
|
| +
|
| public:
|
| explicit CompareHashesForTimestamp(const EntrySet& set);
|
|
|
| bool operator()(uint64 hash1, uint64 hash2);
|
| +
|
| private:
|
| const EntrySet& entry_set_;
|
| };
|
|
|
| CompareHashesForTimestamp::CompareHashesForTimestamp(const EntrySet& set)
|
| - : entry_set_(set) {
|
| + : entry_set_(set) {
|
| }
|
|
|
| bool CompareHashesForTimestamp::operator()(uint64 hash1, uint64 hash2) {
|
| @@ -77,13 +79,11 @@ bool CompareHashesForTimestamp::operator()(uint64 hash1, uint64 hash2) {
|
| namespace disk_cache {
|
|
|
| EntryMetadata::EntryMetadata()
|
| - : last_used_time_seconds_since_epoch_(0),
|
| - entry_size_(0) {
|
| + : last_used_time_seconds_since_epoch_(0), entry_size_(0) {
|
| }
|
|
|
| EntryMetadata::EntryMetadata(base::Time last_used_time, int entry_size)
|
| - : last_used_time_seconds_since_epoch_(0),
|
| - entry_size_(entry_size) {
|
| + : last_used_time_seconds_since_epoch_(0), entry_size_(entry_size) {
|
| SetLastUsedTime(last_used_time);
|
| }
|
|
|
| @@ -93,7 +93,7 @@ base::Time EntryMetadata::GetLastUsedTime() const {
|
| return base::Time();
|
|
|
| return base::Time::UnixEpoch() +
|
| - base::TimeDelta::FromSeconds(last_used_time_seconds_since_epoch_);
|
| + base::TimeDelta::FromSeconds(last_used_time_seconds_since_epoch_);
|
| }
|
|
|
| void EntryMetadata::SetLastUsedTime(const base::Time& last_used_time) {
|
| @@ -152,14 +152,17 @@ SimpleIndex::SimpleIndex(base::SingleThreadTaskRunner* io_thread,
|
| // Creating the callback once so it is reused every time
|
| // write_to_disk_timer_.Start() is called.
|
| write_to_disk_cb_(base::Bind(&SimpleIndex::WriteToDisk, AsWeakPtr())),
|
| - app_on_background_(false) {}
|
| + app_on_background_(false) {
|
| +}
|
|
|
| SimpleIndex::~SimpleIndex() {
|
| DCHECK(io_thread_checker_.CalledOnValidThread());
|
|
|
| // Fail all callbacks waiting for the index to come up.
|
| for (CallbackList::iterator it = to_run_when_initialized_.begin(),
|
| - end = to_run_when_initialized_.end(); it != end; ++it) {
|
| + end = to_run_when_initialized_.end();
|
| + it != end;
|
| + ++it) {
|
| it->Run(net::ERR_ABORTED);
|
| }
|
| }
|
| @@ -194,10 +197,9 @@ void SimpleIndex::Initialize(base::Time cache_mtime) {
|
|
|
| SimpleIndexLoadResult* load_result = new SimpleIndexLoadResult();
|
| scoped_ptr<SimpleIndexLoadResult> load_result_scoped(load_result);
|
| - base::Closure reply = base::Bind(
|
| - &SimpleIndex::MergeInitializingSet,
|
| - AsWeakPtr(),
|
| - base::Passed(&load_result_scoped));
|
| + base::Closure reply = base::Bind(&SimpleIndex::MergeInitializingSet,
|
| + AsWeakPtr(),
|
| + base::Passed(&load_result_scoped));
|
| index_file_->LoadIndexEntries(cache_mtime, reply, load_result);
|
| }
|
|
|
| @@ -225,7 +227,8 @@ int SimpleIndex::ExecuteWhenReady(const net::CompletionCallback& task) {
|
| }
|
|
|
| scoped_ptr<SimpleIndex::HashList> SimpleIndex::GetEntriesBetween(
|
| - base::Time initial_time, base::Time end_time) {
|
| + base::Time initial_time,
|
| + base::Time end_time) {
|
| DCHECK_EQ(true, initialized_);
|
|
|
| if (!initial_time.is_null())
|
| @@ -239,7 +242,8 @@ scoped_ptr<SimpleIndex::HashList> SimpleIndex::GetEntriesBetween(
|
| DCHECK(extended_end_time >= initial_time);
|
| scoped_ptr<HashList> ret_hashes(new HashList());
|
| for (EntrySet::iterator it = entries_set_.begin(), end = entries_set_.end();
|
| - it != end; ++it) {
|
| + it != end;
|
| + ++it) {
|
| EntryMetadata& metadata = it->second;
|
| base::Time entry_time = metadata.GetLastUsedTime();
|
| if (initial_time <= entry_time && entry_time < extended_end_time)
|
| @@ -309,18 +313,23 @@ void SimpleIndex::StartEvictionIfNeeded() {
|
| eviction_in_progress_ = true;
|
| eviction_start_time_ = base::TimeTicks::Now();
|
| SIMPLE_CACHE_UMA(MEMORY_KB,
|
| - "Eviction.CacheSizeOnStart2", cache_type_,
|
| + "Eviction.CacheSizeOnStart2",
|
| + cache_type_,
|
| cache_size_ / kBytesInKb);
|
| SIMPLE_CACHE_UMA(MEMORY_KB,
|
| - "Eviction.MaxCacheSizeOnStart2", cache_type_,
|
| + "Eviction.MaxCacheSizeOnStart2",
|
| + cache_type_,
|
| max_size_ / kBytesInKb);
|
| std::vector<uint64> entry_hashes;
|
| entry_hashes.reserve(entries_set_.size());
|
| for (EntrySet::const_iterator it = entries_set_.begin(),
|
| - end = entries_set_.end(); it != end; ++it) {
|
| + end = entries_set_.end();
|
| + it != end;
|
| + ++it) {
|
| entry_hashes.push_back(it->first);
|
| }
|
| - std::sort(entry_hashes.begin(), entry_hashes.end(),
|
| + std::sort(entry_hashes.begin(),
|
| + entry_hashes.end(),
|
| CompareHashesForTimestamp(entries_set_));
|
|
|
| // Remove as many entries from the index to get below |low_watermark_|.
|
| @@ -337,17 +346,19 @@ void SimpleIndex::StartEvictionIfNeeded() {
|
|
|
| // Take out the rest of hashes from the eviction list.
|
| entry_hashes.erase(it, entry_hashes.end());
|
| - SIMPLE_CACHE_UMA(COUNTS,
|
| - "Eviction.EntryCount", cache_type_, entry_hashes.size());
|
| + SIMPLE_CACHE_UMA(
|
| + COUNTS, "Eviction.EntryCount", cache_type_, entry_hashes.size());
|
| SIMPLE_CACHE_UMA(TIMES,
|
| - "Eviction.TimeToSelectEntries", cache_type_,
|
| + "Eviction.TimeToSelectEntries",
|
| + cache_type_,
|
| base::TimeTicks::Now() - eviction_start_time_);
|
| SIMPLE_CACHE_UMA(MEMORY_KB,
|
| - "Eviction.SizeOfEvicted2", cache_type_,
|
| + "Eviction.SizeOfEvicted2",
|
| + cache_type_,
|
| evicted_so_far_size / kBytesInKb);
|
|
|
| - delegate_->DoomEntries(&entry_hashes, base::Bind(&SimpleIndex::EvictionDone,
|
| - AsWeakPtr()));
|
| + delegate_->DoomEntries(&entry_hashes,
|
| + base::Bind(&SimpleIndex::EvictionDone, AsWeakPtr()));
|
| }
|
|
|
| bool SimpleIndex::UpdateEntrySize(uint64 entry_hash, int entry_size) {
|
| @@ -369,10 +380,12 @@ void SimpleIndex::EvictionDone(int result) {
|
| eviction_in_progress_ = false;
|
| SIMPLE_CACHE_UMA(BOOLEAN, "Eviction.Result", cache_type_, result == net::OK);
|
| SIMPLE_CACHE_UMA(TIMES,
|
| - "Eviction.TimeToDone", cache_type_,
|
| + "Eviction.TimeToDone",
|
| + cache_type_,
|
| base::TimeTicks::Now() - eviction_start_time_);
|
| SIMPLE_CACHE_UMA(MEMORY_KB,
|
| - "Eviction.SizeWhenDone2", cache_type_,
|
| + "Eviction.SizeWhenDone2",
|
| + cache_type_,
|
| cache_size_ / kBytesInKb);
|
| }
|
|
|
| @@ -388,8 +401,8 @@ void SimpleIndex::InsertInEntrySet(
|
| void SimpleIndex::PostponeWritingToDisk() {
|
| if (!initialized_)
|
| return;
|
| - const int delay = app_on_background_ ? background_flush_delay_
|
| - : foreground_flush_delay_;
|
| + const int delay =
|
| + app_on_background_ ? background_flush_delay_ : foreground_flush_delay_;
|
| // If the timer is already active, Start() will just Reset it, postponing it.
|
| write_to_disk_timer_.Start(
|
| FROM_HERE, base::TimeDelta::FromMilliseconds(delay), write_to_disk_cb_);
|
| @@ -413,24 +426,27 @@ void SimpleIndex::MergeInitializingSet(
|
| EntrySet* index_file_entries = &load_result->entries;
|
|
|
| for (base::hash_set<uint64>::const_iterator it = removed_entries_.begin();
|
| - it != removed_entries_.end(); ++it) {
|
| + it != removed_entries_.end();
|
| + ++it) {
|
| index_file_entries->erase(*it);
|
| }
|
| removed_entries_.clear();
|
|
|
| for (EntrySet::const_iterator it = entries_set_.begin();
|
| - it != entries_set_.end(); ++it) {
|
| + it != entries_set_.end();
|
| + ++it) {
|
| const uint64 entry_hash = it->first;
|
| std::pair<EntrySet::iterator, bool> insert_result =
|
| - index_file_entries->insert(EntrySet::value_type(entry_hash,
|
| - EntryMetadata()));
|
| + index_file_entries->insert(
|
| + EntrySet::value_type(entry_hash, EntryMetadata()));
|
| EntrySet::iterator& possibly_inserted_entry = insert_result.first;
|
| possibly_inserted_entry->second = it->second;
|
| }
|
|
|
| uint64 merged_cache_size = 0;
|
| for (EntrySet::iterator it = index_file_entries->begin();
|
| - it != index_file_entries->end(); ++it) {
|
| + it != index_file_entries->end();
|
| + ++it) {
|
| merged_cache_size += it->second.GetEntrySize();
|
| }
|
|
|
| @@ -444,11 +460,17 @@ void SimpleIndex::MergeInitializingSet(
|
| WriteToDisk();
|
|
|
| SIMPLE_CACHE_UMA(CUSTOM_COUNTS,
|
| - "IndexInitializationWaiters", cache_type_,
|
| - to_run_when_initialized_.size(), 0, 100, 20);
|
| + "IndexInitializationWaiters",
|
| + cache_type_,
|
| + to_run_when_initialized_.size(),
|
| + 0,
|
| + 100,
|
| + 20);
|
| // Run all callbacks waiting for the index to come up.
|
| for (CallbackList::iterator it = to_run_when_initialized_.begin(),
|
| - end = to_run_when_initialized_.end(); it != end; ++it) {
|
| + end = to_run_when_initialized_.end();
|
| + it != end;
|
| + ++it) {
|
| io_thread_->PostTask(FROM_HERE, base::Bind((*it), net::OK));
|
| }
|
| to_run_when_initialized_.clear();
|
| @@ -462,8 +484,7 @@ void SimpleIndex::OnApplicationStateChange(
|
| // developer.android.com/training/basics/activity-lifecycle/pausing.html
|
| if (state == base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) {
|
| app_on_background_ = false;
|
| - } else if (state ==
|
| - base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES) {
|
| + } else if (state == base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES) {
|
| app_on_background_ = true;
|
| WriteToDisk();
|
| }
|
| @@ -475,24 +496,30 @@ void SimpleIndex::WriteToDisk() {
|
| if (!initialized_)
|
| return;
|
| SIMPLE_CACHE_UMA(CUSTOM_COUNTS,
|
| - "IndexNumEntriesOnWrite", cache_type_,
|
| - entries_set_.size(), 0, 100000, 50);
|
| + "IndexNumEntriesOnWrite",
|
| + cache_type_,
|
| + entries_set_.size(),
|
| + 0,
|
| + 100000,
|
| + 50);
|
| const base::TimeTicks start = base::TimeTicks::Now();
|
| if (!last_write_to_disk_.is_null()) {
|
| if (app_on_background_) {
|
| SIMPLE_CACHE_UMA(MEDIUM_TIMES,
|
| - "IndexWriteInterval.Background", cache_type_,
|
| + "IndexWriteInterval.Background",
|
| + cache_type_,
|
| start - last_write_to_disk_);
|
| } else {
|
| SIMPLE_CACHE_UMA(MEDIUM_TIMES,
|
| - "IndexWriteInterval.Foreground", cache_type_,
|
| + "IndexWriteInterval.Foreground",
|
| + cache_type_,
|
| start - last_write_to_disk_);
|
| }
|
| }
|
| last_write_to_disk_ = start;
|
|
|
| - index_file_->WriteToDisk(entries_set_, cache_size_,
|
| - start, app_on_background_);
|
| + index_file_->WriteToDisk(
|
| + entries_set_, cache_size_, start, app_on_background_);
|
| }
|
|
|
| } // namespace disk_cache
|
|
|