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 | |
|
Alexei Svitkine (slow)
2016/09/12 16:54:13
Nit: Remove empty line
jkrcal
2016/09/23 13:40:09
Done.
| |
| 16 namespace testing { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 const char kGroupTesting[] = "Testing"; | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 VariationParamsManager::VariationParamsManager() | |
| 25 : field_trial_list_(new base::FieldTrialList(nullptr)), | |
| 26 scoped_feature_list_(new base::test::ScopedFeatureList()) {} | |
| 27 | |
| 28 VariationParamsManager::VariationParamsManager( | |
| 29 const std::string& trial_name, | |
| 30 const std::map<std::string, std::string>& param_values, | |
| 31 const std::map<std::string, std::string>& param_features) | |
| 32 : VariationParamsManager() { | |
| 33 SetVariationParams(trial_name, param_values, param_features); | |
| 34 } | |
| 35 | |
| 36 VariationParamsManager::~VariationParamsManager() { | |
| 37 ClearAllVariationIDs(); | |
| 38 ClearAllVariationParams(); | |
| 39 } | |
| 40 | |
| 41 void VariationParamsManager::SetVariationParams( | |
| 42 const std::string& trial_name, | |
| 43 const std::map<std::string, std::string>& param_values, | |
| 44 const std::map<std::string, std::string>& param_features) { | |
| 45 variations::AssociateVariationParams(trial_name, kGroupTesting, param_values); | |
| 46 base::FieldTrial* field_trial = | |
| 47 base::FieldTrialList::CreateFieldTrial(trial_name, kGroupTesting); | |
| 48 | |
| 49 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
| 50 for (auto& pair : param_features) { | |
| 51 feature_list->RegisterFieldTrialOverride( | |
| 52 pair.second /* name of the feature */, | |
| 53 base::FeatureList::OverrideState::OVERRIDE_ENABLE_FEATURE, | |
| 54 field_trial); | |
| 55 } | |
| 56 | |
| 57 scoped_feature_list_->InitWithFeatureList(std::move(feature_list)); | |
| 58 } | |
| 59 | |
| 60 void VariationParamsManager::ClearAllVariationIDs() { | |
| 61 variations::testing::ClearAllVariationIDs(); | |
| 62 } | |
| 63 | |
| 64 void VariationParamsManager::ClearAllVariationParams() { | |
| 65 variations::testing::ClearAllVariationParams(); | |
| 66 // When the scoped feature list is destroyed, it puts back the original | |
| 67 // feature list that was there when InitWithFeatureList() was called. | |
| 68 scoped_feature_list_.reset(new base::test::ScopedFeatureList()); | |
| 69 } | |
| 70 | |
| 71 } // namespace testing | |
| 72 | |
|
Alexei Svitkine (slow)
2016/09/12 16:54:13
Nit: Remove empty line
jkrcal
2016/09/23 13:40:09
Done.
| |
| 73 } // namespace variations | |
| OLD | NEW |