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

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

Issue 1941963002: Add variations params api to get params from features. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
13 14
14 namespace variations { 15 namespace variations {
15 16
16 namespace { 17 namespace {
17 18
18 // The internal singleton accessor for the map, used to keep it thread-safe. 19 // The internal singleton accessor for the map, used to keep it thread-safe.
19 class GroupMapAccessor { 20 class GroupMapAccessor {
20 public: 21 public:
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 return VariationsParamAssociator::GetInstance()->AssociateVariationParams( 206 return VariationsParamAssociator::GetInstance()->AssociateVariationParams(
206 trial_name, group_name, params); 207 trial_name, group_name, params);
207 } 208 }
208 209
209 bool GetVariationParams(const std::string& trial_name, 210 bool GetVariationParams(const std::string& trial_name,
210 std::map<std::string, std::string>* params) { 211 std::map<std::string, std::string>* params) {
211 return VariationsParamAssociator::GetInstance()->GetVariationParams( 212 return VariationsParamAssociator::GetInstance()->GetVariationParams(
212 trial_name, params); 213 trial_name, params);
213 } 214 }
214 215
216 bool GetVariationParamsByFeature(const base::Feature& feature,
217 std::map<std::string, std::string>* params) {
218 if (!base::FeatureList::IsEnabled(feature))
219 return false;
220
221 base::FieldTrial* trial = base::FeatureList::GetFieldTrial(feature);
222 if (!trial)
223 return false;
224
225 return GetVariationParams(trial->trial_name(), params);
226 }
227
215 std::string GetVariationParamValue(const std::string& trial_name, 228 std::string GetVariationParamValue(const std::string& trial_name,
216 const std::string& param_name) { 229 const std::string& param_name) {
217 std::map<std::string, std::string> params; 230 std::map<std::string, std::string> params;
218 if (GetVariationParams(trial_name, &params)) { 231 if (GetVariationParams(trial_name, &params)) {
219 std::map<std::string, std::string>::iterator it = params.find(param_name); 232 std::map<std::string, std::string>::iterator it = params.find(param_name);
220 if (it != params.end()) 233 if (it != params.end())
221 return it->second; 234 return it->second;
222 } 235 }
223 return std::string(); 236 return std::string();
224 } 237 }
225 238
239 std::string GetVariationParamValueByFeature(const base::Feature& feature,
240 const std::string& param_name) {
241 if (!base::FeatureList::IsEnabled(feature))
242 return std::string();
243
244 base::FieldTrial* trial = base::FeatureList::GetFieldTrial(feature);
245 if (!trial)
246 return std::string();
247
248 return GetVariationParamValue(trial->trial_name(), param_name);
249 }
250
226 // Functions below are exposed for testing explicitly behind this namespace. 251 // Functions below are exposed for testing explicitly behind this namespace.
227 // They simply wrap existing functions in this file. 252 // They simply wrap existing functions in this file.
228 namespace testing { 253 namespace testing {
229 254
230 void ClearAllVariationIDs() { 255 void ClearAllVariationIDs() {
231 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); 256 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting();
232 } 257 }
233 258
234 void ClearAllVariationParams() { 259 void ClearAllVariationParams() {
235 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting(); 260 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting();
236 } 261 }
237 262
238 } // namespace testing 263 } // namespace testing
239 264
240 } // namespace variations 265 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/variations_associated_data.h ('k') | components/variations/variations_associated_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698