[go: nahoru, domu]

🧇 Add histograms to track SearchProviderOverride usage

Adds the Search.SearchProviderOverrideStatus histogram

Bug: 1517316
Bug: b:302675777
Change-Id: I55281aa1e520f63c16907891c95fb8a35fb983c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5181077
Auto-Submit: Nicolas Dossou-Gbété <dgn@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Luc Nguyen <lucnguyen@google.com>
Reviewed-by: Alex Ilin <alexilin@chromium.org>
Reviewed-by: David Roger <droger@chromium.org>
Commit-Queue: Nicolas Dossou-Gbété <dgn@chromium.org>
Reviewed-by: Orin Jaworski <orinj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1247193}
diff --git a/components/search_engines/template_url_prepopulate_data.cc b/components/search_engines/template_url_prepopulate_data.cc
index 7eb20a8b..3a7e303 100644
--- a/components/search_engines/template_url_prepopulate_data.cc
+++ b/components/search_engines/template_url_prepopulate_data.cc
@@ -12,6 +12,7 @@
 #include "base/containers/contains.h"
 #include "base/feature_list.h"
 #include "base/logging.h"
+#include "base/metrics/histogram_functions.h"
 #include "base/rand_util.h"
 #include "base/ranges/algorithm.h"
 #include "build/build_config.h"
@@ -1728,6 +1729,23 @@
   return t_urls;
 }
 
+// These values are persisted to logs. Entries should not be renumbered and
+// numeric values should never be reused.
+enum class SearchProviderOverrideStatus {
+  // No preferences are available for `prefs::kSearchProviderOverrides`.
+  kNoPref = 0,
+
+  // The preferences for `prefs::kSearchProviderOverrides` do not contain valid
+  // template URLs.
+  kEmptyPref = 1,
+
+  // The preferences for `prefs::kSearchProviderOverrides` contain valid
+  // template URL(s).
+  kPrefHasValidUrls = 2,
+
+  kMaxValue = kPrefHasValidUrls
+};
+
 std::vector<std::unique_ptr<TemplateURLData>> GetOverriddenTemplateURLData(
     PrefService* prefs) {
   std::vector<std::unique_ptr<TemplateURLData>> t_urls;
@@ -1745,6 +1763,14 @@
       }
     }
   }
+
+  base::UmaHistogramEnumeration(
+      "Search.SearchProviderOverrideStatus",
+      !t_urls.empty() ? SearchProviderOverrideStatus::kPrefHasValidUrls
+                      : (prefs->HasPrefPath(prefs::kSearchProviderOverrides)
+                             ? SearchProviderOverrideStatus::kEmptyPref
+                             : SearchProviderOverrideStatus::kNoPref));
+
   return t_urls;
 }
 
diff --git a/tools/metrics/histograms/enums.xml b/tools/metrics/histograms/enums.xml
index bdcfe0b..89c94b4 100644
--- a/tools/metrics/histograms/enums.xml
+++ b/tools/metrics/histograms/enums.xml
@@ -37287,6 +37287,12 @@
   <int value="1" label="From omnibox"/>
 </enum>
 
+<enum name="SearchProviderOverrideStatus">
+  <int value="0" label="kNoPref"/>
+  <int value="1" label="kEmptyPref"/>
+  <int value="2" label="kPrefHasValidUrls"/>
+</enum>
+
 <enum name="SearchWidgetUseInfo">
   <int value="0" label="defunct Present in partnership device"/>
   <int value="1" label="defunct Not present in partnership device"/>
diff --git a/tools/metrics/histograms/metadata/search/histograms.xml b/tools/metrics/histograms/metadata/search/histograms.xml
index d79d065..f9c177e 100644
--- a/tools/metrics/histograms/metadata/search/histograms.xml
+++ b/tools/metrics/histograms/metadata/search/histograms.xml
@@ -1080,6 +1080,19 @@
   </summary>
 </histogram>
 
+<histogram name="Search.SearchProviderOverrideStatus"
+    enum="SearchProviderOverrideStatus" expires_after="2024-06-01">
+  <owner>dgn@chromium.org</owner>
+  <owner>droger@chromium.org</owner>
+  <summary>
+    The status of the preference where the search engine overrides provided by
+    the Chrome distribution channel are loaded. It is recorded every time we put
+    together a list of built-in search engines providers, which can happen
+    multiple times per run, when initially loading search engines for the
+    omnibox, showing a search engine choice screen or settings screen, etc.
+  </summary>
+</histogram>
+
 <histogram name="Search.SearchWidgetUseAndDeviceInfo"
     enum="SearchWidgetUseInfo" expires_after="2020-02-16">
   <owner>yusufo@chromium.org</owner>