| 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..dedb4325323d63c3e156bab466c6be0a44508388 100644
|
| --- a/net/disk_cache/simple/simple_index.cc
|
| +++ b/net/disk_cache/simple/simple_index.cc
|
| @@ -77,10 +77,17 @@ 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) {
|
| + it->Run(net::ERR_ABORTED);
|
| + }
|
| }
|
|
|
| void SimpleIndex::Initialize() {
|
| @@ -95,6 +102,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::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);
|
| + 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.
|
| @@ -271,6 +313,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() {
|
|
|