Use checkdeps to ensure API headers don't include internal headers.

This CL updates the checkdeps configuration for the api/ folder in
order to explicitly avoid to #include non API headers from API headers.

In order to force a careful review of potential exceptions to this
rule, the CL also adds mbonadei@ and kwiberg@ as OWNERS of api/DEPS.

Bug: webrtc:9887
Change-Id: I0ada6f1020186b2782c7d060af36079c452ba1aa
Reviewed-on: https://webrtc-review.googlesource.com/c/106800
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25338}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index a7b5cc1..b5d1e11 100755
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -862,6 +862,62 @@
   results.extend(CheckNoStreamUsageIsAdded(
       input_api, output_api, non_third_party_sources))
   results.extend(CheckAddedDepsHaveTargetApprovals(input_api, output_api))
+  results.extend(CheckApiDepsFileIsUpToDate(input_api, output_api))
+  return results
+
+
+def CheckApiDepsFileIsUpToDate(input_api, output_api):
+  results = []
+  api_deps = os.path.join(input_api.PresubmitLocalPath(), 'api', 'DEPS')
+  with open(api_deps) as f:
+    deps_content = _ParseDeps(f.read())
+
+  include_rules = deps_content.get('include_rules', [])
+  specific_include_rules = deps_content.get('specific_include_rules', [])
+  cc_include_rules = specific_include_rules.get(r'.*\.cc', [])
+
+  top_level_files = [f for f in os.listdir(input_api.PresubmitLocalPath())
+                     if f != 'api' and not f.startswith('.')]
+  top_level_dirs = []
+  for f in top_level_files:
+    if os.path.isdir(os.path.join(input_api.PresubmitLocalPath(), f)):
+      top_level_dirs.append(f)
+
+  missing_include_rules = []
+  for p in top_level_dirs:
+    rule = '-%s' % p
+    if rule not in include_rules:
+      missing_include_rules.append(rule)
+  if missing_include_rules:
+    results.append(output_api.PresubmitError(
+        'Please add the following lines to `include_rules` in file\n'
+        '%s:\n%s' % (api_deps, str(missing_include_rules))))
+
+  missing_cc_include_rules = []
+  non_webrtc_dirs = [
+      'base',
+      'build',
+      'build_overrides',
+      'buildtools',
+      'data',
+      'infra',
+      'out',
+      'resources',
+      'testing',
+      'style-guide',
+  ]
+  webrtc_top_level_dirs = [d for d in top_level_dirs
+                           if d not in non_webrtc_dirs]
+
+  for p in webrtc_top_level_dirs:
+    rule = '+%s' % p
+    if rule not in cc_include_rules:
+      missing_cc_include_rules.append(rule)
+  if missing_cc_include_rules:
+    results.append(output_api.PresubmitError(
+        r'Please add the following lines to the `.*\.cc` rule under '
+        '`specific_include_rules` in file\n'
+        '%s:\n%s' % (api_deps, str(missing_cc_include_rules))))
   return results