From: uazo <uazo@users.noreply.github.com>
Date: Mon, 2 May 2022 11:48:03 +0000
Subject: Add site engagement flag

Enabled by default.

Original License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
 chrome/browser/about_flags.cc                 |  6 ++++
 chrome/browser/flag_descriptions.cc           |  5 +++
 chrome/browser/flag_descriptions.h            |  3 ++
 .../content/site_engagement_score.cc          |  5 +++
 components/site_engagement/core/BUILD.gn      |  6 ++++
 components/site_engagement/core/features.cc   | 29 ++++++++++++++++
 components/site_engagement/core/features.h    | 34 +++++++++++++++++++
 7 files changed, 88 insertions(+)
 create mode 100644 components/site_engagement/core/features.cc
 create mode 100644 components/site_engagement/core/features.h

diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -142,6 +142,7 @@
 #include "components/segmentation_platform/public/features.h"
 #include "components/send_tab_to_self/features.h"
 #include "components/services/heap_profiling/public/cpp/switches.h"
+#include "components/site_engagement/core/features.h"
 #include "components/shared_highlighting/core/common/shared_highlighting_features.h"
 #include "components/signin/core/browser/dice_account_reconcilor_delegate.h"
 #include "components/signin/public/base/signin_buildflags.h"
@@ -9174,6 +9175,11 @@ const FeatureEntry kFeatureEntries[] = {
      flag_descriptions::kSearchReadyOmniboxDescription, kOsAndroid,
      FEATURE_VALUE_TYPE(chrome::android::kSearchReadyOmniboxFeature)},
 
+    {"site-engagement",
+     flag_descriptions::kSiteEngagementName,
+     flag_descriptions::kSiteEngagementDescription, kOsAll,
+     FEATURE_VALUE_TYPE(site_engagement::features::kSiteEngagement)},
+
 #if BUILDFLAG(IS_CHROMEOS_ASH)
     {"use-multiple-overlays", flag_descriptions::kUseMultipleOverlaysName,
      flag_descriptions::kUseMultipleOverlaysDescription, kOsCrOS,
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -3461,6 +3461,11 @@ const char kSkipServiceWorkerFetchHandlerDescription[] =
     "Skips starting the service worker and run the fetch handler if the fetch "
     "handler is recognized as skippable.";
 
+const char kSiteEngagementName[] =
+    "Enable site engagement feature";
+const char kSiteEngagementDescription[] =
+    "Site Engagement Service provides information about how engaged a user is with a origin; this affects which NTP tiles are automatically created.";
+
 const char kWebSQLAccessName[] = "Allows access to WebSQL APIs";
 const char kWebSQLAccessDescription[] =
     "The WebSQL API is enabled by default, but can be disabled here.";
diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
--- a/chrome/browser/flag_descriptions.h
+++ b/chrome/browser/flag_descriptions.h
@@ -1975,6 +1975,9 @@ extern const char kReduceUserAgentPlatformOsCpuDescription[];
 extern const char kSkipServiceWorkerFetchHandlerName[];
 extern const char kSkipServiceWorkerFetchHandlerDescription[];
 
+extern const char kSiteEngagementName[];
+extern const char kSiteEngagementDescription[];
+
 extern const char kWebSQLAccessName[];
 extern const char kWebSQLAccessDescription[];
 
diff --git a/components/site_engagement/content/site_engagement_score.cc b/components/site_engagement/content/site_engagement_score.cc
--- a/components/site_engagement/content/site_engagement_score.cc
+++ b/components/site_engagement/content/site_engagement_score.cc
@@ -17,6 +17,7 @@
 #include "components/content_settings/core/common/content_settings.h"
 #include "components/content_settings/core/common/content_settings_types.h"
 #include "components/content_settings/core/common/content_settings_utils.h"
+#include "components/site_engagement/core/features.h"
 #include "components/site_engagement/content/engagement_type.h"
 #include "components/site_engagement/content/site_engagement_metrics.h"
 #include "components/variations/variations_associated_data.h"
@@ -275,6 +276,10 @@ void SiteEngagementScore::Commit() {
   if (!UpdateScoreDict(*score_dict_))
     return;
 
+  if (!base::FeatureList::IsEnabled(features::kSiteEngagement)) {
+    score_dict_.reset();
+    return;
+  }
   settings_map_->SetWebsiteSettingDefaultScope(
       origin_, GURL(), ContentSettingsType::SITE_ENGAGEMENT,
       base::Value(std::move(*score_dict_)));
diff --git a/components/site_engagement/core/BUILD.gn b/components/site_engagement/core/BUILD.gn
--- a/components/site_engagement/core/BUILD.gn
+++ b/components/site_engagement/core/BUILD.gn
@@ -4,8 +4,14 @@
 
 static_library("core") {
   sources = [
+    "features.cc",
+    "features.h",
     "pref_names.cc",
     "pref_names.h",
     "site_engagement_score_provider.h",
   ]
+
+  deps = [
+    "//base",
+  ]
 }
diff --git a/components/site_engagement/core/features.cc b/components/site_engagement/core/features.cc
new file mode 100644
--- /dev/null
+++ b/components/site_engagement/core/features.cc
@@ -0,0 +1,29 @@
+/*
+    This file is part of Bromite.
+
+    Bromite is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    Bromite is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Bromite. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include "components/site_engagement/core/features.h"
+
+#include "base/feature_list.h"
+
+namespace site_engagement {
+namespace features {
+
+const base::Feature kSiteEngagement{"SiteEngagement",
+                                    base::FEATURE_ENABLED_BY_DEFAULT};
+
+}  // namespace features
+}  // namespace site_engagement
diff --git a/components/site_engagement/core/features.h b/components/site_engagement/core/features.h
new file mode 100644
--- /dev/null
+++ b/components/site_engagement/core/features.h
@@ -0,0 +1,34 @@
+/*
+    This file is part of Bromite.
+
+    Bromite is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    Bromite is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Bromite. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#ifndef SITE_ENGAGEMENT_CORE_FEATURES_H_
+#define SITE_ENGAGEMENT_CORE_FEATURES_H_
+
+#include <string>
+
+#include "base/feature_list.h"
+
+namespace site_engagement {
+namespace features {
+
+// Enable site engagement
+extern const base::Feature kSiteEngagement;
+
+}  // namespace features
+}  // namespace site_engagement
+
+#endif  // SITE_ENGAGEMENT_CORE_FEATURES_H_
--
2.25.1
