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/backend_impl.h" | 5 #include "net/disk_cache/backend_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 size_t GetIndexSize(int table_len) { | 70 size_t GetIndexSize(int table_len) { |
71 size_t table_size = sizeof(disk_cache::CacheAddr) * table_len; | 71 size_t table_size = sizeof(disk_cache::CacheAddr) * table_len; |
72 return sizeof(disk_cache::IndexHeader) + table_size; | 72 return sizeof(disk_cache::IndexHeader) + table_size; |
73 } | 73 } |
74 | 74 |
75 // ------------------------------------------------------------------------ | 75 // ------------------------------------------------------------------------ |
76 | 76 |
77 // Sets group for the current experiment. Returns false if the files should be | 77 // Sets group for the current experiment. Returns false if the files should be |
78 // discarded. | 78 // discarded. |
79 bool InitExperiment(disk_cache::IndexHeader* header) { | 79 bool InitExperiment(disk_cache::IndexHeader* header, bool cache_created) { |
80 if (header->experiment == disk_cache::EXPERIMENT_OLD_FILE1 || | 80 if (header->experiment == disk_cache::EXPERIMENT_OLD_FILE1 || |
81 header->experiment == disk_cache::EXPERIMENT_OLD_FILE2) { | 81 header->experiment == disk_cache::EXPERIMENT_OLD_FILE2) { |
82 // Discard current cache. | 82 // Discard current cache. |
83 return false; | 83 return false; |
84 } | 84 } |
85 | 85 |
| 86 if (base::FieldTrialList::FindFullName("SimpleCacheTrial") == |
| 87 "ExperimentControl") { |
| 88 if (cache_created) { |
| 89 header->experiment = disk_cache::EXPERIMENT_SIMPLE_CONTROL; |
| 90 return true; |
| 91 } else if (header->experiment != disk_cache::EXPERIMENT_SIMPLE_CONTROL) { |
| 92 return false; |
| 93 } |
| 94 } |
| 95 |
86 header->experiment = disk_cache::NO_EXPERIMENT; | 96 header->experiment = disk_cache::NO_EXPERIMENT; |
87 return true; | 97 return true; |
88 } | 98 } |
89 | 99 |
90 // A callback to perform final cleanup on the background thread. | 100 // A callback to perform final cleanup on the background thread. |
91 void FinalCleanupCallback(disk_cache::BackendImpl* backend) { | 101 void FinalCleanupCallback(disk_cache::BackendImpl* backend) { |
92 backend->CleanupCache(); | 102 backend->CleanupCache(); |
93 } | 103 } |
94 | 104 |
95 } // namespace | 105 } // namespace |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 261 } |
252 | 262 |
253 if (!CheckIndex()) { | 263 if (!CheckIndex()) { |
254 ReportError(ERR_INIT_FAILED); | 264 ReportError(ERR_INIT_FAILED); |
255 return net::ERR_FAILED; | 265 return net::ERR_FAILED; |
256 } | 266 } |
257 | 267 |
258 if (!restarted_ && (create_files || !data_->header.num_entries)) | 268 if (!restarted_ && (create_files || !data_->header.num_entries)) |
259 ReportError(ERR_CACHE_CREATED); | 269 ReportError(ERR_CACHE_CREATED); |
260 | 270 |
261 if (!(user_flags_ & kNoRandom) && | 271 if (!(user_flags_ & kNoRandom) && cache_type_ == net::DISK_CACHE && |
262 cache_type_ == net::DISK_CACHE && !InitExperiment(&data_->header)) | 272 !InitExperiment(&data_->header, create_files)) { |
263 return net::ERR_FAILED; | 273 return net::ERR_FAILED; |
| 274 } |
264 | 275 |
265 // We don't care if the value overflows. The only thing we care about is that | 276 // We don't care if the value overflows. The only thing we care about is that |
266 // the id cannot be zero, because that value is used as "not dirty". | 277 // the id cannot be zero, because that value is used as "not dirty". |
267 // Increasing the value once per second gives us many years before we start | 278 // Increasing the value once per second gives us many years before we start |
268 // having collisions. | 279 // having collisions. |
269 data_->header.this_id++; | 280 data_->header.this_id++; |
270 if (!data_->header.this_id) | 281 if (!data_->header.this_id) |
271 data_->header.this_id++; | 282 data_->header.this_id++; |
272 | 283 |
273 bool previous_crash = (data_->header.crash != 0); | 284 bool previous_crash = (data_->header.crash != 0); |
(...skipping 1769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 if (total_memory > kMaxBuffersSize || total_memory <= 0) | 2054 if (total_memory > kMaxBuffersSize || total_memory <= 0) |
2044 total_memory = kMaxBuffersSize; | 2055 total_memory = kMaxBuffersSize; |
2045 | 2056 |
2046 done = true; | 2057 done = true; |
2047 } | 2058 } |
2048 | 2059 |
2049 return static_cast<int>(total_memory); | 2060 return static_cast<int>(total_memory); |
2050 } | 2061 } |
2051 | 2062 |
2052 } // namespace disk_cache | 2063 } // namespace disk_cache |
OLD | NEW |