Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 |
| OLD | NEW |