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