Sync CrosSettings with Pref for KioskHeartbeat Events

The new implementation of sending KioskHeartbeat Events via ERP and the
MetricCollector requires the CrosSetting for KioskHeartbeatEnabled
synced to Prefs as Prefs are pulled on MetricCollector side enablement.
This change keeps Prefs in sync with changes on CrosSettings.

Bug: 316127786
Change-Id: I570239503e2d5294ed20277dd30969a096dfb2ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5119733
Code-Coverage: [email protected] <[email protected]>
Reviewed-by: Alex Ilin <[email protected]>
Commit-Queue: Marc Grimme <[email protected]>
Reviewed-by: Leonid Baraz <[email protected]>
Reviewed-by: Sergey Poromov <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1245871}
diff --git a/chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.cc b/chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.cc
index 0bd356cd..ddd817b3 100644
--- a/chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.cc
+++ b/chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.cc
@@ -8,6 +8,7 @@
 
 #include "base/containers/contains.h"
 #include "base/values.h"
+#include "chrome/browser/ash/settings/cros_settings.h"
 #include "chrome/browser/chromeos/reporting/metric_default_utils.h"
 #include "components/pref_registry/pref_registry_syncable.h"
 #include "components/reporting/metrics/reporting_settings.h"
@@ -26,6 +27,13 @@
   registry->RegisterListPref(kAppsInstalled);
 }
 
+void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
+  CHECK(registry);
+  registry->RegisterBooleanPref(
+      ::ash::kHeartbeatEnabled,
+      ::reporting::metrics::kHeartbeatTelemetryDefaultValue);
+}
+
 std::optional<std::string> GetAppReportingCategoryForType(
     ::apps::AppType app_type) {
   switch (app_type) {
diff --git a/chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.h b/chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.h
index d71125b..8a0daf3 100644
--- a/chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.h
+++ b/chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.h
@@ -8,6 +8,8 @@
 #include <optional>
 #include <string>
 
+class PrefRegistrySimple;
+
 namespace user_prefs {
 class PrefRegistrySyncable;
 }
@@ -49,6 +51,7 @@
 constexpr char kAppCategorySystemApps[] = "system_apps";
 
 void RegisterProfilePrefs(::user_prefs::PrefRegistrySyncable* registry);
+void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
 
 // Gets the corresponding app metric reporting category for the specified app
 // type.
diff --git a/chrome/browser/policy/configuration_policy_handler_list_factory.cc b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
index 1ae5c2a..60e9ce0 100644
--- a/chrome/browser/policy/configuration_policy_handler_list_factory.cc
+++ b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
@@ -187,6 +187,7 @@
 #include "chrome/browser/policy/default_geolocation_policy_handler.h"
 #include "chrome/browser/policy/device_login_screen_geolocation_access_level_policy_handler.h"
 #include "chrome/browser/policy/os_color_mode_policy_handler.h"
+#include "chromeos/ash/components/settings/cros_settings_names.h"
 #include "chromeos/ash/services/assistant/public/cpp/assistant_prefs.h"
 #include "chromeos/ash/services/multidevice_setup/public/cpp/prefs.h"
 #include "chromeos/components/disks/disks_prefs.h"
@@ -1577,6 +1578,9 @@
   { key::kUserFeedbackWithLowLevelDebugDataAllowed,
     ash::prefs::kUserFeedbackWithLowLevelDebugDataAllowed,
     base::Value::Type::LIST },
+  { key::kHeartbeatEnabled,
+    ash::kHeartbeatEnabled,
+    base::Value::Type::BOOLEAN },
 #endif // BUILDFLAG(IS_CHROMEOS_ASH)
 
 #if BUILDFLAG(IS_LINUX)
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 58ca863..9e6281d6 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -1518,6 +1518,7 @@
       registry);
   ash::login::SecurityTokenSessionController::RegisterLocalStatePrefs(registry);
   ash::reporting::LoginLogoutReporter::RegisterPrefs(registry);
+  ash::reporting::RegisterLocalStatePrefs(registry);
   ash::MultiProfileUserController::RegisterPrefs(registry);
   ash::NetworkMetadataStore::RegisterPrefs(registry);
   ash::NetworkThrottlingObserver::RegisterPrefs(registry);