content: Replace uses of BrowserThread task posting with post_task.h API

This patch updates callsites of BrowserThread task posting methods to
use the post_task.h API instead.

Background: We're changing the way tasks are posted to a BrowserThread,
see PSA [1] and design doc [2]. This unifies the way tasks are posted
and paves the way for annotating tasks with task types and other
attributes that can be used to prioritize tasks in the future browser
UI thread scheduler (design doc [3]).

This CL changes callsites of the following forms:
(a) BrowserThread::Post*Task(BrowserThread::UI/IO, ..) to
    base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI/IO}, ..),
(b) BrowserThread::GetTaskRunnerForThread(BrowserThread::UI/IO) to
    base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI/IO}).

It also adds necessary includes. These mechanical changes were applied
by a script.

Tasks posted with the same BrowserThread::ID trait (via
PostTaskWithTraits or TaskRunners obtained from
Create*TaskRunnerWithTraits) will still execute in the order they
were posted, see [4].

[1] https://groups.google.com/a/chromium.org/d/topic/chromium-dev/A3_snMVXv8A/discussion
[2] https://docs.google.com/document/d/1SGy9VTXUwyXEX_yBZ0ukFAnS8B0hDeMUJD-1iALaE-Q/edit?usp=sharing
[3] https://docs.google.com/document/d/1z1BDq9vzcEpkhN9LSPF5XMnZ0kLJ8mWWkNAi4OI7cos/edit?usp=sharing
[4] https://cs.chromium.org/chromium/src/base/task/post_task.h?l=66

[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]

Bug: 878356
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:linux_vr;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I37526c8e75630ee7bec29421276094a30e903894
Reviewed-on: https://chromium-review.googlesource.com/1186623
Reviewed-by: Eric Seckler <[email protected]>
Reviewed-by: Vaclav Brozek <[email protected]>
Reviewed-by: Alex Clarke <[email protected]>
Reviewed-by: Sami Kyöstilä <[email protected]>
Commit-Queue: Eric Seckler <[email protected]>
Cr-Commit-Position: refs/heads/master@{#592750}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index e6e3a6e..cc0105c 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -29,6 +29,7 @@
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/string_util.h"
 #include "base/strings/utf_string_conversions.h"
+#include "base/task/post_task.h"
 #include "base/threading/thread_task_runner_handle.h"
 #include "base/time/time.h"
 #include "base/trace_event/trace_event.h"
@@ -98,6 +99,7 @@
 #include "content/public/browser/ax_event_notification_details.h"
 #include "content/public/browser/browser_context.h"
 #include "content/public/browser/browser_plugin_guest_manager.h"
+#include "content/public/browser/browser_task_traits.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/content_browser_client.h"
 #include "content/public/browser/download_manager.h"
@@ -3952,8 +3954,8 @@
     // Android), the downloader service will be invalid. Pre-Mojo, this would
     // hang the callback indefinitely since the IPC would be dropped. Now,
     // respond with a 400 HTTP error code to indicate that something went wrong.
-    BrowserThread::PostTask(
-        BrowserThread::UI, FROM_HERE,
+    base::PostTaskWithTraits(
+        FROM_HERE, {BrowserThread::UI},
         base::BindOnce(&WebContentsImpl::OnDidDownloadImage,
                        weak_factory_.GetWeakPtr(), std::move(callback),
                        download_id, url, 400, std::vector<SkBitmap>(),
@@ -4301,8 +4303,8 @@
         resource_type == RESOURCE_TYPE_MEDIA
             ? partition->GetMediaURLRequestContext()
             : partition->GetURLRequestContext());
-    BrowserThread::PostTask(
-        BrowserThread::IO, FROM_HERE,
+    base::PostTaskWithTraits(
+        FROM_HERE, {BrowserThread::IO},
         base::BindOnce(&NotifyCacheOnIO, request_context, url, http_method));
   }
 }