diff options
author | pasko@chromium.org <pasko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 21:23:26 +0000 |
---|---|---|
committer | pasko@chromium.org <pasko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 21:23:26 +0000 |
commit | aa6a8c91ff9506edfb9f8bcce84d7fcced7a04d8 (patch) | |
tree | 6755ac766192f55a36a33b3bf0496d2ac4f4ad14 /net/disk_cache | |
parent | 0f85d30d21582003613394d275211cd3f97c90c5 (diff) | |
download | chromium_src-aa6a8c91ff9506edfb9f8bcce84d7fcced7a04d8.zip chromium_src-aa6a8c91ff9506edfb9f8bcce84d7fcced7a04d8.tar.gz chromium_src-aa6a8c91ff9506edfb9f8bcce84d7fcced7a04d8.tar.bz2 |
Simple Cache: set variable index flush delays
The flush delay is pulled from the experiment. The experiment group encodes two
values in the name separated by underscore. For example, experiment group
"5000_100" would set foreground flush interval to 5 seconds and background
interval to 100ms. I don't like commas in the name.
BUG=250796
Review URL: https://chromiumcodereview.appspot.com/17076006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207087 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/simple/simple_index.cc | 31 | ||||
-rw-r--r-- | net/disk_cache/simple/simple_index.h | 6 |
2 files changed, 32 insertions, 5 deletions
diff --git a/net/disk_cache/simple/simple_index.cc b/net/disk_cache/simple/simple_index.cc index 56b9c01..8d65cbc 100644 --- a/net/disk_cache/simple/simple_index.cc +++ b/net/disk_cache/simple/simple_index.cc @@ -12,8 +12,11 @@ #include "base/files/file_enumerator.h" #include "base/logging.h" #include "base/message_loop.h" +#include "base/metrics/field_trial.h" #include "base/metrics/histogram.h" #include "base/pickle.h" +#include "base/strings/string_number_conversions.h" +#include "base/strings/string_tokenizer.h" #include "base/task_runner.h" #include "base/threading/worker_pool.h" #include "base/time.h" @@ -30,10 +33,10 @@ namespace { -// How many seconds we delay writing the index to disk since the last cache +// How many milliseconds we delay writing the index to disk since the last cache // operation has happened. -const int kWriteToDiskDelayMSecs = 20000; -const int kWriteToDiskOnBackgroundDelayMSecs = 100; +const int kDefaultWriteToDiskDelayMSecs = 20000; +const int kDefaultWriteToDiskOnBackgroundDelayMSecs = 100; // Divides the cache space into this amount of parts to evict when only one part // is left. @@ -124,6 +127,24 @@ SimpleIndex::~SimpleIndex() { void SimpleIndex::Initialize() { DCHECK(io_thread_checker_.CalledOnValidThread()); + // Take the foreground and background index flush delays from the experiment + // settings only if both are valid. + foreground_flush_delay_ = kDefaultWriteToDiskDelayMSecs; + background_flush_delay_ = kDefaultWriteToDiskOnBackgroundDelayMSecs; + const std::string index_flush_intervals = base::FieldTrialList::FindFullName( + "SimpleCacheIndexFlushDelay_Foreground_Background"); + if (!index_flush_intervals.empty()) { + base::StringTokenizer tokens(index_flush_intervals, "_"); + int foreground_delay, background_delay; + if (tokens.GetNext() && + base::StringToInt(tokens.token(), &foreground_delay) && + tokens.GetNext() && + base::StringToInt(tokens.token(), &background_delay)) { + foreground_flush_delay_ = foreground_delay; + background_flush_delay_ = background_delay; + } + } + #if defined(OS_ANDROID) activity_status_listener_.reset(new base::android::ActivityStatus::Listener( base::Bind(&SimpleIndex::OnActivityStateChange, AsWeakPtr()))); @@ -310,8 +331,8 @@ void SimpleIndex::InsertInEntrySet( void SimpleIndex::PostponeWritingToDisk() { if (!initialized_) return; - const int delay = app_on_background_ ? kWriteToDiskOnBackgroundDelayMSecs - : kWriteToDiskDelayMSecs; + 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_); diff --git a/net/disk_cache/simple/simple_index.h b/net/disk_cache/simple/simple_index.h index b8f08a3..2f24897 100644 --- a/net/disk_cache/simple/simple_index.h +++ b/net/disk_cache/simple/simple_index.h @@ -181,6 +181,12 @@ class NET_EXPORT_PRIVATE SimpleIndex // background we can write the index much more frequently, to insure fresh // index on next startup. bool app_on_background_; + + // The time in milliseconds for the index to be idle before it gets flushed to + // the disk. When the app is on foreground the delay is different from the + // background state. + int foreground_flush_delay_; + int background_flush_delay_; }; } // namespace disk_cache |