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

Side by Side Diff: net/disk_cache/memory/mem_backend_impl.cc

Issue 2626173003: Calculate the size of all cache entries between two points in time. (Closed)
Patch Set: fix unit_tests compilation 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/mem_backend_impl.h" 5 #include "net/disk_cache/memory/mem_backend_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 int MemBackendImpl::DoomEntriesSince(Time initial_time, 199 int MemBackendImpl::DoomEntriesSince(Time initial_time,
200 const CompletionCallback& callback) { 200 const CompletionCallback& callback) {
201 return DoomEntriesBetween(initial_time, Time::Max(), callback); 201 return DoomEntriesBetween(initial_time, Time::Max(), callback);
202 } 202 }
203 203
204 int MemBackendImpl::CalculateSizeOfAllEntries( 204 int MemBackendImpl::CalculateSizeOfAllEntries(
205 const CompletionCallback& callback) { 205 const CompletionCallback& callback) {
206 return current_size_; 206 return current_size_;
207 } 207 }
208 208
209 int MemBackendImpl::CalculateSizeOfEntriesBetween(
210 base::Time initial_time,
211 base::Time end_time,
212 const CompletionCallback& callback) {
213 if (end_time.is_null())
214 end_time = Time::Max();
gavinp 2017/01/12 16:07:36 If you're going to cut and paste from DoomEntriesB
dullweber 2017/01/12 17:03:15 Done.
215 DCHECK_GE(end_time, initial_time);
216
217 int size = 0;
218 base::LinkNode<MemEntryImpl>* node = lru_list_.head();
219 while (node != lru_list_.end() && node->value()->GetLastUsed() < initial_time)
220 node = node->next();
221 while (node != lru_list_.end() && node->value()->GetLastUsed() < end_time) {
222 MemEntryImpl* entry = node->value();
223 size += entry->GetStorageSize();
224 node = node->next();
225 }
226 return size;
227 }
228
209 class MemBackendImpl::MemIterator final : public Backend::Iterator { 229 class MemBackendImpl::MemIterator final : public Backend::Iterator {
210 public: 230 public:
211 explicit MemIterator(base::WeakPtr<MemBackendImpl> backend) 231 explicit MemIterator(base::WeakPtr<MemBackendImpl> backend)
212 : backend_(backend) {} 232 : backend_(backend) {}
213 233
214 int OpenNextEntry(Entry** next_entry, 234 int OpenNextEntry(Entry** next_entry,
215 const CompletionCallback& callback) override { 235 const CompletionCallback& callback) override {
216 if (!backend_) 236 if (!backend_)
217 return net::ERR_FAILED; 237 return net::ERR_FAILED;
218 238
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 base::LinkNode<MemEntryImpl>* entry = lru_list_.head(); 293 base::LinkNode<MemEntryImpl>* entry = lru_list_.head();
274 while (current_size_ > target_size && entry != lru_list_.end()) { 294 while (current_size_ > target_size && entry != lru_list_.end()) {
275 MemEntryImpl* to_doom = entry->value(); 295 MemEntryImpl* to_doom = entry->value();
276 entry = entry->next(); 296 entry = entry->next();
277 if (!to_doom->InUse()) 297 if (!to_doom->InUse())
278 to_doom->Doom(); 298 to_doom->Doom();
279 } 299 }
280 } 300 }
281 301
282 } // namespace disk_cache 302 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698