Commit 95a35c01 authored by Gabriel Charette's avatar Gabriel Charette

IWYU for bind/callback_helpers.h and ptr_util.h

These missing includes are preventing removal of unused headers from
task_runner_util.h and consequently migration from task_runner_util.h to
task_runner.h's new PostTaskAndReplyWithResult member method.

The following script was run on every file in the codebase, prioritizing
.h over matching .cc to best enforce the rule of not include a header
included by your .h :

def Fix(file_path):
  content = refactor_lib.ReadFile(file_path)

  # Assume fwd-decls are correct in first pass.
  fwd_decls_match = re.compile(r'\n *[^/\n][^/\n][^/\n]*class (NullCallback|DoNothing|ScopedClosureRunner);', re.DOTALL).findall(content)
  if fwd_decls_match:
    print 'fwd_decls_match in %s' % (file_path)
    return False

  bind_helpers_match = re.compile(
      # Doesn't begin with a comment.
      r'\n *[^/\n][^/\n]'
      # Anything else after a non-comment start (and don't allow this to capture a comment start either)
      r'[^/\n]*'
      # Anything before but an open angle-bracket to avoid cases like unique_ptr<Foo> where you don't need the full definition of Foo.
      r'[^<]'
      # Only match with base:: prefix; more precise, can manually fix missing includes in //base proper in a follow-up pass if needed.
      r'base::(NullCallback|DoNothing|DeletePointer)\b[^*]', re.DOTALL).findall(content)

  callback_helpers_match = re.compile(r'\n *[^/\n][^/\n][^/\n]*[^<]base::(IsBaseCallback|EnableIfIsBaseCallback|AdaptCallbackForRepeating|ScopedClosureRunner)\b[^*]', re.DOTALL).findall(content)

  ptr_util_match = re.compile(r'\n *[^/\n][^/\n][^/\n]*[^<]base::WrapUnique\b[^*]', re.DOTALL).findall(content)

  if not bind_helpers_match and not callback_helpers_match and not ptr_util_match:
    return False

  updated_content = content
  if bind_helpers_match:
    updated_content = refactor_lib.AddInclude(file_path, updated_content, "base/bind_helpers.h")
  if callback_helpers_match:
    updated_content = refactor_lib.AddInclude(file_path, updated_content, "base/callback_helpers.h")
  if ptr_util_match:
    updated_content = refactor_lib.AddInclude(file_path, updated_content, "base/memory/ptr_util.h")

  if updated_content == content:
    return False

  # Write updated file
  refactor_lib.WriteFile(file_path, updated_content)

  return True

[email protected]
(mechanical change for //base API)

Bug: 1026641
Change-Id: Ic88585c62dd2f74d34c59c708faeddb231aee47f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2087971Reviewed-by: default avatarGabriel Charette <[email protected]>
Reviewed-by: default avatardanakj <[email protected]>
Commit-Queue: Gabriel Charette <[email protected]>
Cr-Original-Commit-Position: refs/heads/[email protected]{#747685}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: b8ffaf4cfcb5e6b6a9916bb1b314820b10b0daf4
parent 101bca19
......@@ -8,6 +8,7 @@
#include <memory>
#include <string>
#include "base/callback_helpers.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ParentMap.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "callback.h"
void Foo(base::OnceClosure) {}
......
......@@ -6,6 +6,7 @@
#include "DiagnosticsReporter.h"
#include <algorithm>
#include "base/memory/ptr_util.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "make_unique_gc_object.h"
#include "base/memory/ptr_util.h"
namespace blink {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment