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

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

Issue 2696563002: [NTP::SectionOrder] Add EM oriented order. (Closed)
Patch Set: treib@ comment. Created 3 years, 10 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
« no previous file with comments | « components/ntp_snippets/features.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/feature_list.h"
7 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
8 #include "base/time/clock.h" 9 #include "base/time/clock.h"
9 #include "components/ntp_snippets/category_rankers/click_based_category_ranker.h " 10 #include "components/ntp_snippets/category_rankers/click_based_category_ranker.h "
10 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" 11 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h"
11 #include "components/variations/variations_associated_data.h" 12 #include "components/variations/variations_associated_data.h"
12 13
13 namespace ntp_snippets { 14 namespace ntp_snippets {
14 15
15 const base::Feature kArticleSuggestionsFeature{ 16 const base::Feature kArticleSuggestionsFeature{
16 "NTPArticleSuggestions", base::FEATURE_ENABLED_BY_DEFAULT}; 17 "NTPArticleSuggestions", base::FEATURE_ENABLED_BY_DEFAULT};
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // Default, Enabled or Disabled. 59 // Default, Enabled or Disabled.
59 return CategoryRankerChoice::CLICK_BASED; 60 return CategoryRankerChoice::CLICK_BASED;
60 } 61 }
61 if (category_ranker_value == kCategoryRankerConstantRanker) { 62 if (category_ranker_value == kCategoryRankerConstantRanker) {
62 return CategoryRankerChoice::CONSTANT; 63 return CategoryRankerChoice::CONSTANT;
63 } 64 }
64 if (category_ranker_value == kCategoryRankerClickBasedRanker) { 65 if (category_ranker_value == kCategoryRankerClickBasedRanker) {
65 return CategoryRankerChoice::CLICK_BASED; 66 return CategoryRankerChoice::CLICK_BASED;
66 } 67 }
67 68
68 NOTREACHED() << "The " << kCategoryRankerParameter << " parameter value is '" 69 LOG(DFATAL) << "The " << kCategoryRankerParameter << " parameter value is '"
69 << category_ranker_value << "'"; 70 << category_ranker_value << "'";
70 return CategoryRankerChoice::CONSTANT; 71 return CategoryRankerChoice::CONSTANT;
71 } 72 }
72 73
73 std::unique_ptr<CategoryRanker> BuildSelectedCategoryRanker( 74 std::unique_ptr<CategoryRanker> BuildSelectedCategoryRanker(
74 PrefService* pref_service, 75 PrefService* pref_service,
75 std::unique_ptr<base::Clock> clock) { 76 std::unique_ptr<base::Clock> clock) {
76 CategoryRankerChoice choice = ntp_snippets::GetSelectedCategoryRanker(); 77 CategoryRankerChoice choice = ntp_snippets::GetSelectedCategoryRanker();
77 switch (choice) { 78 switch (choice) {
78 case CategoryRankerChoice::CONSTANT: 79 case CategoryRankerChoice::CONSTANT:
79 return base::MakeUnique<ConstantCategoryRanker>(); 80 return base::MakeUnique<ConstantCategoryRanker>();
80 case CategoryRankerChoice::CLICK_BASED: 81 case CategoryRankerChoice::CLICK_BASED:
81 return base::MakeUnique<ClickBasedCategoryRanker>(pref_service, 82 return base::MakeUnique<ClickBasedCategoryRanker>(pref_service,
82 std::move(clock)); 83 std::move(clock));
83 default:
84 NOTREACHED() << "The category ranker choice value is "
85 << static_cast<int>(choice);
86 } 84 }
87 return nullptr; 85 return nullptr;
88 } 86 }
89 87
88 const base::Feature kCategoryOrder{"ContentSuggestionsCategoryOrder",
89 base::FEATURE_DISABLED_BY_DEFAULT};
90
91 const char kCategoryOrderParameter[] = "category_order";
92 const char kCategoryOrderGeneral[] = "general";
93 const char kCategoryOrderEmergingMarketsOriented[] =
94 "emerging_markets_oriented";
95
96 CategoryOrderChoice GetSelectedCategoryOrder() {
97 if (!base::FeatureList::IsEnabled(kCategoryOrder)) {
98 return CategoryOrderChoice::GENERAL;
99 }
100
101 std::string category_order_value =
102 variations::GetVariationParamValueByFeature(kCategoryOrder,
103 kCategoryOrderParameter);
104
105 if (category_order_value.empty()) {
106 // Enabled with no parameters.
107 return CategoryOrderChoice::GENERAL;
108 }
109 if (category_order_value == kCategoryOrderGeneral) {
110 return CategoryOrderChoice::GENERAL;
111 }
112 if (category_order_value == kCategoryOrderEmergingMarketsOriented) {
113 return CategoryOrderChoice::EMERGING_MARKETS_ORIENTED;
114 }
115
116 LOG(DFATAL) << "The " << kCategoryOrderParameter << " parameter value is '"
117 << category_order_value << "'";
118 return CategoryOrderChoice::GENERAL;
119 }
120
90 } // namespace ntp_snippets 121 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/features.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698