libchrome: Add presubmit check for Chromium UMA collection code

UMA collection macros or functions from Chromium don't work on CrOS and
send the metrics silently into the void.

Since such collecting code is used in //base changing to #ifdefs that
fail to compile on CrOS isn't feasible.

The hook can be overriden by the developer through --no-verify and this
is fine as it should be a warning but not stopping the author if they
don't need the metrics on CrOS.

BUG=b:298176110
TEST=repo upload of code that collects UMA using Chromium code

Change-Id: I5f2ec7503fb50315ab0e6eada4897252a36dba48
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/libchrome/+/4822575
Tested-by: Christoph Schlosser <cschlosser@chromium.org>
Reviewed-by: Grace Cham <hscham@chromium.org>
Commit-Queue: Christoph Schlosser <cschlosser@chromium.org>
Reviewed-by: Ian Barkley-Yeung <iby@chromium.org>
diff --git a/libchrome_tools/developer-tools/presubmit/check-libchrome.py b/libchrome_tools/developer-tools/presubmit/check-libchrome.py
index dac378b..4edf4ff 100755
--- a/libchrome_tools/developer-tools/presubmit/check-libchrome.py
+++ b/libchrome_tools/developer-tools/presubmit/check-libchrome.py
@@ -31,7 +31,11 @@
     'Use `thread_local bool|T*` instead. See https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++.md#thread_local-variables for discussion. (b/274724518)',
     # base::StringPiece will be deprecated and replaced by std:string_view.
     r'base::StringPiece':
-    'Use the now equivalent std::string_view (crrev.com/c/4294483). See upstream bug crbug.com/691162 for details.'
+    'Use the now equivalent std::string_view (crrev.com/c/4294483). See upstream bug crbug.com/691162 for details.',
+    # UMA_HISTOGRAM macros send their metrics into the void on CrOS.
+    r'UMA_(?:STABILITY_){0,1}HISTOGRAM[_A-Z0-9]*\(': 'Chromium UMA macros don\'t work on CrOS. See crsrc.org/o/src/platform2/metrics/metrics_library.h if you want to collect metrics on CrOS.',
+    # UmaHistogram functions send their metrics into the void on CrOS.
+    r'(?:base::){0,1}UmaHistogram[a-zA-Z0-9]*\(': 'Chromium UmaHistogram functions don\'t work on CrOS. See crsrc.org/o/src/platform2/metrics/metrics_library.h if you want to collect metrics on CrOS.'
 }
 
 LINE_NUMBER_RE=re.compile(r'^@@ [0-9\,\+\-]+ \+([0-9]+)[ \,][0-9 ]*@@')