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

Side by Side 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, 11 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 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 "components/ntp_snippets/category_rankers/click_based_category_ranker.h "
8 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h"
7 #include "components/variations/variations_associated_data.h" 9 #include "components/variations/variations_associated_data.h"
8 10
9 namespace ntp_snippets { 11 namespace ntp_snippets {
10 12
11 const base::Feature kArticleSuggestionsFeature{ 13 const base::Feature kArticleSuggestionsFeature{
12 "NTPArticleSuggestions", base::FEATURE_ENABLED_BY_DEFAULT}; 14 "NTPArticleSuggestions", base::FEATURE_ENABLED_BY_DEFAULT};
13 15
14 const base::Feature kBookmarkSuggestionsFeature{ 16 const base::Feature kBookmarkSuggestionsFeature{
15 "NTPBookmarkSuggestions", base::FEATURE_ENABLED_BY_DEFAULT}; 17 "NTPBookmarkSuggestions", base::FEATURE_ENABLED_BY_DEFAULT};
16 18
(...skipping 20 matching lines...) Expand all
37 39
38 const base::Feature kForeignSessionsSuggestionsFeature{ 40 const base::Feature kForeignSessionsSuggestionsFeature{
39 "NTPForeignSessionsSuggestions", base::FEATURE_DISABLED_BY_DEFAULT}; 41 "NTPForeignSessionsSuggestions", base::FEATURE_DISABLED_BY_DEFAULT};
40 42
41 const base::Feature kFetchMoreFeature{"NTPSuggestionsFetchMore", 43 const base::Feature kFetchMoreFeature{"NTPSuggestionsFetchMore",
42 base::FEATURE_ENABLED_BY_DEFAULT}; 44 base::FEATURE_ENABLED_BY_DEFAULT};
43 45
44 const base::Feature kPreferAmpUrlsFeature{"NTPPreferAmpUrls", 46 const base::Feature kPreferAmpUrlsFeature{"NTPPreferAmpUrls",
45 base::FEATURE_ENABLED_BY_DEFAULT}; 47 base::FEATURE_ENABLED_BY_DEFAULT};
46 48
49 const base::Feature kCategoryRanker{"ContentSuggestionsCategoryRanker",
50 base::FEATURE_ENABLED_BY_DEFAULT};
51
52 const char kCategoryRankerParameter[] = "category_ranker";
53 const char kCategoryRankerConstantRanker[] = "constant";
54 const char kCategoryRankerClickBasedRanker[] = "click_based";
55
56 CategoryRankerChoice GetSelectedCategoryRanker() {
57 std::string category_ranker_value =
58 variations::GetVariationParamValueByFeature(kCategoryRanker,
59 kCategoryRankerParameter);
60
61 if (category_ranker_value.empty()) {
62 // Default, Enabled or Disabled.
63 return CategoryRankerChoice::CONSTANT;
64 }
65 if (category_ranker_value == kCategoryRankerConstantRanker) {
66 return CategoryRankerChoice::CONSTANT;
67 }
68 if (category_ranker_value == kCategoryRankerClickBasedRanker) {
69 return CategoryRankerChoice::CLICK_BASED;
70 }
71
72 NOTREACHED() << "The " << kCategoryRankerParameter << " parameter value is '"
73 << category_ranker_value << "'";
74 return CategoryRankerChoice::CONSTANT;
75 }
76
77 std::unique_ptr<CategoryRanker> BuildSelectedCategoryRanker(
78 PrefService* pref_service) {
79 CategoryRankerChoice choice = ntp_snippets::GetSelectedCategoryRanker();
80 switch (choice) {
81 case CategoryRankerChoice::CONSTANT:
82 return base::MakeUnique<ConstantCategoryRanker>();
83 case CategoryRankerChoice::CLICK_BASED:
84 return base::MakeUnique<ClickBasedCategoryRanker>(pref_service);
85 default:
86 NOTREACHED() << "The category ranker choice value is "
87 << static_cast<int>(choice);
88 }
89 return nullptr;
90 }
91
47 } // namespace ntp_snippets 92 } // namespace ntp_snippets
OLDNEW
« 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