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

Unified Diff: components/ntp_snippets/features.cc

Issue 2595883002: [NTP::SectionOrder] Add a flag to choose category ranker. (Closed)
Patch Set: histograms.xml. Created 3 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/features.cc
diff --git a/components/ntp_snippets/features.cc b/components/ntp_snippets/features.cc
index 03cfbc3bf45f0831f3d6c9836aa39d7f2e8254df..c3c7fc87baf2a2ac811d3e24bfabae0c1ee721ae 100644
--- a/components/ntp_snippets/features.cc
+++ b/components/ntp_snippets/features.cc
@@ -4,6 +4,8 @@
#include "components/ntp_snippets/features.h"
+#include "components/ntp_snippets/category_rankers/click_based_category_ranker.h"
+#include "components/ntp_snippets/category_rankers/constant_category_ranker.h"
#include "components/variations/variations_associated_data.h"
namespace ntp_snippets {
@@ -44,4 +46,47 @@ const base::Feature kFetchMoreFeature{"NTPSuggestionsFetchMore",
const base::Feature kPreferAmpUrlsFeature{"NTPPreferAmpUrls",
base::FEATURE_ENABLED_BY_DEFAULT};
+const base::Feature kCategoryRanker{"ContentSuggestionsCategoryRanker",
+ base::FEATURE_ENABLED_BY_DEFAULT};
+
+const char kCategoryRankerParameter[] = "category_ranker";
+const char kCategoryRankerConstantRanker[] = "constant";
+const char kCategoryRankerClickBasedRanker[] = "click_based";
+
+CategoryRankerChoice GetSelectedCategoryRanker() {
+ std::string category_ranker_value =
+ variations::GetVariationParamValueByFeature(kCategoryRanker,
+ kCategoryRankerParameter);
+
+ if (category_ranker_value.empty()) {
+ // Default, Enabled or Disabled.
+ return CategoryRankerChoice::CONSTANT;
+ }
+ if (category_ranker_value == kCategoryRankerConstantRanker) {
+ return CategoryRankerChoice::CONSTANT;
+ }
+ if (category_ranker_value == kCategoryRankerClickBasedRanker) {
+ return CategoryRankerChoice::CLICK_BASED;
+ }
+
+ NOTREACHED() << "The " << kCategoryRankerParameter << " parameter value is '"
+ << category_ranker_value << "'";
+ return CategoryRankerChoice::CONSTANT;
+}
+
+std::unique_ptr<CategoryRanker> BuildSelectedCategoryRanker(
+ PrefService* pref_service) {
+ CategoryRankerChoice choice = ntp_snippets::GetSelectedCategoryRanker();
+ switch (choice) {
+ case CategoryRankerChoice::CONSTANT:
+ return base::MakeUnique<ConstantCategoryRanker>();
+ case CategoryRankerChoice::CLICK_BASED:
+ return base::MakeUnique<ClickBasedCategoryRanker>(pref_service);
+ default:
+ NOTREACHED() << "The category ranker choice value is "
+ << static_cast<int>(choice);
+ }
+ return nullptr;
+}
+
} // namespace ntp_snippets
« no previous file with comments | « components/ntp_snippets/features.h ('k') | ios/chrome/browser/ntp_snippets/ios_chrome_content_suggestions_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698