1 // Copyright 2018 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 
5 #include "components/feed/feed_feature_list.h"
6 #include "components/feed/buildflags.h"
7 
8 #include "base/feature_list.h"
9 #include "base/metrics/field_trial_params.h"
10 
11 namespace feed {
12 
13 const base::Feature kInterestFeedContentSuggestions{
14     "InterestFeedContentSuggestions", base::FEATURE_ENABLED_BY_DEFAULT};
15 // InterestFeedV2 takes precedence over InterestFeedContentSuggestions.
16 // InterestFeedV2 is cached in ChromeCachedFlags. If the default value here is
17 // changed, please update the cached one's default value in CachedFeatureFlags.
18 const base::Feature kInterestFeedV2{"InterestFeedV2",
19                                     base::FEATURE_DISABLED_BY_DEFAULT};
20 
21 const base::FeatureParam<std::string> kDisableTriggerTypes{
22     &kInterestFeedContentSuggestions, "disable_trigger_types", ""};
23 const base::FeatureParam<int> kSuppressRefreshDurationMinutes{
24     &kInterestFeedContentSuggestions, "suppress_refresh_duration_minutes", 30};
25 const base::FeatureParam<int> kTimeoutDurationSeconds{
26     &kInterestFeedContentSuggestions, "timeout_duration_seconds", 30};
27 const base::FeatureParam<bool> kThrottleBackgroundFetches{
28     &kInterestFeedContentSuggestions, "throttle_background_fetches", true};
29 const base::FeatureParam<bool> kOnlySetLastRefreshAttemptOnSuccess{
30     &kInterestFeedContentSuggestions,
31     "only_set_last_refresh_attempt_on_success", true};
32 
33 const base::Feature kReportFeedUserActions{"ReportFeedUserActions",
34                                            base::FEATURE_DISABLED_BY_DEFAULT};
35 
36 // Determines whether conditions should be reached before enabling the upload of
37 // click and view actions in the feed (e.g., the user needs to view X cards).
38 // For example, This is needed when the notice card is at the second position in
39 // the feed.
40 const base::Feature kInterestFeedV1ClicksAndViewsConditionalUpload{
41     "InterestFeedV1ClickAndViewActionsConditionalUpload",
42     base::FEATURE_DISABLED_BY_DEFAULT};
43 const base::Feature kInterestFeedV2ClicksAndViewsConditionalUpload{
44     "InterestFeedV2ClickAndViewActionsConditionalUpload",
45     base::FEATURE_DISABLED_BY_DEFAULT};
46 
47 // Feature that allows the client to automatically dismiss the notice card based
48 // on the clicks and views on the notice card.
49 const base::Feature kInterestFeedNoticeCardAutoDismiss{
50     "InterestFeedNoticeCardAutoDismiss", base::FEATURE_DISABLED_BY_DEFAULT};
51 
52 // Used for A:B testing of a bug fix (crbug.com/1151391).
53 const base::Feature kInterestFeedSpinnerAlwaysAnimate{
54     "InterestFeedSpinnerAlwaysAnimate", base::FEATURE_DISABLED_BY_DEFAULT};
55 
56 const char kDefaultReferrerUrl[] =
57     "https://www.googleapis.com/auth/chrome-content-suggestions";
58 
GetFeedReferrerUrl()59 std::string GetFeedReferrerUrl() {
60   const base::Feature* feature = base::FeatureList::IsEnabled(kInterestFeedV2)
61                                      ? &kInterestFeedV2
62                                      : &kInterestFeedContentSuggestions;
63   std::string referrer =
64       base::GetFieldTrialParamValueByFeature(*feature, "referrer_url");
65   return referrer.empty() ? kDefaultReferrerUrl : referrer;
66 }
67 
68 // Chrome can be built with or without v1 or v2.
69 // If both are built-in, use kInterestFeedV2 to decide whether v2 is used.
70 // Otherwise use the version available.
IsV2Enabled()71 bool IsV2Enabled() {
72 #if BUILDFLAG(ENABLE_FEED_V1) && BUILDFLAG(ENABLE_FEED_V2)
73   return base::FeatureList::IsEnabled(feed::kInterestFeedV2);
74 #elif BUILDFLAG(ENABLE_FEED_V1)
75   return false;
76 #else
77   return true;
78 #endif
79 }
80 
IsV1Enabled()81 bool IsV1Enabled() {
82   return !IsV2Enabled();
83 }
84 
85 }  // namespace feed
86