| 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 // Keep sorted, and keep nullptr at the end. | 15 // Keep sorted, and keep nullptr at the end. |
| 17 const base::Feature* const kAllFeatures[] = { | 16 const base::Feature* const kAllFeatures[] = { |
| 18 &kArticleSuggestionsFeature, | 17 &kArticleSuggestionsFeature, |
| 19 &kBookmarkSuggestionsFeature, | 18 &kBookmarkSuggestionsFeature, |
| 20 &kBreakingNewsPushFeature, | 19 &kBreakingNewsPushFeature, |
| 21 &kCategoryOrder, | 20 &kCategoryOrder, |
| 22 &kCategoryRanker, | 21 &kCategoryRanker, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 base::FEATURE_ENABLED_BY_DEFAULT}; | 54 base::FEATURE_ENABLED_BY_DEFAULT}; |
| 56 | 55 |
| 57 const base::Feature kPublisherFaviconsFromNewServerFeature{ | 56 const base::Feature kPublisherFaviconsFromNewServerFeature{ |
| 58 "ContentSuggestionsFaviconsFromNewServer", | 57 "ContentSuggestionsFaviconsFromNewServer", |
| 59 base::FEATURE_DISABLED_BY_DEFAULT}; | 58 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 60 | 59 |
| 61 const base::Feature kRemoteSuggestionsEmulateM58FetchingSchedule{ | 60 const base::Feature kRemoteSuggestionsEmulateM58FetchingSchedule{ |
| 62 "RemoteSuggestionsEmulateM58FetchingSchedule", | 61 "RemoteSuggestionsEmulateM58FetchingSchedule", |
| 63 base::FEATURE_DISABLED_BY_DEFAULT}; | 62 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 64 | 63 |
| 65 const char kCategoryRankerParameter[] = "category_ranker"; | 64 constexpr base::FeatureParam<CategoryRankerChoice>::Option |
| 65 kCategoryRankerParameterOptions[] = { |
| 66 {CategoryRankerChoice::CONSTANT, kCategoryRankerConstantRanker}, |
| 67 {CategoryRankerChoice::CLICK_BASED, kCategoryRankerClickBasedRanker}}; |
| 68 constexpr base::FeatureParam<CategoryRankerChoice> kCategoryRankerParameter{ |
| 69 &kCategoryRanker, "category_ranker", CategoryRankerChoice::CONSTANT, |
| 70 &kCategoryRankerParameterOptions}; |
| 66 const char kCategoryRankerConstantRanker[] = "constant"; | 71 const char kCategoryRankerConstantRanker[] = "constant"; |
| 67 const char kCategoryRankerClickBasedRanker[] = "click_based"; | 72 const char kCategoryRankerClickBasedRanker[] = "click_based"; |
| 68 | 73 |
| 69 CategoryRankerChoice GetSelectedCategoryRanker() { | |
| 70 std::string category_ranker_value = | |
| 71 variations::GetVariationParamValueByFeature(kCategoryRanker, | |
| 72 kCategoryRankerParameter); | |
| 73 | |
| 74 if (category_ranker_value.empty()) { | |
| 75 // TODO(crbug.com/735066): Remove the experiment configurations from | |
| 76 // fieldtrial_testing_config.json when enabling ClickBasedRanker by default. | |
| 77 | |
| 78 // Default, Enabled or Disabled. | |
| 79 return CategoryRankerChoice::CONSTANT; | |
| 80 } | |
| 81 if (category_ranker_value == kCategoryRankerConstantRanker) { | |
| 82 return CategoryRankerChoice::CONSTANT; | |
| 83 } | |
| 84 if (category_ranker_value == kCategoryRankerClickBasedRanker) { | |
| 85 return CategoryRankerChoice::CLICK_BASED; | |
| 86 } | |
| 87 | |
| 88 LOG(DFATAL) << "The " << kCategoryRankerParameter << " parameter value is '" | |
| 89 << category_ranker_value << "'"; | |
| 90 return CategoryRankerChoice::CONSTANT; | |
| 91 } | |
| 92 | |
| 93 std::unique_ptr<CategoryRanker> BuildSelectedCategoryRanker( | 74 std::unique_ptr<CategoryRanker> BuildSelectedCategoryRanker( |
| 94 PrefService* pref_service, | 75 PrefService* pref_service, |
| 95 std::unique_ptr<base::Clock> clock) { | 76 std::unique_ptr<base::Clock> clock) { |
| 96 CategoryRankerChoice choice = ntp_snippets::GetSelectedCategoryRanker(); | 77 CategoryRankerChoice choice = kCategoryRankerParameter.Get(); |
| 97 switch (choice) { | 78 switch (choice) { |
| 98 case CategoryRankerChoice::CONSTANT: | 79 case CategoryRankerChoice::CONSTANT: |
| 99 return base::MakeUnique<ConstantCategoryRanker>(); | 80 return base::MakeUnique<ConstantCategoryRanker>(); |
| 100 case CategoryRankerChoice::CLICK_BASED: | 81 case CategoryRankerChoice::CLICK_BASED: |
| 101 return base::MakeUnique<ClickBasedCategoryRanker>(pref_service, | 82 return base::MakeUnique<ClickBasedCategoryRanker>(pref_service, |
| 102 std::move(clock)); | 83 std::move(clock)); |
| 103 } | 84 } |
| 104 return nullptr; | 85 return nullptr; |
| 105 } | 86 } |
| 106 | 87 |
| 107 const base::Feature kCategoryOrder{"ContentSuggestionsCategoryOrder", | 88 const base::Feature kCategoryOrder{"ContentSuggestionsCategoryOrder", |
| 108 base::FEATURE_DISABLED_BY_DEFAULT}; | 89 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 109 | 90 |
| 110 const char kCategoryOrderParameter[] = "category_order"; | 91 constexpr base::FeatureParam<CategoryOrderChoice>::Option |
| 92 kCategoryOrderParameterOptions[] = { |
| 93 {CategoryOrderChoice::GENERAL, kCategoryOrderGeneral}, |
| 94 {CategoryOrderChoice::EMERGING_MARKETS_ORIENTED, |
| 95 kCategoryOrderEmergingMarketsOriented}}; |
| 96 const base::FeatureParam<CategoryOrderChoice> kCategoryOrderParameter{ |
| 97 &kCategoryOrder, "category_order", CategoryOrderChoice::GENERAL, |
| 98 &kCategoryOrderParameterOptions}; |
| 99 |
| 111 const char kCategoryOrderGeneral[] = "general"; | 100 const char kCategoryOrderGeneral[] = "general"; |
| 112 const char kCategoryOrderEmergingMarketsOriented[] = | 101 const char kCategoryOrderEmergingMarketsOriented[] = |
| 113 "emerging_markets_oriented"; | 102 "emerging_markets_oriented"; |
| 114 | 103 |
| 115 CategoryOrderChoice GetSelectedCategoryOrder() { | 104 CategoryOrderChoice GetSelectedCategoryOrder() { |
| 116 if (!base::FeatureList::IsEnabled(kCategoryOrder)) { | 105 return kCategoryOrderParameter.Get(); |
| 117 return CategoryOrderChoice::GENERAL; | |
| 118 } | |
| 119 | |
| 120 std::string category_order_value = | |
| 121 variations::GetVariationParamValueByFeature(kCategoryOrder, | |
| 122 kCategoryOrderParameter); | |
| 123 | |
| 124 if (category_order_value.empty()) { | |
| 125 // Enabled with no parameters. | |
| 126 return CategoryOrderChoice::GENERAL; | |
| 127 } | |
| 128 if (category_order_value == kCategoryOrderGeneral) { | |
| 129 return CategoryOrderChoice::GENERAL; | |
| 130 } | |
| 131 if (category_order_value == kCategoryOrderEmergingMarketsOriented) { | |
| 132 return CategoryOrderChoice::EMERGING_MARKETS_ORIENTED; | |
| 133 } | |
| 134 | |
| 135 LOG(DFATAL) << "The " << kCategoryOrderParameter << " parameter value is '" | |
| 136 << category_order_value << "'"; | |
| 137 return CategoryOrderChoice::GENERAL; | |
| 138 } | 106 } |
| 139 | 107 |
| 140 const base::Feature kNotificationsFeature = {"ContentSuggestionsNotifications", | 108 const base::Feature kNotificationsFeature = {"ContentSuggestionsNotifications", |
| 141 base::FEATURE_DISABLED_BY_DEFAULT}; | 109 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 142 | 110 |
| 143 const char kNotificationsPriorityParam[] = "priority"; | 111 const char kNotificationsPriorityParam[] = "priority"; |
| 144 const char kNotificationsTextParam[] = "text"; | 112 const char kNotificationsTextParam[] = "text"; |
| 145 const char kNotificationsTextValuePublisher[] = "publisher"; | 113 const char kNotificationsTextValuePublisher[] = "publisher"; |
| 146 const char kNotificationsTextValueSnippet[] = "snippet"; | 114 const char kNotificationsTextValueSnippet[] = "snippet"; |
| 147 const char kNotificationsTextValueAndMore[] = "and_more"; | 115 const char kNotificationsTextValueAndMore[] = "and_more"; |
| 148 const char kNotificationsKeepWhenFrontmostParam[] = | 116 const char kNotificationsKeepWhenFrontmostParam[] = |
| 149 "keep_notification_when_frontmost"; | 117 "keep_notification_when_frontmost"; |
| 150 const char kNotificationsOpenToNTPParam[] = "open_to_ntp"; | 118 const char kNotificationsOpenToNTPParam[] = "open_to_ntp"; |
| 151 const char kNotificationsDailyLimit[] = "daily_limit"; | 119 const char kNotificationsDailyLimit[] = "daily_limit"; |
| 152 const char kNotificationsIgnoredLimitParam[] = "ignored_limit"; | 120 const char kNotificationsIgnoredLimitParam[] = "ignored_limit"; |
| 153 | 121 |
| 154 const base::Feature kKeepPrefetchedContentSuggestions{ | 122 const base::Feature kKeepPrefetchedContentSuggestions{ |
| 155 "KeepPrefetchedContentSuggestions", base::FEATURE_DISABLED_BY_DEFAULT}; | 123 "KeepPrefetchedContentSuggestions", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 156 | 124 |
| 157 const base::Feature kDeleteRemoteCategoriesNotPresentInLastFetch{ | 125 const base::Feature kDeleteRemoteCategoriesNotPresentInLastFetch{ |
| 158 "DeleteRemoteCategoriesNotPresentInLastFetch", | 126 "DeleteRemoteCategoriesNotPresentInLastFetch", |
| 159 base::FEATURE_DISABLED_BY_DEFAULT}; | 127 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 160 | 128 |
| 161 } // namespace ntp_snippets | 129 } // namespace ntp_snippets |
| OLD | NEW |