Commit ff7dace0 authored by Sami Kyostila's avatar Sami Kyostila Committed by Commit Bot

chrome/browser/plugins: Always specify thread affinity when posting tasks

*** Note: There is no behavior change from this patch. ***

The PostTask APIs will shortly be changed to require all tasks to explicitly
specify their thread affinity, i.e., whether the task should run on the thread
pool or a specific named thread such as a BrowserThread. This patch updates all
call sites with thread affinity annotation. We also remove the "WithTraits"
suffix to make the call sites more readable.

Before:

    // Thread pool task.
    base::PostTaskWithTraits(FROM_HERE, {...}, ...);

    // UI thread task.
    base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI, ...}, ...);

After:

    // Thread pool task.
    base::PostTask(FROM_HERE, {base::ThreadPool(), ...}, ...);

    // UI thread task.
    base::PostTask(FROM_HERE, {BrowserThread::UI, ...}, ...);

This patch was semi-automatically prepared with these steps:

    1. Patch in https://crrev.com/c/1635827 to make thread affinity a build-time
       requirement.
    2. Run an initial pass with a clang rewriter:
       https://chromium-review.googlesource.com/c/chromium/src/+/1635623
    3. ninja -C out/Debug | grep 'requested here' | cut -d: -f1-3 | sort | \
           uniq > errors.txt
    4. while read line; do
         f=$(echo $line | cut -d: -f 1)
         r=$(echo $line | cut -d: -f 2)
         c=$(echo $line | cut -d: -f 3)
         sed -i "${r}s/./&base::ThreadPool(),/$c" $f
       done < errors.txt
    5. GOTO 3 until build succeeds.
    6. Remove the "WithTraits" suffix from task API call sites:

       $ tools/git/mffr.py -i <(cat <<EOF
       [
         ["PostTaskWithTraits",
          "PostTask"],
         ["PostDelayedTaskWithTraits",
          "PostDelayedTask"],
         ["PostTaskWithTraitsAndReply",
          "PostTaskAndReply"],
         ["CreateTaskRunnerWithTraits",
          "CreateTaskRunner"],
         ["CreateSequencedTaskRunnerWithTraits",
          "CreateSequencedTaskRunner"],
         ["CreateUpdateableSequencedTaskRunnerWithTraits",
          "CreateUpdateableSequencedTaskRunner"],
         ["CreateSingleThreadTaskRunnerWithTraits",
          "CreateSingleThreadTaskRunner"],
         ["CreateCOMSTATaskRunnerWithTraits",
          "CreateCOMSTATaskRunner"]
       ]
       EOF
       )

This CL was uploaded by git cl split.

R=tommycli@chromium.org

Bug: 968047
Change-Id: Id69af8c66a5b886be639f1f22c0dc027a49e7758
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1738702
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684431}
parent 301d265e
...@@ -174,7 +174,7 @@ void PDFIFrameNavigationThrottle::LoadPlaceholderHTML() { ...@@ -174,7 +174,7 @@ void PDFIFrameNavigationThrottle::LoadPlaceholderHTML() {
PdfWebContentsLifetimeHelper::CreateForWebContents(web_contents); PdfWebContentsLifetimeHelper::CreateForWebContents(web_contents);
PdfWebContentsLifetimeHelper* helper = PdfWebContentsLifetimeHelper* helper =
PdfWebContentsLifetimeHelper::FromWebContents(web_contents); PdfWebContentsLifetimeHelper::FromWebContents(web_contents);
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {content::BrowserThread::UI}, FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&PdfWebContentsLifetimeHelper::NavigateIFrameToPlaceholder, base::BindOnce(&PdfWebContentsLifetimeHelper::NavigateIFrameToPlaceholder,
helper->GetWeakPtr(), params)); helper->GetWeakPtr(), params));
......
...@@ -105,7 +105,7 @@ void PluginResponseInterceptorURLLoaderThrottle::WillProcessResponse( ...@@ -105,7 +105,7 @@ void PluginResponseInterceptorURLLoaderThrottle::WillProcessResponse(
bool embedded = bool embedded =
resource_type_ != static_cast<int>(content::ResourceType::kMainFrame); resource_type_ != static_cast<int>(content::ResourceType::kMainFrame);
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {content::BrowserThread::UI}, FROM_HERE, {content::BrowserThread::UI},
base::BindOnce( base::BindOnce(
&extensions::StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent, &extensions::StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent,
......
...@@ -50,7 +50,7 @@ class PluginResponseInterceptorURLLoaderThrottleBrowserTest ...@@ -50,7 +50,7 @@ class PluginResponseInterceptorURLLoaderThrottleBrowserTest
int CountPDFProcesses() { int CountPDFProcesses() {
int result = -1; int result = -1;
base::RunLoop run_loop; base::RunLoop run_loop;
base::PostTaskWithTraitsAndReply( base::PostTaskAndReply(
FROM_HERE, {content::BrowserThread::IO}, FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&PluginResponseInterceptorURLLoaderThrottleBrowserTest:: base::BindOnce(&PluginResponseInterceptorURLLoaderThrottleBrowserTest::
CountPDFProcessesOnIOThread, CountPDFProcessesOnIOThread,
......
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