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

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: first round of comments 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
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 31ea158524fc80adad16d8cc80944bb8e89f3fe4..960c118e22540372291d9b43e53c84a9a53c7ad3 100644
--- a/net/disk_cache/simple/simple_index.cc
+++ b/net/disk_cache/simple/simple_index.cc
@@ -77,10 +77,16 @@ SimpleIndex::SimpleIndex(
initialized_(false),
index_filename_(path.AppendASCII("simple-index")),
cache_thread_(cache_thread),
- io_thread_(io_thread) {}
+ io_thread_(io_thread) {
+}
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)
gavinp 2013/04/18 06:11:35 This for loop needs braces.
pasko-google - do not use 2013/04/18 09:29:54 Not required though. And I had an impression that
+ it->Run(net::ERR_ABORTED);
}
void SimpleIndex::Initialize() {
@@ -95,6 +101,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;
+}
+
+std::set<uint64>* SimpleIndex::ExtractEntriesBetween(
+ 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);
+ std::set<uint64>* ret_hashes = new std::set<uint64>();
gavinp 2013/04/18 06:11:35 Can we make ret_hashes a scoped_ptr? And it might
pasko-google - do not use 2013/04/18 09:29:54 Sure, I understand it may feel more cozy. Done.
+ 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->insert(metadata.GetHashKey());
+ entries_set_.erase(it++);
+ } else {
+ it++;
+ }
+ }
+ return ret_hashes;
+}
+
+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.
@@ -271,6 +312,13 @@ void SimpleIndex::MergeInitializingSet(
}
initialized_ = true;
+
+ // 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() {

Powered by Google App Engine
This is Rietveld 408576698