Index: components/variations/variations_associated_data.cc |
diff --git a/components/variations/variations_associated_data.cc b/components/variations/variations_associated_data.cc |
index ec696a3e37fd0bd5d7db10c0f98d6c49754a5235..0dffe8ff63fbe64e92ef74e26ac9afb6fe69fa02 100644 |
--- a/components/variations/variations_associated_data.cc |
+++ b/components/variations/variations_associated_data.cc |
@@ -8,12 +8,11 @@ |
#include <utility> |
#include <vector> |
-#include "base/feature_list.h" |
#include "base/macros.h" |
#include "base/memory/singleton.h" |
#include "base/metrics/field_trial.h" |
#include "base/metrics/field_trial_param_associator.h" |
-#include "base/strings/string_number_conversions.h" |
+#include "base/metrics/field_trial_params.h" |
#include "base/strings/string_split.h" |
#include "components/variations/variations_http_header_provider.h" |
@@ -154,107 +153,48 @@ bool AssociateVariationParams( |
const std::string& trial_name, |
const std::string& group_name, |
const std::map<std::string, std::string>& params) { |
- return base::FieldTrialParamAssociator::GetInstance() |
- ->AssociateFieldTrialParams(trial_name, group_name, params); |
+ return base::AssociateFieldTrialParams(trial_name, group_name, params); |
} |
bool GetVariationParams(const std::string& trial_name, |
std::map<std::string, std::string>* params) { |
- return base::FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams( |
- trial_name, params); |
+ return base::GetFieldTrialParams(trial_name, params); |
} |
bool GetVariationParamsByFeature(const base::Feature& feature, |
std::map<std::string, std::string>* params) { |
- if (!base::FeatureList::IsEnabled(feature)) |
- return false; |
- |
- base::FieldTrial* trial = base::FeatureList::GetFieldTrial(feature); |
- if (!trial) |
- return false; |
- |
- return GetVariationParams(trial->trial_name(), params); |
+ return base::GetFieldTrialParamsByFeature(feature, params); |
} |
std::string GetVariationParamValue(const std::string& trial_name, |
const std::string& param_name) { |
- std::map<std::string, std::string> params; |
- if (GetVariationParams(trial_name, ¶ms)) { |
- std::map<std::string, std::string>::iterator it = params.find(param_name); |
- if (it != params.end()) |
- return it->second; |
- } |
- return std::string(); |
+ return base::GetFieldTrialParamValue(trial_name, param_name); |
} |
std::string GetVariationParamValueByFeature(const base::Feature& feature, |
const std::string& param_name) { |
- if (!base::FeatureList::IsEnabled(feature)) |
- return std::string(); |
- |
- base::FieldTrial* trial = base::FeatureList::GetFieldTrial(feature); |
- if (!trial) |
- return std::string(); |
- |
- return GetVariationParamValue(trial->trial_name(), param_name); |
+ return base::GetFieldTrialParamValueByFeature(feature, param_name); |
} |
int GetVariationParamByFeatureAsInt(const base::Feature& feature, |
const std::string& param_name, |
int default_value) { |
- std::string value_as_string = |
- GetVariationParamValueByFeature(feature, param_name); |
- int value_as_int = 0; |
- if (!base::StringToInt(value_as_string, &value_as_int)) { |
- if (!value_as_string.empty()) { |
- DLOG(WARNING) << "Failed to parse variation param " << param_name |
- << " with string value " << value_as_string |
- << " under feature " << feature.name |
- << " into an int. Falling back to default value of " |
- << default_value; |
- } |
- value_as_int = default_value; |
- } |
- return value_as_int; |
+ return base::GetFieldTrialParamByFeatureAsInt(feature, param_name, |
+ default_value); |
} |
double GetVariationParamByFeatureAsDouble(const base::Feature& feature, |
const std::string& param_name, |
double default_value) { |
- std::string value_as_string = |
- GetVariationParamValueByFeature(feature, param_name); |
- double value_as_double = 0; |
- if (!base::StringToDouble(value_as_string, &value_as_double)) { |
- if (!value_as_string.empty()) { |
- DLOG(WARNING) << "Failed to parse variation param " << param_name |
- << " with string value " << value_as_string |
- << " under feature " << feature.name |
- << " into a double. Falling back to default value of " |
- << default_value; |
- } |
- value_as_double = default_value; |
- } |
- return value_as_double; |
+ return base::GetFieldTrialParamByFeatureAsDouble(feature, param_name, |
+ default_value); |
} |
bool GetVariationParamByFeatureAsBool(const base::Feature& feature, |
const std::string& param_name, |
bool default_value) { |
- std::string value_as_string = |
- variations::GetVariationParamValueByFeature(feature, param_name); |
- if (value_as_string == "true") |
- return true; |
- if (value_as_string == "false") |
- return false; |
- |
- if (!value_as_string.empty()) { |
- DLOG(WARNING) << "Failed to parse variation param " << param_name |
- << " with string value " << value_as_string |
- << " under feature " << feature.name |
- << " into a bool. Falling back to default value of " |
- << default_value; |
- } |
- return default_value; |
+ return base::GetFieldTrialParamByFeatureAsBool(feature, param_name, |
+ default_value); |
} |
// Functions below are exposed for testing explicitly behind this namespace. |