Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: trunk/src/net/disk_cache/simple/simple_index.cc

Issue 14081031: Revert 195845 "With this CL we can catch OnResume, OnPause, OnDe..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « trunk/src/net/disk_cache/simple/simple_index.h ('k') | trunk/src/net/net.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/net/disk_cache/simple/simple_index.cc
===================================================================
--- trunk/src/net/disk_cache/simple/simple_index.cc (revision 196356)
+++ trunk/src/net/disk_cache/simple/simple_index.cc (working copy)
@@ -32,9 +32,11 @@
// How many seconds we delay writing the index to disk since the last cache
// operation has happened.
-const int kWriteToDiskDelayMSecs = 20000;
-const int kWriteToDiskOnBackgroundDelayMSecs = 100;
+const int kWriteToDiskDelaySecs = 20;
+// WriteToDisk at lest every 5 minutes.
+const int kMaxWriteToDiskDelaySecs = 300;
+
// Divides the cache space into this amount of parts to evict when only one part
// is left.
const uint32 kEvictionMarginDivisor = 20;
@@ -164,12 +166,7 @@
initialized_(false),
index_filename_(path.AppendASCII("the-real-index")),
cache_thread_(cache_thread),
- io_thread_(io_thread),
-#if defined(OS_ANDROID)
- activity_status_notifier_(
- base::Bind(&SimpleIndex::ActivityStatusChanged, AsWeakPtr())),
-#endif
- app_on_background_(false) {
+ io_thread_(io_thread) {
}
SimpleIndex::~SimpleIndex() {
@@ -377,17 +374,19 @@
void SimpleIndex::PostponeWritingToDisk() {
if (!initialized_)
return;
- int delay = kWriteToDiskDelayMSecs;
- if (app_on_background_) {
- // When the app is in the background we can write the index much more
- // frequently. We could even write it to disk on every operation if we
- // wanted to.
- delay = kWriteToDiskOnBackgroundDelayMSecs;
+ const base::TimeDelta file_age = base::Time::Now() - last_write_to_disk_;
+ if (file_age > base::TimeDelta::FromSeconds(kMaxWriteToDiskDelaySecs) &&
+ write_to_disk_timer_.IsRunning()) {
+ // If the index file is too old and there is a timer programmed to run a
+ // WriteToDisk soon, we don't postpone it, so we always WriteToDisk
+ // approximately every kMaxWriteToDiskDelaySecs.
+ return;
}
+
// If the timer is already active, Start() will just Reset it, postponing it.
write_to_disk_timer_.Start(
FROM_HERE,
- base::TimeDelta::FromMilliseconds(delay),
+ base::TimeDelta::FromSeconds(kWriteToDiskDelaySecs),
base::Bind(&SimpleIndex::WriteToDisk, AsWeakPtr()));
}
@@ -453,6 +452,8 @@
const base::FilePath& index_filename) {
using file_util::FileEnumerator;
LOG(INFO) << "Simple Cache Index is being restored from disk.";
+
+ file_util::Delete(index_filename, /* recursive = */ false);
scoped_ptr<EntrySet> index_file_entries(new EntrySet());
// TODO(felipeg,gavinp): Fix this once we have a one-file per entry format.
@@ -478,6 +479,7 @@
hash_key_string, &hash_key)) {
LOG(WARNING) << "Invalid Entry Hash Key filename while restoring "
<< "Simple Index from disk: " << hash_name;
+ // TODO(felipeg): Should we delete the invalid file here ?
continue;
}
@@ -544,6 +546,7 @@
cache_size_ += it->second.GetEntrySize();
}
}
+ last_write_to_disk_ = base::Time::Now();
initialized_ = true;
removed_entries_.clear();
@@ -562,23 +565,6 @@
to_run_when_initialized_.clear();
}
-#if defined(OS_ANDROID)
-void SimpleIndex::ActivityStatusChanged(
- net::SimpleCacheActivityStatusNotifier::ActivityStatus activity_status) {
- DCHECK(io_thread_checker_.CalledOnValidThread());
- // For more info about android activities, see:
- // developer.android.com/training/basics/activity-lifecycle/pausing.html
- // These values are defined in the file ActivityStatus.java
- if (activity_status == net::SimpleCacheActivityStatusNotifier::RESUMED) {
- app_on_background_ = false;
- } else if (activity_status ==
- net::SimpleCacheActivityStatusNotifier::STOPPED) {
- app_on_background_ = true;
- WriteToDisk();
- }
-}
-#endif
-
void SimpleIndex::WriteToDisk() {
DCHECK(io_thread_checker_.CalledOnValidThread());
if (!initialized_)
@@ -586,6 +572,7 @@
UMA_HISTOGRAM_CUSTOM_COUNTS("SimpleCache.IndexNumEntriesOnWrite",
entries_set_.size(), 0, 100000, 50);
const base::TimeTicks start = base::TimeTicks::Now();
+ last_write_to_disk_ = base::Time::Now();
SimpleIndexFile::IndexMetadata index_metadata(entries_set_.size(),
cache_size_);
scoped_ptr<Pickle> pickle = SimpleIndexFile::Serialize(index_metadata,
« no previous file with comments | « trunk/src/net/disk_cache/simple/simple_index.h ('k') | trunk/src/net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698