Commit 3cd045bd authored by Sami Kyostila's avatar Sami Kyostila Committed by Commit Bot

chrome/browser/spellchecker: 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=rouslan@chromium.org

Bug: 968047
Change-Id: I695547fcd8f3859e16252bf24b8e78d6374ede4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1739867
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684429}
parent 74a89b88
...@@ -222,8 +222,8 @@ int SpellcheckCustomDictionary::Change::Sanitize( ...@@ -222,8 +222,8 @@ int SpellcheckCustomDictionary::Change::Sanitize(
SpellcheckCustomDictionary::SpellcheckCustomDictionary( SpellcheckCustomDictionary::SpellcheckCustomDictionary(
const base::FilePath& dictionary_directory_name) const base::FilePath& dictionary_directory_name)
: task_runner_( : task_runner_(base::CreateSequencedTaskRunner(
base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()})), {base::ThreadPool(), base::MayBlock()})),
custom_dictionary_path_( custom_dictionary_path_(
dictionary_directory_name.Append(chrome::kCustomDictionaryFileName)), dictionary_directory_name.Append(chrome::kCustomDictionaryFileName)),
is_loaded_(false) {} is_loaded_(false) {}
...@@ -452,7 +452,7 @@ void SpellcheckCustomDictionary::OnLoaded( ...@@ -452,7 +452,7 @@ void SpellcheckCustomDictionary::OnLoaded(
fix_invalid_file_.Reset( fix_invalid_file_.Reset(
base::BindOnce(&SpellcheckCustomDictionary::FixInvalidFile, base::BindOnce(&SpellcheckCustomDictionary::FixInvalidFile,
weak_ptr_factory_.GetWeakPtr(), std::move(result))); weak_ptr_factory_.GetWeakPtr(), std::move(result)));
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, FROM_HERE,
{content::BrowserThread::UI, base::TaskPriority::BEST_EFFORT}, {content::BrowserThread::UI, base::TaskPriority::BEST_EFFORT},
fix_invalid_file_.callback()); fix_invalid_file_.callback());
......
...@@ -110,8 +110,8 @@ SpellcheckHunspellDictionary::SpellcheckHunspellDictionary( ...@@ -110,8 +110,8 @@ SpellcheckHunspellDictionary::SpellcheckHunspellDictionary(
const std::string& language, const std::string& language,
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
SpellcheckService* spellcheck_service) SpellcheckService* spellcheck_service)
: task_runner_( : task_runner_(base::CreateSequencedTaskRunner(
base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()})), {base::ThreadPool(), base::MayBlock()})),
language_(language), language_(language),
use_browser_spellchecker_(false), use_browser_spellchecker_(false),
browser_context_(browser_context), browser_context_(browser_context),
......
...@@ -128,10 +128,9 @@ void SpellingRequest::OnLocalCheckCompletedOnAnyThread( ...@@ -128,10 +128,9 @@ void SpellingRequest::OnLocalCheckCompletedOnAnyThread(
base::WeakPtr<SpellingRequest> request, base::WeakPtr<SpellingRequest> request,
const std::vector<SpellCheckResult>& results) { const std::vector<SpellCheckResult>& results) {
// Local checking can happen on any thread - don't DCHECK thread. // Local checking can happen on any thread - don't DCHECK thread.
base::PostTaskWithTraits( base::PostTask(FROM_HERE, {content::BrowserThread::UI},
FROM_HERE, {content::BrowserThread::UI}, base::BindOnce(&SpellingRequest::OnLocalCheckCompleted,
base::BindOnce(&SpellingRequest::OnLocalCheckCompleted, request, request, results));
results));
} }
void SpellingRequest::OnLocalCheckCompleted( void SpellingRequest::OnLocalCheckCompleted(
......
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