| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 174 |
| 175 int MemBackendImpl::DoomAllEntries(const CompletionCallback& callback) { | 175 int MemBackendImpl::DoomAllEntries(const CompletionCallback& callback) { |
| 176 return DoomEntriesBetween(Time(), Time(), callback); | 176 return DoomEntriesBetween(Time(), Time(), callback); |
| 177 } | 177 } |
| 178 | 178 |
| 179 int MemBackendImpl::DoomEntriesBetween(Time initial_time, | 179 int MemBackendImpl::DoomEntriesBetween(Time initial_time, |
| 180 Time end_time, | 180 Time end_time, |
| 181 const CompletionCallback& callback) { | 181 const CompletionCallback& callback) { |
| 182 if (end_time.is_null()) | 182 if (end_time.is_null()) |
| 183 end_time = Time::Max(); | 183 end_time = Time::Max(); |
| 184 | |
| 185 DCHECK_GE(end_time, initial_time); | 184 DCHECK_GE(end_time, initial_time); |
| 186 | 185 |
| 187 base::LinkNode<MemEntryImpl>* node = lru_list_.head(); | 186 base::LinkNode<MemEntryImpl>* node = lru_list_.head(); |
| 188 while (node != lru_list_.end() && node->value()->GetLastUsed() < initial_time) | 187 while (node != lru_list_.end() && node->value()->GetLastUsed() < initial_time) |
| 189 node = node->next(); | 188 node = node->next(); |
| 190 while (node != lru_list_.end() && node->value()->GetLastUsed() < end_time) { | 189 while (node != lru_list_.end() && node->value()->GetLastUsed() < end_time) { |
| 191 MemEntryImpl* to_doom = node->value(); | 190 MemEntryImpl* to_doom = node->value(); |
| 192 node = node->next(); | 191 node = node->next(); |
| 193 to_doom->Doom(); | 192 to_doom->Doom(); |
| 194 } | 193 } |
| 195 | 194 |
| 196 return net::OK; | 195 return net::OK; |
| 197 } | 196 } |
| 198 | 197 |
| 199 int MemBackendImpl::DoomEntriesSince(Time initial_time, | 198 int MemBackendImpl::DoomEntriesSince(Time initial_time, |
| 200 const CompletionCallback& callback) { | 199 const CompletionCallback& callback) { |
| 201 return DoomEntriesBetween(initial_time, Time::Max(), callback); | 200 return DoomEntriesBetween(initial_time, Time::Max(), callback); |
| 202 } | 201 } |
| 203 | 202 |
| 204 int MemBackendImpl::CalculateSizeOfAllEntries( | 203 int MemBackendImpl::CalculateSizeOfAllEntries( |
| 205 const CompletionCallback& callback) { | 204 const CompletionCallback& callback) { |
| 206 return current_size_; | 205 return current_size_; |
| 207 } | 206 } |
| 208 | 207 |
| 208 int MemBackendImpl::CalculateSizeOfEntriesBetween( |
| 209 base::Time initial_time, |
| 210 base::Time end_time, |
| 211 const CompletionCallback& callback) { |
| 212 if (end_time.is_null()) |
| 213 end_time = Time::Max(); |
| 214 DCHECK_GE(end_time, initial_time); |
| 215 |
| 216 int size = 0; |
| 217 base::LinkNode<MemEntryImpl>* node = lru_list_.head(); |
| 218 while (node != lru_list_.end() && node->value()->GetLastUsed() < initial_time) |
| 219 node = node->next(); |
| 220 while (node != lru_list_.end() && node->value()->GetLastUsed() < end_time) { |
| 221 MemEntryImpl* entry = node->value(); |
| 222 size += entry->GetStorageSize(); |
| 223 node = node->next(); |
| 224 } |
| 225 return size; |
| 226 } |
| 227 |
| 209 class MemBackendImpl::MemIterator final : public Backend::Iterator { | 228 class MemBackendImpl::MemIterator final : public Backend::Iterator { |
| 210 public: | 229 public: |
| 211 explicit MemIterator(base::WeakPtr<MemBackendImpl> backend) | 230 explicit MemIterator(base::WeakPtr<MemBackendImpl> backend) |
| 212 : backend_(backend) {} | 231 : backend_(backend) {} |
| 213 | 232 |
| 214 int OpenNextEntry(Entry** next_entry, | 233 int OpenNextEntry(Entry** next_entry, |
| 215 const CompletionCallback& callback) override { | 234 const CompletionCallback& callback) override { |
| 216 if (!backend_) | 235 if (!backend_) |
| 217 return net::ERR_FAILED; | 236 return net::ERR_FAILED; |
| 218 | 237 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 base::LinkNode<MemEntryImpl>* entry = lru_list_.head(); | 292 base::LinkNode<MemEntryImpl>* entry = lru_list_.head(); |
| 274 while (current_size_ > target_size && entry != lru_list_.end()) { | 293 while (current_size_ > target_size && entry != lru_list_.end()) { |
| 275 MemEntryImpl* to_doom = entry->value(); | 294 MemEntryImpl* to_doom = entry->value(); |
| 276 entry = entry->next(); | 295 entry = entry->next(); |
| 277 if (!to_doom->InUse()) | 296 if (!to_doom->InUse()) |
| 278 to_doom->Doom(); | 297 to_doom->Doom(); |
| 279 } | 298 } |
| 280 } | 299 } |
| 281 | 300 |
| 282 } // namespace disk_cache | 301 } // namespace disk_cache |
| OLD | NEW |