Add new app metric reporting user policies and map to pref

This change adds new app metric reporting policies that control app
inventory and usage telemetry reporting. This also maps these new
policies with respective prefs so metric reporting components can easily
look them up and subscribe to changes as needed.

Bug: b:260803048
Change-Id: I1f08d360527707af100fc96e56fc5d855c5031ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4508788
Reviewed-by: Anqing Zhao <[email protected]>
Reviewed-by: Tommy Nyquist <[email protected]>
Reviewed-by: Leonid Baraz <[email protected]>
Commit-Queue: Vignesh Shenvi <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1141079}
diff --git a/chrome/browser/ash/BUILD.gn b/chrome/browser/ash/BUILD.gn
index 8df7a0a5..3203dd4 100644
--- a/chrome/browser/ash/BUILD.gn
+++ b/chrome/browser/ash/BUILD.gn
@@ -2532,6 +2532,8 @@
     "policy/reporting/metrics_reporting/device_activity/device_activity_sampler.h",
     "policy/reporting/metrics_reporting/metric_reporting_manager.cc",
     "policy/reporting/metrics_reporting/metric_reporting_manager.h",
+    "policy/reporting/metrics_reporting/metric_reporting_prefs.cc",
+    "policy/reporting/metrics_reporting/metric_reporting_prefs.h",
     "policy/reporting/metrics_reporting/mojo_service_events_observer_base.h",
     "policy/reporting/metrics_reporting/network/fake_network_diagnostics_util.cc",
     "policy/reporting/metrics_reporting/network/fake_network_diagnostics_util.h",
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
new file mode 100644
index 0000000..fcd6e91a
--- /dev/null
+++ b/chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.cc
@@ -0,0 +1,23 @@
+// Copyright 2023 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.h"
+
+#include "base/values.h"
+#include "chrome/browser/chromeos/reporting/metric_default_utils.h"
+#include "components/pref_registry/pref_registry_syncable.h"
+
+namespace ash::reporting {
+
+void RegisterProfilePrefs(::user_prefs::PrefRegistrySyncable* registry) {
+  DCHECK(registry);
+  registry->RegisterListPref(kReportAppInventory);
+  registry->RegisterListPref(kReportAppUsage);
+  registry->RegisterIntegerPref(
+      kReportAppUsageCollectionRateMs,
+      ::reporting::metrics::kDefaultAppUsageTelemetryCollectionRate
+          .InMilliseconds());
+}
+
+}  // namespace ash::reporting
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
new file mode 100644
index 0000000..57995b5
--- /dev/null
+++ b/chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.h
@@ -0,0 +1,31 @@
+// Copyright 2023 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ASH_POLICY_REPORTING_METRICS_REPORTING_METRIC_REPORTING_PREFS_H_
+#define CHROME_BROWSER_ASH_POLICY_REPORTING_METRICS_REPORTING_METRIC_REPORTING_PREFS_H_
+
+namespace user_prefs {
+class PrefRegistrySyncable;
+}
+
+namespace ash::reporting {
+
+// A list pref that controls app inventory event reporting for the specified app
+// types.
+constexpr char kReportAppInventory[] = "reporting.report_app_inventory";
+
+// A list pref that controls app usage telemetry reporting for the specified app
+// types.
+constexpr char kReportAppUsage[] = "reporting.report_app_usage";
+
+// An integer pref that controls the collection frequency of app usage
+// telemetry.
+constexpr char kReportAppUsageCollectionRateMs[] =
+    "reporting.report_app_usage_collection_rate_ms";
+
+void RegisterProfilePrefs(::user_prefs::PrefRegistrySyncable* registry);
+
+}  // namespace ash::reporting
+
+#endif  // CHROME_BROWSER_ASH_POLICY_REPORTING_METRICS_REPORTING_METRIC_REPORTING_PREFS_H_
diff --git a/chrome/browser/chromeos/reporting/metric_default_utils.h b/chrome/browser/chromeos/reporting/metric_default_utils.h
index 7d1d8c79..89b4d8b 100644
--- a/chrome/browser/chromeos/reporting/metric_default_utils.h
+++ b/chrome/browser/chromeos/reporting/metric_default_utils.h
@@ -9,6 +9,10 @@
 
 namespace reporting::metrics {
 
+// Default app telemetry collection rate.
+constexpr base::TimeDelta kDefaultAppUsageTelemetryCollectionRate =
+    base::Minutes(15);
+
 // Default audio telemetry collection rate.
 constexpr base::TimeDelta kDefaultAudioTelemetryCollectionRate =
     base::Minutes(15);
diff --git a/chrome/browser/policy/configuration_policy_handler_list_factory.cc b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
index fdf44dd..461ff00 100644
--- a/chrome/browser/policy/configuration_policy_handler_list_factory.cc
+++ b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
@@ -168,6 +168,7 @@
 #include "chrome/browser/ash/policy/handlers/configuration_policy_handler_ash.h"
 #include "chrome/browser/ash/policy/handlers/lacros_availability_policy_handler.h"
 #include "chrome/browser/ash/policy/handlers/lacros_selection_policy_handler.h"
+#include "chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.h"
 #include "chrome/browser/nearby_sharing/common/nearby_share_prefs.h"
 #include "chrome/browser/policy/default_geolocation_policy_handler.h"
 #include "chrome/browser/policy/device_login_screen_geolocation_access_level_policy_handler.h"
@@ -1425,6 +1426,15 @@
   { key::kShowDisplaySizeScreenEnabled,
     ash::prefs::kShowDisplaySizeScreenEnabled,
     base::Value::Type::BOOLEAN },
+  { key::kReportAppInventory,
+    ash::reporting::kReportAppInventory,
+    base::Value::Type::LIST },
+  { key::kReportAppUsage,
+    ash::reporting::kReportAppUsage,
+    base::Value::Type::LIST },
+  { key::kReportAppUsageCollectionRateMs,
+    ash::reporting::kReportAppUsageCollectionRateMs,
+    base::Value::Type::INTEGER },
 #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 e056747..f0d6d64b 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -387,6 +387,7 @@
 #include "chrome/browser/ash/policy/handlers/tpm_auto_update_mode_policy_handler.h"
 #include "chrome/browser/ash/policy/reporting/app_install_event_log_manager_wrapper.h"
 #include "chrome/browser/ash/policy/reporting/arc_app_install_event_logger.h"
+#include "chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.h"
 #include "chrome/browser/ash/policy/scheduled_task_handler/reboot_notifications_scheduler.h"
 #include "chrome/browser/ash/policy/status_collector/device_status_collector.h"
 #include "chrome/browser/ash/policy/status_collector/status_collector.h"
@@ -1681,6 +1682,7 @@
   file_manager::prefs::RegisterProfilePrefs(registry);
   bruschetta::prefs::RegisterProfilePrefs(registry);
   wallpaper_handlers::prefs::RegisterProfilePrefs(registry);
+  ash::reporting::RegisterProfilePrefs(registry);
 #endif  // BUILDFLAG(IS_CHROMEOS_ASH)
 
 #if BUILDFLAG(IS_CHROMEOS_LACROS)