Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/variations/variations_params_manager.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/feature_list.h" | |
| 10 #include "base/metrics/field_trial.h" | |
| 11 #include "base/test/scoped_feature_list.h" | |
| 12 #include "components/variations/variations_associated_data.h" | |
| 13 | |
| 14 namespace variations { | |
| 15 namespace testing { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 const char kGroupTesting[] = "Testing"; | |
|
Alexei Svitkine (slow)
2016/11/24 19:29:40
Nit: Add a comment about how this is used.
jkrcal
2016/11/25 13:23:37
Done.
| |
| 20 | |
| 21 base::FieldTrial* CreateFieldTrialWithParams( | |
| 22 const std::string& trial_name, | |
| 23 const std::map<std::string, std::string>& param_values) { | |
| 24 variations::AssociateVariationParams(trial_name, kGroupTesting, param_values); | |
|
Alexei Svitkine (slow)
2016/11/24 19:29:40
Nit: No need for variations:: here
jkrcal
2016/11/25 13:23:37
Done.
| |
| 25 return base::FieldTrialList::CreateFieldTrial(trial_name, kGroupTesting); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 VariationParamsManager::VariationParamsManager() | |
| 31 : field_trial_list_(new base::FieldTrialList(nullptr)), | |
| 32 scoped_feature_list_(new base::test::ScopedFeatureList()) {} | |
| 33 | |
| 34 VariationParamsManager::VariationParamsManager( | |
| 35 const std::string& trial_name, | |
| 36 const std::map<std::string, std::string>& param_values) | |
| 37 : VariationParamsManager() { | |
| 38 SetVariationParams(trial_name, param_values); | |
| 39 } | |
| 40 | |
| 41 VariationParamsManager::VariationParamsManager( | |
| 42 const std::string& trial_name, | |
| 43 const std::map<std::string, std::string>& param_values, | |
| 44 const std::set<std::string>& associated_features) | |
| 45 : VariationParamsManager() { | |
| 46 SetVariationParamsWithFeatureAssociations(trial_name, param_values, | |
| 47 associated_features); | |
| 48 } | |
| 49 | |
| 50 VariationParamsManager::~VariationParamsManager() { | |
| 51 ClearAllVariationIDs(); | |
| 52 ClearAllVariationParams(); | |
| 53 } | |
| 54 | |
| 55 void VariationParamsManager::SetVariationParams( | |
| 56 const std::string& trial_name, | |
| 57 const std::map<std::string, std::string>& param_values) { | |
| 58 CreateFieldTrialWithParams(trial_name, param_values); | |
| 59 } | |
| 60 | |
| 61 void VariationParamsManager::SetVariationParamsWithFeatureAssociations( | |
| 62 const std::string& trial_name, | |
| 63 const std::map<std::string, std::string>& param_values, | |
| 64 const std::set<std::string>& associated_features) { | |
| 65 base::FieldTrial* field_trial = | |
| 66 CreateFieldTrialWithParams(trial_name, param_values); | |
| 67 | |
| 68 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
| 69 for (const std::string& feature_name : associated_features) { | |
| 70 feature_list->RegisterFieldTrialOverride( | |
| 71 feature_name, | |
| 72 base::FeatureList::OverrideState::OVERRIDE_ENABLE_FEATURE, | |
| 73 field_trial); | |
| 74 } | |
| 75 | |
| 76 scoped_feature_list_->InitWithFeatureList(std::move(feature_list)); | |
| 77 } | |
| 78 | |
| 79 void VariationParamsManager::ClearAllVariationIDs() { | |
| 80 variations::testing::ClearAllVariationIDs(); | |
|
Alexei Svitkine (slow)
2016/11/24 19:29:40
Nit: Remove namespaces
jkrcal
2016/11/25 13:23:37
I guess I cannot remove it here and below as it wo
| |
| 81 } | |
| 82 | |
| 83 void VariationParamsManager::ClearAllVariationParams() { | |
| 84 variations::testing::ClearAllVariationParams(); | |
|
Alexei Svitkine (slow)
2016/11/24 19:29:40
Nit: Ditto.
jkrcal
2016/11/25 13:23:37
Ditto.
| |
| 85 // When the scoped feature list is destroyed, it puts back the original | |
| 86 // feature list that was there when InitWithFeatureList() was called. | |
| 87 scoped_feature_list_.reset(new base::test::ScopedFeatureList()); | |
| 88 } | |
| 89 | |
| 90 } // namespace testing | |
| 91 } // namespace variations | |
| OLD | NEW |