| OLD | NEW |
| 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/feature_list.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/time/clock.h" | 9 #include "base/time/clock.h" |
| 10 #include "components/ntp_snippets/category_rankers/click_based_category_ranker.h
" | 10 #include "components/ntp_snippets/category_rankers/click_based_category_ranker.h
" |
| 11 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" | 11 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" |
| 12 #include "components/variations/variations_associated_data.h" | |
| 13 | 12 |
| 14 namespace ntp_snippets { | 13 namespace ntp_snippets { |
| 15 | 14 |
| 16 const base::Feature kArticleSuggestionsFeature{ | 15 const base::Feature kArticleSuggestionsFeature{ |
| 17 "NTPArticleSuggestions", base::FEATURE_ENABLED_BY_DEFAULT}; | 16 "NTPArticleSuggestions", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 18 | 17 |
| 19 const base::Feature kBookmarkSuggestionsFeature{ | 18 const base::Feature kBookmarkSuggestionsFeature{ |
| 20 "NTPBookmarkSuggestions", base::FEATURE_ENABLED_BY_DEFAULT}; | 19 "NTPBookmarkSuggestions", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 21 | 20 |
| 22 const base::Feature kRecentOfflineTabSuggestionsFeature{ | 21 const base::Feature kRecentOfflineTabSuggestionsFeature{ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 const base::Feature kPreferAmpUrlsFeature{"NTPPreferAmpUrls", | 33 const base::Feature kPreferAmpUrlsFeature{"NTPPreferAmpUrls", |
| 35 base::FEATURE_ENABLED_BY_DEFAULT}; | 34 base::FEATURE_ENABLED_BY_DEFAULT}; |
| 36 | 35 |
| 37 const base::Feature kCategoryRanker{"ContentSuggestionsCategoryRanker", | 36 const base::Feature kCategoryRanker{"ContentSuggestionsCategoryRanker", |
| 38 base::FEATURE_ENABLED_BY_DEFAULT}; | 37 base::FEATURE_ENABLED_BY_DEFAULT}; |
| 39 | 38 |
| 40 const base::Feature kPublisherFaviconsFromNewServerFeature{ | 39 const base::Feature kPublisherFaviconsFromNewServerFeature{ |
| 41 "ContentSuggestionsFaviconsFromNewServer", | 40 "ContentSuggestionsFaviconsFromNewServer", |
| 42 base::FEATURE_DISABLED_BY_DEFAULT}; | 41 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 43 | 42 |
| 44 const char kCategoryRankerParameter[] = "category_ranker"; | |
| 45 const char kCategoryRankerConstantRanker[] = "constant"; | 43 const char kCategoryRankerConstantRanker[] = "constant"; |
| 46 const char kCategoryRankerClickBasedRanker[] = "click_based"; | 44 const char kCategoryRankerClickBasedRanker[] = "click_based"; |
| 47 | 45 |
| 48 CategoryRankerChoice GetSelectedCategoryRanker() { | 46 constexpr base::FeatureParam<CategoryRankerChoice>::Option |
| 49 std::string category_ranker_value = | 47 kCategoryRankerParameterOptions[] = { |
| 50 variations::GetVariationParamValueByFeature(kCategoryRanker, | 48 {CategoryRankerChoice::CONSTANT, kCategoryRankerConstantRanker}, |
| 51 kCategoryRankerParameter); | 49 {CategoryRankerChoice::CLICK_BASED, kCategoryRankerClickBasedRanker}}; |
| 52 | 50 const base::FeatureParam<CategoryRankerChoice> kCategoryRankerParameter{ |
| 53 if (category_ranker_value.empty()) { | 51 &kCategoryRanker, "category_ranker", CategoryRankerChoice::CONSTANT, |
| 54 // Default, Enabled or Disabled. | 52 &kCategoryRankerParameterOptions}; |
| 55 return CategoryRankerChoice::CONSTANT; | |
| 56 } | |
| 57 if (category_ranker_value == kCategoryRankerConstantRanker) { | |
| 58 return CategoryRankerChoice::CONSTANT; | |
| 59 } | |
| 60 if (category_ranker_value == kCategoryRankerClickBasedRanker) { | |
| 61 return CategoryRankerChoice::CLICK_BASED; | |
| 62 } | |
| 63 | |
| 64 LOG(DFATAL) << "The " << kCategoryRankerParameter << " parameter value is '" | |
| 65 << category_ranker_value << "'"; | |
| 66 return CategoryRankerChoice::CONSTANT; | |
| 67 } | |
| 68 | 53 |
| 69 std::unique_ptr<CategoryRanker> BuildSelectedCategoryRanker( | 54 std::unique_ptr<CategoryRanker> BuildSelectedCategoryRanker( |
| 70 PrefService* pref_service, | 55 PrefService* pref_service, |
| 71 std::unique_ptr<base::Clock> clock) { | 56 std::unique_ptr<base::Clock> clock) { |
| 72 CategoryRankerChoice choice = ntp_snippets::GetSelectedCategoryRanker(); | 57 CategoryRankerChoice choice = kCategoryRankerParameter.Get(); |
| 73 switch (choice) { | 58 switch (choice) { |
| 74 case CategoryRankerChoice::CONSTANT: | 59 case CategoryRankerChoice::CONSTANT: |
| 75 return base::MakeUnique<ConstantCategoryRanker>(); | 60 return base::MakeUnique<ConstantCategoryRanker>(); |
| 76 case CategoryRankerChoice::CLICK_BASED: | 61 case CategoryRankerChoice::CLICK_BASED: |
| 77 return base::MakeUnique<ClickBasedCategoryRanker>(pref_service, | 62 return base::MakeUnique<ClickBasedCategoryRanker>(pref_service, |
| 78 std::move(clock)); | 63 std::move(clock)); |
| 79 } | 64 } |
| 80 return nullptr; | 65 return nullptr; |
| 81 } | 66 } |
| 82 | 67 |
| 83 const base::Feature kCategoryOrder{"ContentSuggestionsCategoryOrder", | 68 const base::Feature kCategoryOrder{"ContentSuggestionsCategoryOrder", |
| 84 base::FEATURE_DISABLED_BY_DEFAULT}; | 69 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 85 | 70 |
| 86 const char kCategoryOrderParameter[] = "category_order"; | 71 constexpr base::FeatureParam<CategoryOrderChoice>::Option |
| 72 kCategoryOrderParameterOptions[] = { |
| 73 {CategoryOrderChoice::GENERAL, kCategoryOrderGeneral}, |
| 74 {CategoryOrderChoice::EMERGING_MARKETS_ORIENTED, |
| 75 kCategoryOrderEmergingMarketsOriented}}; |
| 76 const base::FeatureParam<CategoryOrderChoice> kCategoryOrderParameter{ |
| 77 &kCategoryOrder, "category_order", CategoryOrderChoice::GENERAL, |
| 78 &kCategoryOrderParameterOptions}; |
| 79 |
| 87 const char kCategoryOrderGeneral[] = "general"; | 80 const char kCategoryOrderGeneral[] = "general"; |
| 88 const char kCategoryOrderEmergingMarketsOriented[] = | 81 const char kCategoryOrderEmergingMarketsOriented[] = |
| 89 "emerging_markets_oriented"; | 82 "emerging_markets_oriented"; |
| 90 | 83 |
| 91 CategoryOrderChoice GetSelectedCategoryOrder() { | 84 CategoryOrderChoice GetSelectedCategoryOrder() { |
| 92 if (!base::FeatureList::IsEnabled(kCategoryOrder)) { | 85 return kCategoryOrderParameter.Get(); |
| 93 return CategoryOrderChoice::GENERAL; | |
| 94 } | |
| 95 | |
| 96 std::string category_order_value = | |
| 97 variations::GetVariationParamValueByFeature(kCategoryOrder, | |
| 98 kCategoryOrderParameter); | |
| 99 | |
| 100 if (category_order_value.empty()) { | |
| 101 // Enabled with no parameters. | |
| 102 return CategoryOrderChoice::GENERAL; | |
| 103 } | |
| 104 if (category_order_value == kCategoryOrderGeneral) { | |
| 105 return CategoryOrderChoice::GENERAL; | |
| 106 } | |
| 107 if (category_order_value == kCategoryOrderEmergingMarketsOriented) { | |
| 108 return CategoryOrderChoice::EMERGING_MARKETS_ORIENTED; | |
| 109 } | |
| 110 | |
| 111 LOG(DFATAL) << "The " << kCategoryOrderParameter << " parameter value is '" | |
| 112 << category_order_value << "'"; | |
| 113 return CategoryOrderChoice::GENERAL; | |
| 114 } | 86 } |
| 115 | 87 |
| 116 } // namespace ntp_snippets | 88 } // namespace ntp_snippets |
| OLD | NEW |