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

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

Issue 2321273003: Extend VariationParamsManager to support feature associations. (Closed)
Patch Set: Last comments Created 4 years 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 "base/metrics/field_trial.h"
14 #include "base/metrics/field_trial_param_associator.h" 15 #include "base/metrics/field_trial_param_associator.h"
15 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
16 #include "components/variations/variations_http_header_provider.h" 17 #include "components/variations/variations_http_header_provider.h"
17 18
18 namespace variations { 19 namespace variations {
19 20
20 namespace { 21 namespace {
21 22
22 const char kGroupTesting[] = "Testing";
23
24 // 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.
25 class GroupMapAccessor { 24 class GroupMapAccessor {
26 public: 25 public:
27 typedef std::map<ActiveGroupId, VariationID, ActiveGroupIdCompare> 26 typedef std::map<ActiveGroupId, VariationID, ActiveGroupIdCompare>
28 GroupToIDMap; 27 GroupToIDMap;
29 28
30 // Retrieve the singleton. 29 // Retrieve the singleton.
31 static GroupMapAccessor* GetInstance() { 30 static GroupMapAccessor* GetInstance() {
32 return base::Singleton<GroupMapAccessor>::get(); 31 return base::Singleton<GroupMapAccessor>::get();
33 } 32 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if (!trial) 187 if (!trial)
189 return std::string(); 188 return std::string();
190 189
191 return GetVariationParamValue(trial->trial_name(), param_name); 190 return GetVariationParamValue(trial->trial_name(), param_name);
192 } 191 }
193 192
194 // Functions below are exposed for testing explicitly behind this namespace. 193 // Functions below are exposed for testing explicitly behind this namespace.
195 // They simply wrap existing functions in this file. 194 // They simply wrap existing functions in this file.
196 namespace testing { 195 namespace testing {
197 196
198 VariationParamsManager::VariationParamsManager(
199 const std::string& trial_name,
200 const std::map<std::string, std::string>& params) {
201 SetVariationParams(trial_name, params);
202 }
203
204 VariationParamsManager::~VariationParamsManager() {
205 ClearAllVariationIDs();
206 ClearAllVariationParams();
207 field_trial_list_.reset();
208 }
209
210 void VariationParamsManager::SetVariationParams(
211 const std::string& trial_name,
212 const std::map<std::string, std::string>& params) {
213 field_trial_list_.reset(new base::FieldTrialList(nullptr));
214 variations::AssociateVariationParams(trial_name, kGroupTesting, params);
215 base::FieldTrialList::CreateFieldTrial(trial_name, kGroupTesting);
216 }
217
218 void ClearAllVariationIDs() { 197 void ClearAllVariationIDs() {
219 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); 198 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting();
220 } 199 }
221 200
222 void ClearAllVariationParams() { 201 void ClearAllVariationParams() {
223 base::FieldTrialParamAssociator::GetInstance()->ClearAllParamsForTesting(); 202 base::FieldTrialParamAssociator::GetInstance()->ClearAllParamsForTesting();
224 } 203 }
225 204
226 } // namespace testing 205 } // namespace testing
227 206
228 } // namespace variations 207 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/variations_associated_data.h ('k') | components/variations/variations_params_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698