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

Side by Side Diff: net/disk_cache/backend_impl.cc

Issue 160485: Disk cache: Open the disk cache experiment for new users.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/backend_impl.h ('k') | net/disk_cache/disk_cache_test_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/backend_impl.h" 5 #include "net/disk_cache/backend_impl.h"
6 6
7 #include "base/field_trial.h" 7 #include "base/field_trial.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/histogram.h" 10 #include "base/histogram.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 // Sets |current_group| for the current experiment. Returns false if the files 141 // Sets |current_group| for the current experiment. Returns false if the files
142 // should be discarded. 142 // should be discarded.
143 bool InitExperiment(int* current_group) { 143 bool InitExperiment(int* current_group) {
144 if (*current_group == 3 || *current_group == 4) { 144 if (*current_group == 3 || *current_group == 4) {
145 // Discard current cache for groups 3 and 4. 145 // Discard current cache for groups 3 and 4.
146 return false; 146 return false;
147 } 147 }
148 148
149 if (*current_group <= 5) { 149 if (*current_group <= 5) {
150 #if defined(UNIT_TEST)
151 // The unit test controls directly what to test.
152 *current_group = 0;
153 return true;
154 #endif
155
156 // Re-load the two groups. 150 // Re-load the two groups.
157 int option = base::RandInt(0, 9); 151 int option = base::RandInt(0, 9);
158 152
159 if (option > 1) { 153 if (option > 1) {
160 // 80% will be out of the experiment. 154 // 80% will be out of the experiment.
161 *current_group = 9; 155 *current_group = 9;
162 } else { 156 } else {
163 *current_group = option + 6; 157 *current_group = option + 6;
164 } 158 }
165 } 159 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 281
288 if (!restarted_) { 282 if (!restarted_) {
289 trace_object_ = TraceObject::GetTraceObject(); 283 trace_object_ = TraceObject::GetTraceObject();
290 // Create a recurrent timer of 30 secs. 284 // Create a recurrent timer of 30 secs.
291 int timer_delay = unit_test_ ? 1000 : 30000; 285 int timer_delay = unit_test_ ? 1000 : 30000;
292 timer_.Start(TimeDelta::FromMilliseconds(timer_delay), this, 286 timer_.Start(TimeDelta::FromMilliseconds(timer_delay), this,
293 &BackendImpl::OnStatsTimer); 287 &BackendImpl::OnStatsTimer);
294 } 288 }
295 289
296 init_ = true; 290 init_ = true;
297 if (!InitExperiment(&data_->header.experiment)) 291 if (!(user_flags_ & disk_cache::kNoRandom)) {
298 return false; 292 // The unit test controls directly what to test.
293 if (!InitExperiment(&data_->header.experiment))
294 return false;
295 }
299 296
300 if (data_->header.experiment > 6 && data_->header.experiment < 9) 297 if (data_->header.experiment > 6 && data_->header.experiment < 9)
301 new_eviction_ = true; 298 new_eviction_ = true;
302 299
303 if (!CheckIndex()) { 300 if (!CheckIndex()) {
304 ReportError(ERR_INIT_FAILED); 301 ReportError(ERR_INIT_FAILED);
305 return false; 302 return false;
306 } 303 }
307 304
308 // We don't care if the value overflows. The only thing we care about is that 305 // We don't care if the value overflows. The only thing we care about is that
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 void BackendImpl::SetUpgradeMode() { 939 void BackendImpl::SetUpgradeMode() {
943 user_flags_ |= kUpgradeMode; 940 user_flags_ |= kUpgradeMode;
944 read_only_ = true; 941 read_only_ = true;
945 } 942 }
946 943
947 void BackendImpl::SetNewEviction() { 944 void BackendImpl::SetNewEviction() {
948 user_flags_ |= kNewEviction; 945 user_flags_ |= kNewEviction;
949 new_eviction_ = true; 946 new_eviction_ = true;
950 } 947 }
951 948
949 void BackendImpl::SetFlags(uint32 flags) {
950 user_flags_ |= flags;
951 }
952
952 void BackendImpl::ClearRefCountForTest() { 953 void BackendImpl::ClearRefCountForTest() {
953 num_refs_ = 0; 954 num_refs_ = 0;
954 } 955 }
955 956
956 int BackendImpl::SelfCheck() { 957 int BackendImpl::SelfCheck() {
957 if (!init_) { 958 if (!init_) {
958 LOG(ERROR) << "Init failed"; 959 LOG(ERROR) << "Init failed";
959 return ERR_INIT_FAILED; 960 return ERR_INIT_FAILED;
960 } 961 }
961 962
(...skipping 18 matching lines...) Expand all
980 // ------------------------------------------------------------------------ 981 // ------------------------------------------------------------------------
981 982
982 // We just created a new file so we're going to write the header and set the 983 // We just created a new file so we're going to write the header and set the
983 // file length to include the hash table (zero filled). 984 // file length to include the hash table (zero filled).
984 bool BackendImpl::CreateBackingStore(disk_cache::File* file) { 985 bool BackendImpl::CreateBackingStore(disk_cache::File* file) {
985 AdjustMaxCacheSize(0); 986 AdjustMaxCacheSize(0);
986 987
987 IndexHeader header; 988 IndexHeader header;
988 header.table_len = DesiredIndexTableLen(max_size_); 989 header.table_len = DesiredIndexTableLen(max_size_);
989 990
991 // All new profiles are going to use the new eviction.
992 if (!(user_flags_ & disk_cache::kNoRandom)) {
993 header.experiment = 8;
994 new_eviction_ = true;
995 }
996
990 // We need file version 2.1 for the new eviction algorithm. 997 // We need file version 2.1 for the new eviction algorithm.
991 if (new_eviction_) 998 if (new_eviction_)
992 header.version = 0x20001; 999 header.version = 0x20001;
993 1000
994 header.create_time = Time::Now().ToInternalValue(); 1001 header.create_time = Time::Now().ToInternalValue();
995 1002
996 if (!file->Write(&header, sizeof(header), 0)) 1003 if (!file->Write(&header, sizeof(header), 0))
997 return false; 1004 return false;
998 1005
999 return file->SetLength(GetIndexSize(header.table_len)); 1006 return file->SetLength(GetIndexSize(header.table_len));
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 1645
1639 return num_dirty; 1646 return num_dirty;
1640 } 1647 }
1641 1648
1642 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { 1649 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) {
1643 RankingsNode* rankings = cache_entry->rankings()->Data(); 1650 RankingsNode* rankings = cache_entry->rankings()->Data();
1644 return !rankings->dummy; 1651 return !rankings->dummy;
1645 } 1652 }
1646 1653
1647 } // namespace disk_cache 1654 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/backend_impl.h ('k') | net/disk_cache/disk_cache_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698