diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-29 20:44:32 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-29 20:44:32 +0000 |
commit | 50f0e87c11606f326990cdae92f838f080efc5d3 (patch) | |
tree | ac17439dc2c106115993533c7b5f7e4788942f38 /net/disk_cache | |
parent | d9af50c76da16f7f5a7a312bc8219917b2cab77c (diff) | |
download | chromium_src-50f0e87c11606f326990cdae92f838f080efc5d3.zip chromium_src-50f0e87c11606f326990cdae92f838f080efc5d3.tar.gz chromium_src-50f0e87c11606f326990cdae92f838f080efc5d3.tar.bz2 |
Disk cache: Split deleting old entries from the cache into small chunks that run through the
message loop to improve responsiveness of the io thread.
BUG=1345851
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1552 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/backend_impl.cc | 8 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.h | 8 |
2 files changed, 13 insertions, 3 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index 7deb343..bc0f723 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -91,7 +91,7 @@ void CleanupTask::Run() { } } -// Returns a full path to reneme the current cache, in order to delete it. path +// Returns a full path to rename the current cache, in order to delete it. path // is the current folder location, and name is the current folder name. std::wstring GetTempCacheName(const std::wstring& path, const std::wstring& name) { @@ -946,6 +946,7 @@ void BackendImpl::TrimCache(bool empty) { Rankings::ScopedRankingsBlock next(&rankings_, rankings_.GetPrev(node.get())); DCHECK(next.get()); int target_size = empty ? 0 : LowWaterAdjust(max_size_); + int deleted = 0; while (data_->header.num_bytes > target_size && next.get()) { node.reset(next.release()); next.reset(rankings_.GetPrev(node.get())); @@ -968,6 +969,11 @@ void BackendImpl::TrimCache(bool empty) { entry->Release(); if (!empty) stats_.OnEvent(Stats::TRIM_ENTRY); + if (++deleted == 4 && !empty) { + MessageLoop::current()->PostTask(FROM_HERE, + factory_.NewRunnableMethod(&BackendImpl::TrimCache, false)); + break; + } } } diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h index 7a39238..6818d84 100644 --- a/net/disk_cache/backend_impl.h +++ b/net/disk_cache/backend_impl.h @@ -7,6 +7,7 @@ #ifndef NET_DISK_CACHE_BACKEND_IMPL_H__ #define NET_DISK_CACHE_BACKEND_IMPL_H__ +#include "base/compiler_specific.h" #include "base/timer.h" #include "net/disk_cache/block_files.h" #include "net/disk_cache/disk_cache.h" @@ -22,11 +23,13 @@ class BackendImpl : public Backend { public: explicit BackendImpl(const std::wstring& path) : path_(path), block_files_(path), mask_(0), max_size_(0), - init_(false), restarted_(false), unit_test_(false) {} + init_(false), restarted_(false), unit_test_(false), + ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} // mask can be used to limit the usable size of the hash table, for testing. BackendImpl(const std::wstring& path, uint32 mask) : path_(path), block_files_(path), mask_(mask), max_size_(0), - init_(false), restarted_(false), unit_test_(false) {} + init_(false), restarted_(false), unit_test_(false), + ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} ~BackendImpl(); // Performs general initialization for this current instance of the cache. @@ -177,6 +180,7 @@ class BackendImpl : public Backend { Stats stats_; // Usage statistcs. base::RepeatingTimer<BackendImpl> timer_; // Usage timer. TraceObject trace_object_; // Inits and destroys internal tracing. + ScopedRunnableMethodFactory<BackendImpl> factory_; DISALLOW_EVIL_CONSTRUCTORS(BackendImpl); }; |