Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/simple/simple_experiment.h" | 5 #include "net/disk_cache/simple/simple_experiment.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/metrics/field_trial_param_associator.h" | 11 #include "base/metrics/field_trial_param_associator.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 | 13 |
| 14 namespace disk_cache { | 14 namespace disk_cache { |
| 15 | 15 |
| 16 const base::Feature kSimpleSizeExperiment = {"SimpleSizeExperiment", | 16 const base::Feature kSimpleSizeExperiment = {"SimpleSizeExperiment", |
| 17 base::FEATURE_DISABLED_BY_DEFAULT}; | 17 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 18 const base::Feature kSimpleCacheEvictionWithSizeExperiment = { | |
| 19 "SimpleCacheEvictionWithSizeExperiment", base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 20 | |
| 18 const char kSizeMultiplierParam[] = "SizeMultiplier"; | 21 const char kSizeMultiplierParam[] = "SizeMultiplier"; |
| 22 const char kSizeEvictionParam[] = "SizeEviction"; | |
| 19 | 23 |
| 20 namespace { | 24 namespace { |
| 21 | 25 |
| 26 // Updates experiment if the experiment is active. | |
| 27 bool CheckForEvictionWithSizeExperiment( | |
| 28 disk_cache::SimpleExperiment* experiment) { | |
| 29 if (disk_cache::SimpleExperimentType::NONE != experiment->type) | |
|
jkarlin
2017/07/12 15:51:40
After returning early in GetSimpleExperiment you c
hubbe
2017/07/12 18:22:50
Done.
| |
| 30 return false; | |
| 31 | |
| 32 if (!base::FeatureList::IsEnabled(kSimpleCacheEvictionWithSizeExperiment)) | |
| 33 return false; | |
| 34 | |
| 35 base::FieldTrial* trial = | |
| 36 base::FeatureList::GetFieldTrial(kSimpleCacheEvictionWithSizeExperiment); | |
| 37 if (!trial) | |
| 38 return false; | |
| 39 | |
| 40 std::map<std::string, std::string> params; | |
| 41 base::FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams( | |
| 42 trial->trial_name(), ¶ms); | |
| 43 auto iter = params.find(kSizeEvictionParam); | |
| 44 if (iter == params.end()) | |
| 45 return false; | |
| 46 | |
| 47 uint32_t param; | |
| 48 if (!base::StringToUint(iter->second, ¶m)) | |
| 49 return false; | |
| 50 | |
| 51 experiment->type = disk_cache::SimpleExperimentType::SIZE; | |
|
jkarlin
2017/07/12 15:51:41
I believe you want EVICT_WITH_SIZE here ;) That wo
hubbe
2017/07/12 18:22:50
Done.
| |
| 52 experiment->param = param; | |
| 53 return true; | |
| 54 } | |
| 55 | |
| 22 // Returns true if the experiment is found and properly defined. | 56 // Returns true if the experiment is found and properly defined. |
| 23 bool CheckForSimpleSizeExperiment(disk_cache::SimpleExperiment* experiment) { | 57 bool CheckForSimpleSizeExperiment(disk_cache::SimpleExperiment* experiment) { |
| 24 DCHECK_EQ(disk_cache::SimpleExperimentType::NONE, experiment->type); | 58 DCHECK_EQ(disk_cache::SimpleExperimentType::NONE, experiment->type); |
| 25 DCHECK_EQ(0u, experiment->param); | 59 DCHECK_EQ(0u, experiment->param); |
| 26 | 60 |
| 27 if (!base::FeatureList::IsEnabled(kSimpleSizeExperiment)) | 61 if (!base::FeatureList::IsEnabled(kSimpleSizeExperiment)) |
| 28 return false; | 62 return false; |
| 29 | 63 |
| 30 base::FieldTrial* trial = | 64 base::FieldTrial* trial = |
| 31 base::FeatureList::GetFieldTrial(kSimpleSizeExperiment); | 65 base::FeatureList::GetFieldTrial(kSimpleSizeExperiment); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 50 | 84 |
| 51 } // namespace | 85 } // namespace |
| 52 | 86 |
| 53 // Returns the experiment for the given |cache_type|. | 87 // Returns the experiment for the given |cache_type|. |
| 54 SimpleExperiment GetSimpleExperiment(net::CacheType cache_type) { | 88 SimpleExperiment GetSimpleExperiment(net::CacheType cache_type) { |
| 55 SimpleExperiment experiment; | 89 SimpleExperiment experiment; |
| 56 | 90 |
| 57 if (cache_type != net::DISK_CACHE) | 91 if (cache_type != net::DISK_CACHE) |
| 58 return experiment; | 92 return experiment; |
| 59 | 93 |
| 60 CheckForSimpleSizeExperiment(&experiment); | 94 CheckForSimpleSizeExperiment(&experiment); |
|
jkarlin
2017/07/12 15:51:41
Can you have each check return early if they retur
hubbe
2017/07/12 18:22:50
Done.
| |
| 95 CheckForEvictionWithSizeExperiment(&experiment); | |
| 61 return experiment; | 96 return experiment; |
| 62 } | 97 } |
| 63 | 98 |
| 64 } // namespace disk_cache | 99 } // namespace disk_cache |
| OLD | NEW |