Chromium Code Reviews| Index: components/variations/variations_associated_data.cc |
| diff --git a/components/variations/variations_associated_data.cc b/components/variations/variations_associated_data.cc |
| index 465aed58c5407ddc22984d606120e338f0ca49e0..c6e7dd9770fe84ab1c9cc3d939fd75691952ba69 100644 |
| --- a/components/variations/variations_associated_data.cc |
| +++ b/components/variations/variations_associated_data.cc |
| @@ -13,6 +13,7 @@ |
| #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/strings/string_split.h" |
| #include "components/variations/variations_http_header_provider.h" |
| @@ -190,6 +191,66 @@ std::string GetVariationParamValueByFeature(const base::Feature& feature, |
| return GetVariationParamValue(trial->trial_name(), 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()) { |
| + LOG(WARNING) << "Failed to parse variation param " << param_name |
|
Alexei Svitkine (slow)
2016/12/08 21:08:33
Please turn these into DLOG()'s.
LOG() lines are
jkrcal
2016/12/09 06:59:31
Done.
|
| + << " 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; |
| +} |
| + |
| +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()) { |
| + LOG(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; |
| +} |
| + |
| +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") { |
|
Alexei Svitkine (slow)
2016/12/08 21:08:32
Nit: No {}'s here and below.
jkrcal
2016/12/09 06:59:31
Done.
|
| + return true; |
| + } |
| + if (value_as_string == "false") { |
| + return false; |
| + } |
| + |
| + if (!value_as_string.empty()) { |
| + LOG(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; |
| +} |
| + |
| // Functions below are exposed for testing explicitly behind this namespace. |
| // They simply wrap existing functions in this file. |
| namespace testing { |