Index: net/disk_cache/eviction.cc |
=================================================================== |
--- net/disk_cache/eviction.cc (revision 84533) |
+++ net/disk_cache/eviction.cc (working copy) |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -116,7 +116,7 @@ |
Rankings::ScopedRankingsBlock next(rankings_, |
rankings_->GetPrev(node.get(), Rankings::NO_USE)); |
int target_size = empty ? 0 : max_size_; |
- while (header_->num_bytes > target_size && next.get()) { |
+ while ((header_->num_bytes > target_size && next.get()) || test_mode_) { |
// The iterator could be invalidated within EvictEntry(). |
if (!next->HasData()) |
break; |
@@ -304,15 +304,8 @@ |
} |
// If we are not meeting the time targets lets move on to list length. |
- if (!empty && Rankings::LAST_ELEMENT == list) { |
- list = SelectListByLenght(); |
- // Make sure that frequently used items are kept for a minimum time; we know |
- // that this entry is not older than its current target, but it must be at |
- // least older than the target for list 0 (kTargetTime). |
- if ((Rankings::HIGH_USE == list || Rankings::LOW_USE == list) && |
- !NodeIsOldEnough(next[list].get(), 0)) |
- list = 0; |
- } |
+ if (!empty && Rankings::LAST_ELEMENT == list) |
+ list = SelectListByLenght(next); |
if (empty) |
list = 0; |
@@ -321,7 +314,8 @@ |
int target_size = empty ? 0 : max_size_; |
for (; list < kListsToSearch; list++) { |
- while (header_->num_bytes > target_size && next[list].get()) { |
+ while ((header_->num_bytes > target_size && next[list].get()) || |
+ test_mode_) { |
// The iterator could be invalidated within EvictEntry(). |
if (!next[list]->HasData()) |
break; |
@@ -514,15 +508,24 @@ |
return (Time::Now() - used).InHours() > kTargetTime * multiplier; |
} |
-int Eviction::SelectListByLenght() { |
+int Eviction::SelectListByLenght(Rankings::ScopedRankingsBlock* next) { |
int data_entries = header_->num_entries - |
header_->lru.sizes[Rankings::DELETED]; |
// Start by having each list to be roughly the same size. |
if (header_->lru.sizes[0] > data_entries / 3) |
return 0; |
- if (header_->lru.sizes[1] > data_entries / 3) |
- return 1; |
- return 2; |
+ |
+ int list = (header_->lru.sizes[1] > data_entries / 3) ? 1 : 2; |
+ |
+ // Make sure that frequently used items are kept for a minimum time; we know |
+ // that this entry is not older than its current target, but it must be at |
+ // least older than the target for list 0 (kTargetTime), as long as we don't |
+ // exhaust list 0. |
+ if (!NodeIsOldEnough(next[list].get(), 0) && |
+ header_->lru.sizes[0] > data_entries / 10) |
+ list = 0; |
+ |
+ return list; |
} |
void Eviction::ReportListStats() { |