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

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

Issue 14295013: Simple Cache: DoomEntriesBetween() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix an actual bug in DoomEntry 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 | « net/disk_cache/simple/simple_index.h ('k') | net/disk_cache/simple/simple_synchronous_entry.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c2b73b9c80716577363e59f05a4387de37bc4181..02c1453ad4742684562194c157fbd98667a917b1 100644
--- a/net/disk_cache/simple/simple_index.cc
+++ b/net/disk_cache/simple/simple_index.cc
@@ -91,6 +91,12 @@ SimpleIndex::SimpleIndex(
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) {
+ it->Run(net::ERR_ABORTED);
+ }
}
void SimpleIndex::Initialize() {
@@ -105,6 +111,41 @@ void SimpleIndex::Initialize() {
true);
}
+int SimpleIndex::ExecuteWhenReady(const net::CompletionCallback& task) {
+ DCHECK(io_thread_checker_.CalledOnValidThread());
+ if (initialized_)
+ io_thread_->PostTask(FROM_HERE, base::Bind(task, net::OK));
+ else
+ to_run_when_initialized_.push_back(task);
+ return net::ERR_IO_PENDING;
+}
+
+scoped_ptr<std::vector<uint64> > SimpleIndex::RemoveEntriesBetween(
+ const base::Time initial_time, const base::Time end_time) {
+ DCHECK_EQ(true, initialized_);
+ const base::Time extended_end_time =
+ end_time.is_null() ? base::Time::Max() : end_time;
+ DCHECK(extended_end_time >= initial_time);
+ scoped_ptr<std::vector<uint64> > ret_hashes(new std::vector<uint64>());
+ for (EntrySet::iterator it = entries_set_.begin(), end = entries_set_.end();
+ it != end;) {
+ EntryMetadata metadata = it->second;
+ base::Time entry_time = metadata.GetLastUsedTime();
+ if (initial_time <= entry_time && entry_time < extended_end_time) {
+ ret_hashes->push_back(metadata.GetHashKey());
+ entries_set_.erase(it++);
+ } else {
+ it++;
+ }
+ }
+ return ret_hashes.Pass();
+}
+
+int32 SimpleIndex::GetEntryCount() const {
+ // TODO(pasko): return a meaningful initial estimate before initialized.
+ return entries_set_.size();
+}
+
void SimpleIndex::Insert(const std::string& key) {
DCHECK(io_thread_checker_.CalledOnValidThread());
// Upon insert we don't know yet the size of the entry.
@@ -313,6 +354,13 @@ void SimpleIndex::MergeInitializingSet(scoped_ptr<EntrySet> index_file_entries,
// much the merge.
if (force_index_flush)
WriteToDisk();
+
+ // 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) {
+ io_thread_->PostTask(FROM_HERE, base::Bind((*it), net::OK));
+ }
+ to_run_when_initialized_.clear();
}
void SimpleIndex::WriteToDisk() {
« no previous file with comments | « net/disk_cache/simple/simple_index.h ('k') | net/disk_cache/simple/simple_synchronous_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698