| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/variations/variations_associated_data.h" | 5 #include "components/variations/variations_associated_data.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 | 14 |
| 15 namespace variations { | 15 namespace variations { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kGroupTesting[] = "Testing"; |
| 20 |
| 19 // The internal singleton accessor for the map, used to keep it thread-safe. | 21 // The internal singleton accessor for the map, used to keep it thread-safe. |
| 20 class GroupMapAccessor { | 22 class GroupMapAccessor { |
| 21 public: | 23 public: |
| 22 typedef std::map<ActiveGroupId, VariationID, ActiveGroupIdCompare> | 24 typedef std::map<ActiveGroupId, VariationID, ActiveGroupIdCompare> |
| 23 GroupToIDMap; | 25 GroupToIDMap; |
| 24 | 26 |
| 25 // Retrieve the singleton. | 27 // Retrieve the singleton. |
| 26 static GroupMapAccessor* GetInstance() { | 28 static GroupMapAccessor* GetInstance() { |
| 27 return base::Singleton<GroupMapAccessor>::get(); | 29 return base::Singleton<GroupMapAccessor>::get(); |
| 28 } | 30 } |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 if (!trial) | 247 if (!trial) |
| 246 return std::string(); | 248 return std::string(); |
| 247 | 249 |
| 248 return GetVariationParamValue(trial->trial_name(), param_name); | 250 return GetVariationParamValue(trial->trial_name(), param_name); |
| 249 } | 251 } |
| 250 | 252 |
| 251 // Functions below are exposed for testing explicitly behind this namespace. | 253 // Functions below are exposed for testing explicitly behind this namespace. |
| 252 // They simply wrap existing functions in this file. | 254 // They simply wrap existing functions in this file. |
| 253 namespace testing { | 255 namespace testing { |
| 254 | 256 |
| 257 VariationParamsManager::VariationParamsManager( |
| 258 const std::string& trial_name, |
| 259 const std::map<std::string, std::string>& params) { |
| 260 SetVariationParams(trial_name, params); |
| 261 } |
| 262 |
| 263 VariationParamsManager::~VariationParamsManager() { |
| 264 ClearAllVariationIDs(); |
| 265 ClearAllVariationParams(); |
| 266 field_trial_list_.reset(); |
| 267 } |
| 268 |
| 269 void VariationParamsManager::SetVariationParams( |
| 270 const std::string& trial_name, |
| 271 const std::map<std::string, std::string>& params) { |
| 272 field_trial_list_.reset(new base::FieldTrialList(nullptr)); |
| 273 variations::AssociateVariationParams(trial_name, kGroupTesting, params); |
| 274 base::FieldTrialList::CreateFieldTrial(trial_name, kGroupTesting); |
| 275 } |
| 276 |
| 255 void ClearAllVariationIDs() { | 277 void ClearAllVariationIDs() { |
| 256 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); | 278 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); |
| 257 } | 279 } |
| 258 | 280 |
| 259 void ClearAllVariationParams() { | 281 void ClearAllVariationParams() { |
| 260 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting(); | 282 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting(); |
| 261 } | 283 } |
| 262 | 284 |
| 263 } // namespace testing | 285 } // namespace testing |
| 264 | 286 |
| 265 } // namespace variations | 287 } // namespace variations |
| OLD | NEW |