| 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
|
|
|