Commit 2f664e49 authored by Sami Kyostila's avatar Sami Kyostila Committed by Commit Bot

printing: 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://chromium-review.googlesource.com/c/chromium/src/+/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=rbpotter@chromium.org

Bug: 968047
Change-Id: I105e2965f7d21583f68174683a8e76823f7f3065
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1729077
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683302}
parent d6ec9381
......@@ -94,8 +94,9 @@ void DebugDumpSettings(const base::string16& doc_name,
job_settings, base::JSONWriter::OPTIONS_PRETTY_PRINT, &settings_str);
scoped_refptr<base::RefCountedMemory> data =
base::RefCountedString::TakeString(&settings_str);
base::PostTaskWithTraits(
FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()},
base::PostTask(
FROM_HERE,
{base::ThreadPool(), base::TaskPriority::BEST_EFFORT, base::MayBlock()},
base::BindOnce(&DebugDumpDataTask, doc_name, FILE_PATH_LITERAL(".json"),
base::RetainedRef(data)));
}
......@@ -138,8 +139,9 @@ void PrintedDocument::SetPage(int page_number,
}
if (HasDebugDumpPath()) {
base::PostTaskWithTraits(
FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()},
base::PostTask(
FROM_HERE,
{base::ThreadPool(), base::TaskPriority::BEST_EFFORT, base::MayBlock()},
base::BindOnce(&DebugDumpPageTask, name(), base::RetainedRef(page)));
}
}
......@@ -169,8 +171,9 @@ void PrintedDocument::SetDocument(std::unique_ptr<MetafilePlayer> metafile,
}
if (HasDebugDumpPath()) {
base::PostTaskWithTraits(
FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()},
base::PostTask(
FROM_HERE,
{base::ThreadPool(), base::TaskPriority::BEST_EFFORT, base::MayBlock()},
base::BindOnce(&DebugDumpTask, name(), mutable_.metafile_.get()));
}
}
......@@ -268,10 +271,11 @@ void PrintedDocument::DebugDumpData(
const base::RefCountedMemory* data,
const base::FilePath::StringType& extension) {
DCHECK(HasDebugDumpPath());
base::PostTaskWithTraits(FROM_HERE,
{base::TaskPriority::BEST_EFFORT, base::MayBlock()},
base::BindOnce(&DebugDumpDataTask, name(), extension,
base::RetainedRef(data)));
base::PostTask(
FROM_HERE,
{base::ThreadPool(), base::TaskPriority::BEST_EFFORT, base::MayBlock()},
base::BindOnce(&DebugDumpDataTask, name(), extension,
base::RetainedRef(data)));
}
#if defined(OS_WIN) || defined(OS_MACOSX)
......
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