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

Side by Side Diff: base/metrics/field_trial_params.cc

Issue 2804633003: Add base::FeatureParam<> struct (Closed)
Patch Set: rebase Created 3 years, 4 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "base/metrics/field_trial_params.h" 5 #include "base/metrics/field_trial_params.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/field_trial_param_associator.h" 9 #include "base/metrics/field_trial_param_associator.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if (!value_as_string.empty()) { 111 if (!value_as_string.empty()) {
112 DLOG(WARNING) << "Failed to parse field trial param " << param_name 112 DLOG(WARNING) << "Failed to parse field trial param " << param_name
113 << " with string value " << value_as_string 113 << " with string value " << value_as_string
114 << " under feature " << feature.name 114 << " under feature " << feature.name
115 << " into a bool. Falling back to default value of " 115 << " into a bool. Falling back to default value of "
116 << default_value; 116 << default_value;
117 } 117 }
118 return default_value; 118 return default_value;
119 } 119 }
120 120
121 std::string FeatureParam<std::string>::Get() const {
122 const std::string value = GetFieldTrialParamValueByFeature(*feature, name);
123 return value.empty() ? default_value : value;
124 }
125
126 double FeatureParam<double>::Get() const {
127 return GetFieldTrialParamByFeatureAsDouble(*feature, name, default_value);
128 }
129
130 int FeatureParam<int>::Get() const {
131 return GetFieldTrialParamByFeatureAsInt(*feature, name, default_value);
132 }
133
134 bool FeatureParam<bool>::Get() const {
135 return GetFieldTrialParamByFeatureAsBool(*feature, name, default_value);
136 }
137
138 void LogInvalidEnumValue(const base::Feature& feature,
139 const std::string& param_name,
140 const std::string& value_as_string,
141 int default_value_as_int) {
142 DLOG(WARNING) << "Failed to parse field trial param " << param_name
143 << " with string value " << value_as_string << " under feature "
144 << feature.name
145 << " into an enum. Falling back to default value of "
146 << default_value_as_int;
147 }
148
121 } // namespace base 149 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698