| 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/mem_backend_impl.h" | 5 #include "net/disk_cache/mem_backend_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/disk_cache/cache_util.h" | 10 #include "net/disk_cache/cache_util.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 return true; | 243 return true; |
| 244 } | 244 } |
| 245 | 245 |
| 246 bool MemBackendImpl::DoomEntriesBetween(const Time initial_time, | 246 bool MemBackendImpl::DoomEntriesBetween(const Time initial_time, |
| 247 const Time end_time) { | 247 const Time end_time) { |
| 248 if (end_time.is_null()) | 248 if (end_time.is_null()) |
| 249 return DoomEntriesSince(initial_time); | 249 return DoomEntriesSince(initial_time); |
| 250 | 250 |
| 251 DCHECK(end_time >= initial_time); | 251 DCHECK(end_time >= initial_time); |
| 252 | 252 |
| 253 MemEntryImpl* next = rankings_.GetNext(NULL); | 253 MemEntryImpl* node = rankings_.GetNext(NULL); |
| 254 // Last valid entry before |node|. |
| 255 // Note, that entries after |node| may become invalid during |node| doom in |
| 256 // case when they are child entries of it. It is guaranteed that |
| 257 // parent node will go prior to it childs in ranking list (see |
| 258 // InternalReadSparseData and InternalWriteSparseData). |
| 259 MemEntryImpl* last_valid = NULL; |
| 254 | 260 |
| 255 // rankings_ is ordered by last used, this will descend through the cache | 261 // rankings_ is ordered by last used, this will descend through the cache |
| 256 // and start dooming items before the end_time, and will stop once it reaches | 262 // and start dooming items before the end_time, and will stop once it reaches |
| 257 // an item used before the initial time. | 263 // an item used before the initial time. |
| 258 while (next) { | 264 while (node) { |
| 259 MemEntryImpl* node = next; | |
| 260 next = rankings_.GetNext(next); | |
| 261 | |
| 262 if (node->GetLastUsed() < initial_time) | 265 if (node->GetLastUsed() < initial_time) |
| 263 break; | 266 break; |
| 264 | 267 |
| 265 if (node->GetLastUsed() < end_time) | 268 if (node->GetLastUsed() < end_time) |
| 266 node->Doom(); | 269 node->Doom(); |
| 270 else |
| 271 last_valid = node; |
| 272 node = rankings_.GetNext(last_valid); |
| 267 } | 273 } |
| 268 | 274 |
| 269 return true; | 275 return true; |
| 270 } | 276 } |
| 271 | 277 |
| 272 bool MemBackendImpl::DoomEntriesSince(const Time initial_time) { | 278 bool MemBackendImpl::DoomEntriesSince(const Time initial_time) { |
| 273 for (;;) { | 279 for (;;) { |
| 274 // Get the entry in the front. | 280 // Get the entry in the front. |
| 275 Entry* entry = rankings_.GetNext(NULL); | 281 Entry* entry = rankings_.GetNext(NULL); |
| 276 | 282 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 if (current_size_ > max_size_) | 328 if (current_size_ > max_size_) |
| 323 TrimCache(false); | 329 TrimCache(false); |
| 324 } | 330 } |
| 325 | 331 |
| 326 void MemBackendImpl::SubstractStorageSize(int32 bytes) { | 332 void MemBackendImpl::SubstractStorageSize(int32 bytes) { |
| 327 current_size_ -= bytes; | 333 current_size_ -= bytes; |
| 328 DCHECK_GE(current_size_, 0); | 334 DCHECK_GE(current_size_, 0); |
| 329 } | 335 } |
| 330 | 336 |
| 331 } // namespace disk_cache | 337 } // namespace disk_cache |
| OLD | NEW |