Chromium Code Reviews| 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 c87b3c8a7019ca72061ae9e8d34686006ac6164b..996635a8253732afc93e14eac215a4305c3bf6d8 100644 |
| --- a/net/disk_cache/simple/simple_index.cc |
| +++ b/net/disk_cache/simple/simple_index.cc |
| @@ -77,11 +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 = initialized_waitlist_.begin(), |
| + end = initialized_waitlist_.end(); it != end; ++it) |
| + it->Run(net::ERR_ABORTED); |
| } |
| void SimpleIndex::Initialize() { |
| @@ -96,6 +101,40 @@ 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 |
| + initialized_waitlist_.push_back(task); |
|
gavinp
2013/04/17 07:41:18
I think we probably want UMA on the size of this l
pasko-google - do not use
2013/04/17 19:47:52
May I please to it in a followup CL?
|
| + return net::ERR_IO_PENDING; |
| +} |
| + |
| +std::set<uint64>* SimpleIndex::PullEntriesBetween( |
|
felipeg
2013/04/17 16:35:04
I would call it RemoveEntriesBetween
or just Remov
pasko-google - do not use
2013/04/17 19:47:52
Followed Gavin's suggestion: 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>(); |
| + for (EntrySet::iterator it = entries_set_.begin(), end = entries_set_.end(); |
|
gavinp
2013/04/17 07:41:18
Why take the copy of end?
pasko-google - do not use
2013/04/17 19:47:52
This is a premature optimization: in the hope that
gavinp
2013/04/18 06:11:35
It's fine, and plenty readable. I do think it's pr
pasko-google - do not use
2013/04/18 09:29:54
you probably mean common subexpression elimination
|
| + 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 |
|
gavinp
2013/04/17 07:41:18
Style: } else {
pasko-google - do not use
2013/04/17 19:47:52
that is good, I like that, did not know that the g
gavinp
2013/04/18 06:11:35
Google style says braces are OK if you want them,
|
| + it++; |
| + } |
| + return ret_hashes; |
| +} |
| + |
| +int32 SimpleIndex::GetEntryCount() const { |
| + DCHECK(initialized_); |
|
gavinp
2013/04/17 07:41:18
This is going to make us crash in debug builds a l
pasko-google - do not use
2013/04/17 19:47:52
had the same thought very soon after uploading. Sa
|
| + 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. |
| @@ -272,6 +311,13 @@ void SimpleIndex::MergeInitializingSet( |
| } |
| initialized_ = true; |
| + |
| + // Run all callbacks waiting for the index to come up. |
| + for (CallbackList::iterator it = initialized_waitlist_.begin(), |
| + end = initialized_waitlist_.end(); it != end; ++it) { |
| + io_thread_->PostTask(FROM_HERE, base::Bind((*it), net::OK)); |
| + } |
| + initialized_waitlist_.clear(); |
| } |
| void SimpleIndex::WriteToDisk() { |