Skip to content
  • gab's avatar
    Add missing IWYU message_loop.h includes. · f64a25e3
    gab authored
    This is a pre-req to removing the dependency from RunLoop->MessageLoop
    as many files only include run_loop.h but instantiate a MessageLoop.
    
    The following fix script was applied to each file in the codebase
    (plus a few hand fixes for DEPS and for //base):
    
    def Fix(file_path):
      content = refactor_lib.ReadFile(file_path)
    
      # Assume fwd-decls are correct in first pass.
      if 'class MessageLoop;' in content:
        return False
      if 'class MessageLoopForUI;' in content:
        return False
      if 'class MessageLoopForIO;' in content:
        return False
    
      # Using base:: prefix ensures we don't match fwd-decls and other things.
      # Will require a few fixups for missing includes in //base proper.
      # Complex prefix in regex attempts to skip comments.
      matches = re.compile(r'(\n *[^/\n][^/\n][^/\n]*base::MessageLoop(ForUI|ForIO)?\b[^*])', re.DOTALL).findall(content)
    
      if not matches:
        return False
    
      # Ignore unique pointers in headers in first pass...
      if os.path.splitext(file_path)[1] == '.h':
        found = False
        for match in matches:
          if not 'std::unique_ptr<base::MessageLoop' in match[0]:
            found = True
            break
        if not found:
          return False
    
      updated_content = refactor_lib.AddInclude(file_path, content, "base/message_loop/message_loop.h")
    
      if updated_content == content:
        return False
    
      # Write updated file
      refactor_lib.WriteFile(file_path, updated_content)
    
      return True
    
    TBR=gab@chromium.org
    BUG=703346
    CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
    
    Review-Url: https://codereview.chromium.org/2876013002
    Cr-Commit-Position: refs/heads/master@{#471412}
    f64a25e3