features.cc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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
  3. // found in the LICENSE file.
  4. #include "components/ntp_snippets/features.h"
  5. #include "base/feature_list.h"
  6. #include "base/metrics/field_trial_params.h"
  7. #include "base/time/clock.h"
  8. #include "build/build_config.h"
  9. #include "components/ntp_snippets/category_rankers/click_based_category_ranker.h"
  10. #include "components/ntp_snippets/category_rankers/constant_category_ranker.h"
  11. #include "components/variations/variations_associated_data.h"
  12. namespace ntp_snippets {
  13. namespace {
  14. // All platforms proxy for whether the simplified NTP is enabled.
  15. bool IsSimplifiedNtpEnabled() {
  16. #if BUILDFLAG(IS_ANDROID)
  17. return true;
  18. #else
  19. return false;
  20. #endif // BUILDFLAG(IS_ANDROID)
  21. }
  22. } // namespace
  23. // Holds an experiment ID. So long as the feature is set through a server-side
  24. // variations config, this feature should exist on the client. This ensures that
  25. // the experiment ID is visible in chrome://snippets-internals.
  26. const base::Feature kRemoteSuggestionsBackendFeature{
  27. "NTPRemoteSuggestionsBackend", base::FEATURE_DISABLED_BY_DEFAULT};
  28. // Keep sorted, and keep nullptr at the end.
  29. const base::Feature* const kAllFeatures[] = {
  30. &kArticleSuggestionsFeature, &kKeepPrefetchedContentSuggestions,
  31. &kNotificationsFeature, &kRemoteSuggestionsBackendFeature,
  32. &kOptionalImagesEnabledFeature};
  33. const base::Feature kArticleSuggestionsFeature{
  34. "NTPArticleSuggestions", base::FEATURE_ENABLED_BY_DEFAULT};
  35. const base::Feature kRemoteSuggestionsEmulateM58FetchingSchedule{
  36. "RemoteSuggestionsEmulateM58FetchingSchedule",
  37. base::FEATURE_DISABLED_BY_DEFAULT};
  38. std::unique_ptr<CategoryRanker> BuildSelectedCategoryRanker(
  39. PrefService* pref_service,
  40. base::Clock* clock) {
  41. if (IsSimplifiedNtpEnabled()) {
  42. return std::make_unique<ConstantCategoryRanker>();
  43. }
  44. return std::make_unique<ClickBasedCategoryRanker>(pref_service, clock);
  45. }
  46. const base::Feature kNotificationsFeature = {"ContentSuggestionsNotifications",
  47. base::FEATURE_DISABLED_BY_DEFAULT};
  48. const char kNotificationsPriorityParam[] = "priority";
  49. const char kNotificationsTextParam[] = "text";
  50. const char kNotificationsTextValuePublisher[] = "publisher";
  51. const char kNotificationsTextValueSnippet[] = "snippet";
  52. const char kNotificationsTextValueAndMore[] = "and_more";
  53. const char kNotificationsKeepWhenFrontmostParam[] =
  54. "keep_notification_when_frontmost";
  55. const char kNotificationsOpenToNTPParam[] = "open_to_ntp";
  56. const char kNotificationsDailyLimit[] = "daily_limit";
  57. const char kNotificationsIgnoredLimitParam[] = "ignored_limit";
  58. const base::Feature kKeepPrefetchedContentSuggestions{
  59. "KeepPrefetchedContentSuggestions", base::FEATURE_ENABLED_BY_DEFAULT};
  60. const base::Feature kOptionalImagesEnabledFeature{
  61. "NTPRemoteSuggestionsOptionalImages", base::FEATURE_ENABLED_BY_DEFAULT};
  62. std::vector<const base::Feature*> GetAllFeatures() {
  63. // Skip the last feature as it's a nullptr.
  64. return std::vector<const base::Feature*>(
  65. kAllFeatures, kAllFeatures + std::size(kAllFeatures));
  66. }
  67. // Default referrer for the content suggestions.
  68. const char kDefaultReferrerUrl[] =
  69. "https://www.googleapis.com/auth/chrome-content-suggestions";
  70. // Provides ability to customize the referrer URL.
  71. // When specifying a referrer through a field trial, it must contain a path.
  72. // In case of default value above the path is empty, but it is specified.
  73. const base::FeatureParam<std::string> kArticleSuggestionsReferrerURLParam{
  74. &kArticleSuggestionsFeature, "referrer_url", kDefaultReferrerUrl};
  75. std::string GetContentSuggestionsReferrerURL() {
  76. return kArticleSuggestionsReferrerURLParam.Get();
  77. }
  78. } // namespace ntp_snippets