| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/disk_cache/simple/simple_index.h" | 5 #include "net/disk_cache/simple/simple_index.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 net::CacheType cache_type, | 146 net::CacheType cache_type, |
| 147 scoped_ptr<SimpleIndexFile> index_file) | 147 scoped_ptr<SimpleIndexFile> index_file) |
| 148 : delegate_(delegate), | 148 : delegate_(delegate), |
| 149 cache_type_(cache_type), | 149 cache_type_(cache_type), |
| 150 cache_size_(0), | 150 cache_size_(0), |
| 151 max_size_(0), | 151 max_size_(0), |
| 152 high_watermark_(0), | 152 high_watermark_(0), |
| 153 low_watermark_(0), | 153 low_watermark_(0), |
| 154 eviction_in_progress_(false), | 154 eviction_in_progress_(false), |
| 155 initialized_(false), | 155 initialized_(false), |
| 156 index_file_(index_file.Pass()), | 156 index_file_(std::move(index_file)), |
| 157 io_thread_(io_thread), | 157 io_thread_(io_thread), |
| 158 // Creating the callback once so it is reused every time | 158 // Creating the callback once so it is reused every time |
| 159 // write_to_disk_timer_.Start() is called. | 159 // write_to_disk_timer_.Start() is called. |
| 160 write_to_disk_cb_(base::Bind(&SimpleIndex::WriteToDisk, AsWeakPtr())), | 160 write_to_disk_cb_(base::Bind(&SimpleIndex::WriteToDisk, AsWeakPtr())), |
| 161 app_on_background_(false) { | 161 app_on_background_(false) {} |
| 162 } | |
| 163 | 162 |
| 164 SimpleIndex::~SimpleIndex() { | 163 SimpleIndex::~SimpleIndex() { |
| 165 DCHECK(io_thread_checker_.CalledOnValidThread()); | 164 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 166 | 165 |
| 167 // Fail all callbacks waiting for the index to come up. | 166 // Fail all callbacks waiting for the index to come up. |
| 168 for (CallbackList::iterator it = to_run_when_initialized_.begin(), | 167 for (CallbackList::iterator it = to_run_when_initialized_.begin(), |
| 169 end = to_run_when_initialized_.end(); it != end; ++it) { | 168 end = to_run_when_initialized_.end(); it != end; ++it) { |
| 170 it->Run(net::ERR_ABORTED); | 169 it->Run(net::ERR_ABORTED); |
| 171 } | 170 } |
| 172 } | 171 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 end_time.is_null() ? base::Time::Max() : end_time; | 221 end_time.is_null() ? base::Time::Max() : end_time; |
| 223 DCHECK(extended_end_time >= initial_time); | 222 DCHECK(extended_end_time >= initial_time); |
| 224 scoped_ptr<HashList> ret_hashes(new HashList()); | 223 scoped_ptr<HashList> ret_hashes(new HashList()); |
| 225 for (EntrySet::iterator it = entries_set_.begin(), end = entries_set_.end(); | 224 for (EntrySet::iterator it = entries_set_.begin(), end = entries_set_.end(); |
| 226 it != end; ++it) { | 225 it != end; ++it) { |
| 227 EntryMetadata& metadata = it->second; | 226 EntryMetadata& metadata = it->second; |
| 228 base::Time entry_time = metadata.GetLastUsedTime(); | 227 base::Time entry_time = metadata.GetLastUsedTime(); |
| 229 if (initial_time <= entry_time && entry_time < extended_end_time) | 228 if (initial_time <= entry_time && entry_time < extended_end_time) |
| 230 ret_hashes->push_back(it->first); | 229 ret_hashes->push_back(it->first); |
| 231 } | 230 } |
| 232 return ret_hashes.Pass(); | 231 return ret_hashes; |
| 233 } | 232 } |
| 234 | 233 |
| 235 scoped_ptr<SimpleIndex::HashList> SimpleIndex::GetAllHashes() { | 234 scoped_ptr<SimpleIndex::HashList> SimpleIndex::GetAllHashes() { |
| 236 return GetEntriesBetween(base::Time(), base::Time()); | 235 return GetEntriesBetween(base::Time(), base::Time()); |
| 237 } | 236 } |
| 238 | 237 |
| 239 int32_t SimpleIndex::GetEntryCount() const { | 238 int32_t SimpleIndex::GetEntryCount() const { |
| 240 // TODO(pasko): return a meaningful initial estimate before initialized. | 239 // TODO(pasko): return a meaningful initial estimate before initialized. |
| 241 return entries_set_.size(); | 240 return entries_set_.size(); |
| 242 } | 241 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 start - last_write_to_disk_); | 477 start - last_write_to_disk_); |
| 479 } | 478 } |
| 480 } | 479 } |
| 481 last_write_to_disk_ = start; | 480 last_write_to_disk_ = start; |
| 482 | 481 |
| 483 index_file_->WriteToDisk(entries_set_, cache_size_, | 482 index_file_->WriteToDisk(entries_set_, cache_size_, |
| 484 start, app_on_background_, base::Closure()); | 483 start, app_on_background_, base::Closure()); |
| 485 } | 484 } |
| 486 | 485 |
| 487 } // namespace disk_cache | 486 } // namespace disk_cache |
| OLD | NEW |