Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: components/variations/variations_associated_data.cc

Issue 2145963002: Add simpler API for changing parameters in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: A few typos. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/variations/entropy_provider.h"
14 15
15 namespace variations { 16 namespace variations {
16 17
17 namespace { 18 namespace {
18 19
20 const char kGroupTesting[] = "Testing";
21 const char kEntropy[] = "test-entropy-seed";
22
19 // The internal singleton accessor for the map, used to keep it thread-safe. 23 // The internal singleton accessor for the map, used to keep it thread-safe.
20 class GroupMapAccessor { 24 class GroupMapAccessor {
21 public: 25 public:
22 typedef std::map<ActiveGroupId, VariationID, ActiveGroupIdCompare> 26 typedef std::map<ActiveGroupId, VariationID, ActiveGroupIdCompare>
23 GroupToIDMap; 27 GroupToIDMap;
24 28
25 // Retrieve the singleton. 29 // Retrieve the singleton.
26 static GroupMapAccessor* GetInstance() { 30 static GroupMapAccessor* GetInstance() {
27 return base::Singleton<GroupMapAccessor>::get(); 31 return base::Singleton<GroupMapAccessor>::get();
28 } 32 }
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 if (!trial) 249 if (!trial)
246 return std::string(); 250 return std::string();
247 251
248 return GetVariationParamValue(trial->trial_name(), param_name); 252 return GetVariationParamValue(trial->trial_name(), param_name);
249 } 253 }
250 254
251 // Functions below are exposed for testing explicitly behind this namespace. 255 // Functions below are exposed for testing explicitly behind this namespace.
252 // They simply wrap existing functions in this file. 256 // They simply wrap existing functions in this file.
253 namespace testing { 257 namespace testing {
254 258
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(
275 new base::FieldTrialList(new metrics::SHA1EntropyProvider(kEntropy)));
Alexei Svitkine (slow) 2016/07/15 14:51:01 You can just pass nullptr here.
jkrcal 2016/07/18 13:09:01 Done.
276 variations::AssociateVariationParams(trial_name, kGroupTesting, params);
277 base::FieldTrialList::CreateFieldTrial(trial_name, kGroupTesting);
278 }
279
255 void ClearAllVariationIDs() { 280 void ClearAllVariationIDs() {
256 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); 281 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting();
257 } 282 }
258 283
259 void ClearAllVariationParams() { 284 void ClearAllVariationParams() {
260 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting(); 285 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting();
261 } 286 }
262 287
263 } // namespace testing 288 } // namespace testing
264 289
265 } // namespace variations 290 } // namespace variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698