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

Side by Side Diff: components/ntp_snippets/features.cc

Issue 2558743003: Add generic functions for getting typed variation parameter values (Closed)
Patch Set: Alexei's 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ntp_snippets/features.h" 5 #include "components/ntp_snippets/features.h"
6 6
7 #include "base/strings/string_number_conversions.h"
8 #include "components/variations/variations_associated_data.h" 7 #include "components/variations/variations_associated_data.h"
9 8
10 namespace ntp_snippets { 9 namespace ntp_snippets {
11 10
12 const base::Feature kArticleSuggestionsFeature{ 11 const base::Feature kArticleSuggestionsFeature{
13 "NTPArticleSuggestions", base::FEATURE_ENABLED_BY_DEFAULT}; 12 "NTPArticleSuggestions", base::FEATURE_ENABLED_BY_DEFAULT};
14 13
15 const base::Feature kBookmarkSuggestionsFeature{ 14 const base::Feature kBookmarkSuggestionsFeature{
16 "NTPBookmarkSuggestions", base::FEATURE_ENABLED_BY_DEFAULT}; 15 "NTPBookmarkSuggestions", base::FEATURE_ENABLED_BY_DEFAULT};
17 16
(...skipping 17 matching lines...) Expand all
35 34
36 const base::Feature kSectionDismissalFeature{ 35 const base::Feature kSectionDismissalFeature{
37 "NTPSuggestionsSectionDismissal", base::FEATURE_ENABLED_BY_DEFAULT}; 36 "NTPSuggestionsSectionDismissal", base::FEATURE_ENABLED_BY_DEFAULT};
38 37
39 const base::Feature kForeignSessionsSuggestionsFeature{ 38 const base::Feature kForeignSessionsSuggestionsFeature{
40 "NTPForeignSessionsSuggestions", base::FEATURE_DISABLED_BY_DEFAULT}; 39 "NTPForeignSessionsSuggestions", base::FEATURE_DISABLED_BY_DEFAULT};
41 40
42 const base::Feature kFetchMoreFeature{"NTPSuggestionsFetchMore", 41 const base::Feature kFetchMoreFeature{"NTPSuggestionsFetchMore",
43 base::FEATURE_ENABLED_BY_DEFAULT}; 42 base::FEATURE_ENABLED_BY_DEFAULT};
44 43
45 int GetParamAsInt(const base::Feature& feature,
46 const std::string& param_name,
47 const int default_value) {
48 std::string value_as_string =
49 variations::GetVariationParamValueByFeature(feature, param_name);
50 int value_as_int = 0;
51 if (!base::StringToInt(value_as_string, &value_as_int)) {
52 if (!value_as_string.empty()) {
53 LOG(WARNING) << "Failed to parse variation param " << param_name
54 << " with string value " << value_as_string
55 << " under feature " << feature.name
56 << " into an int. Falling back to default value of "
57 << default_value;
58 }
59 value_as_int = default_value;
60 }
61 return value_as_int;
62 }
63
64
65 bool GetParamAsBool(const base::Feature& feature,
66 const std::string& param_name,
67 bool default_value) {
68 std::string value_as_string =
69 variations::GetVariationParamValueByFeature(feature, param_name);
70 if (value_as_string == "true") {
71 return true;
72 }
73 if (value_as_string == "false") {
74 return false;
75 }
76
77 if (!value_as_string.empty()) {
78 LOG(WARNING) << "Failed to parse variation param " << param_name
79 << " with string value " << value_as_string
80 << " under feature " << feature.name
81 << " into a bool. Falling back to default value of "
82 << default_value;
83 }
84 return default_value;
85 }
86
87 } // namespace ntp_snippets 44 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/features.h ('k') | components/ntp_snippets/offline_pages/recent_tab_suggestions_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698