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

Side by Side Diff: net/disk_cache/simple/simple_index.cc

Issue 2626173003: Calculate the size of all cache entries between two points in time. (Closed)
Patch Set: revert cache_storage_cache_unittest.cc Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « net/disk_cache/simple/simple_index.h ('k') | net/net.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 base::Time initial_time, 213 base::Time initial_time,
214 base::Time end_time) { 214 base::Time end_time) {
215 DCHECK_EQ(true, initialized_); 215 DCHECK_EQ(true, initialized_);
216 216
217 if (!initial_time.is_null()) 217 if (!initial_time.is_null())
218 initial_time -= EntryMetadata::GetLowerEpsilonForTimeComparisons(); 218 initial_time -= EntryMetadata::GetLowerEpsilonForTimeComparisons();
219 if (end_time.is_null()) 219 if (end_time.is_null())
220 end_time = base::Time::Max(); 220 end_time = base::Time::Max();
221 else 221 else
222 end_time += EntryMetadata::GetUpperEpsilonForTimeComparisons(); 222 end_time += EntryMetadata::GetUpperEpsilonForTimeComparisons();
223 const base::Time extended_end_time = 223 DCHECK(end_time >= initial_time);
224 end_time.is_null() ? base::Time::Max() : end_time; 224
225 DCHECK(extended_end_time >= initial_time);
226 std::unique_ptr<HashList> ret_hashes(new HashList()); 225 std::unique_ptr<HashList> ret_hashes(new HashList());
227 for (EntrySet::iterator it = entries_set_.begin(), end = entries_set_.end(); 226 for (const auto& entry : entries_set_) {
228 it != end; ++it) { 227 const EntryMetadata& metadata = entry.second;
229 EntryMetadata& metadata = it->second;
230 base::Time entry_time = metadata.GetLastUsedTime(); 228 base::Time entry_time = metadata.GetLastUsedTime();
231 if (initial_time <= entry_time && entry_time < extended_end_time) 229 if (initial_time <= entry_time && entry_time < end_time)
232 ret_hashes->push_back(it->first); 230 ret_hashes->push_back(entry.first);
233 } 231 }
234 return ret_hashes; 232 return ret_hashes;
235 } 233 }
236 234
237 std::unique_ptr<SimpleIndex::HashList> SimpleIndex::GetAllHashes() { 235 std::unique_ptr<SimpleIndex::HashList> SimpleIndex::GetAllHashes() {
238 return GetEntriesBetween(base::Time(), base::Time()); 236 return GetEntriesBetween(base::Time(), base::Time());
239 } 237 }
240 238
241 int32_t SimpleIndex::GetEntryCount() const { 239 int32_t SimpleIndex::GetEntryCount() const {
242 // TODO(pasko): return a meaningful initial estimate before initialized. 240 // TODO(pasko): return a meaningful initial estimate before initialized.
243 return entries_set_.size(); 241 return entries_set_.size();
244 } 242 }
245 243
246 uint64_t SimpleIndex::GetCacheSize() const { 244 uint64_t SimpleIndex::GetCacheSize() const {
247 DCHECK(initialized_); 245 DCHECK(initialized_);
248 return cache_size_; 246 return cache_size_;
249 } 247 }
250 248
249 uint64_t SimpleIndex::GetCacheSizeBetween(base::Time initial_time,
250 base::Time end_time) const {
251 DCHECK_EQ(true, initialized_);
252
253 if (!initial_time.is_null())
254 initial_time -= EntryMetadata::GetLowerEpsilonForTimeComparisons();
255 if (end_time.is_null())
256 end_time = base::Time::Max();
257 else
258 end_time += EntryMetadata::GetUpperEpsilonForTimeComparisons();
259
260 DCHECK(end_time >= initial_time);
261 uint64_t size = 0;
262 for (const auto& entry : entries_set_) {
263 const EntryMetadata& metadata = entry.second;
264 base::Time entry_time = metadata.GetLastUsedTime();
265 if (initial_time <= entry_time && entry_time < end_time)
266 size += metadata.GetEntrySize();
267 }
268 return size;
269 }
270
251 void SimpleIndex::Insert(uint64_t entry_hash) { 271 void SimpleIndex::Insert(uint64_t entry_hash) {
252 DCHECK(io_thread_checker_.CalledOnValidThread()); 272 DCHECK(io_thread_checker_.CalledOnValidThread());
253 // Upon insert we don't know yet the size of the entry. 273 // Upon insert we don't know yet the size of the entry.
254 // It will be updated later when the SimpleEntryImpl finishes opening or 274 // It will be updated later when the SimpleEntryImpl finishes opening or
255 // creating the new entry, and then UpdateEntrySize will be called. 275 // creating the new entry, and then UpdateEntrySize will be called.
256 InsertInEntrySet(entry_hash, EntryMetadata(base::Time::Now(), 0u), 276 InsertInEntrySet(entry_hash, EntryMetadata(base::Time::Now(), 0u),
257 &entries_set_); 277 &entries_set_);
258 if (!initialized_) 278 if (!initialized_)
259 removed_entries_.erase(entry_hash); 279 removed_entries_.erase(entry_hash);
260 PostponeWritingToDisk(); 280 PostponeWritingToDisk();
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 start - last_write_to_disk_); 518 start - last_write_to_disk_);
499 } 519 }
500 } 520 }
501 last_write_to_disk_ = start; 521 last_write_to_disk_ = start;
502 522
503 index_file_->WriteToDisk(reason, entries_set_, cache_size_, start, 523 index_file_->WriteToDisk(reason, entries_set_, cache_size_, start,
504 app_on_background_, base::Closure()); 524 app_on_background_, base::Closure());
505 } 525 }
506 526
507 } // namespace disk_cache 527 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_index.h ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698