Improve _CheckUmaHistogramChanges presubmit

The _CheckUmaHistogramChanges checks whether newly added
UMA_HISTOGRAM_* calls only use defined histogram names.

This CL removes two ways to introduce false positives:
* Unrelated macro names which contain UMA_HISTOGRAM as a continuous
  substring
* More than one string literal on the line with the histogram name.

While those cases are rare, there seems no downside to fixing them.

Bug: 821981
Change-Id: Ie1a803f562883f567d577e742ed2ed87fd0dfe66
Reviewed-on: https://chromium-review.googlesource.com/978245
Commit-Queue: Vaclav Brozek <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/master@{#545583}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 9aa6800..3cf3d7a 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -731,7 +731,9 @@
   the reverse: changes in histograms.xml not matched in the code itself."""
   touched_histograms = []
   histograms_xml_modifications = []
-  pattern = input_api.re.compile('UMA_HISTOGRAM.*\("(.*)"')
+  # For now, the check only detects the case of the macro and histogram names
+  # being on a single line.
+  single_line_re = input_api.re.compile(r'\bUMA_HISTOGRAM.*\("(.*?)"')
   for f in input_api.AffectedFiles():
     # If histograms.xml itself is modified, keep the modified lines for later.
     if f.LocalPath().endswith(('histograms.xml')):
@@ -740,7 +742,7 @@
     if not f.LocalPath().endswith(('cc', 'mm', 'cpp')):
       continue
     for line_num, line in f.ChangedContents():
-      found = pattern.search(line)
+      found = single_line_re.search(line)
       if found:
         touched_histograms.append([found.group(1), f, line_num])