Ensure StrCat means StrCat

undefine StrCat from StrCatW after including windows headers that redefine it
Add preprocessor checks StrCat is not defined to something else.
Add presubmit check headers that include shlwapi.h that redefines StrCat are wrapped

Bug: chromium:856536, chromium:817738
Change-Id: Ief9303cbf6fa4f55f671861e49fb1fc747ed59aa
Reviewed-on: https://chromium-review.googlesource.com/1117180
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Dirk Pranke <[email protected]>
Reviewed-by: Bruce Dawson <[email protected]>
Commit-Queue: Danil Chapovalov <[email protected]>
Cr-Commit-Position: refs/heads/master@{#582449}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 3e7c03a7..3b87479 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -813,6 +813,28 @@
         files) ]
   return []
 
+def _CheckNoStrCatRedefines(input_api, output_api):
+  """Checks no windows headers with StrCat redefined are included directly."""
+  files = []
+  pattern_deny = input_api.re.compile(
+      r'^#include\s*[<"](shlwapi|atlbase|propvarutil|sphelper).h[">]',
+      input_api.re.MULTILINE)
+  pattern_allow = input_api.re.compile(
+      r'^#include\s"base/win/windows_defines.inc"',
+      input_api.re.MULTILINE)
+  for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
+    contents = input_api.ReadFile(f)
+    if pattern_deny.search(contents) and not pattern_allow.search(contents):
+      files.append(f.LocalPath())
+
+  if len(files):
+    return [output_api.PresubmitError(
+        'Do not #include shlwapi.h, atlbase.h, propvarutil.h or sphelper.h '
+        'directly since they pollute code with StrCat macro. Instead, '
+        'include matching header from base/win. See http://crbug.com/856536',
+        files) ]
+  return []
+
 
 def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
   """Checks to make sure no source files use UNIT_TEST."""