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

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

Bug: 968047
Change-Id: Ibc31dc65ba9108247d7e6780d5f815827f4a3354
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1739814
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avataroysteine <oysteine@chromium.org>
Commit-Queue: oysteine <oysteine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684453}
parent fbcdfcda
...@@ -104,10 +104,10 @@ class ChromeTracingDelegateBrowserTest : public InProcessBrowserTest { ...@@ -104,10 +104,10 @@ class ChromeTracingDelegateBrowserTest : public InProcessBrowserTest {
done_callback) { done_callback) {
receive_count_ += 1; receive_count_ += 1;
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI}, base::PostTask(FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(std::move(done_callback), true)); base::BindOnce(std::move(done_callback), true));
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI}, base::PostTask(FROM_HERE, {content::BrowserThread::UI},
on_upload_callback_); on_upload_callback_);
} }
void OnStartedFinalizing(bool success) { void OnStartedFinalizing(bool success) {
...@@ -115,8 +115,8 @@ class ChromeTracingDelegateBrowserTest : public InProcessBrowserTest { ...@@ -115,8 +115,8 @@ class ChromeTracingDelegateBrowserTest : public InProcessBrowserTest {
last_on_started_finalizing_success_ = success; last_on_started_finalizing_success_ = success;
if (!on_started_finalization_callback_.is_null()) { if (!on_started_finalization_callback_.is_null()) {
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI}, base::PostTask(FROM_HERE, {content::BrowserThread::UI},
on_started_finalization_callback_); on_started_finalization_callback_);
} }
} }
......
...@@ -101,9 +101,8 @@ void TraceCrashServiceUploader::OnSimpleURLLoaderComplete( ...@@ -101,9 +101,8 @@ void TraceCrashServiceUploader::OnSimpleURLLoaderComplete(
base::NumberToString(response_code); base::NumberToString(response_code);
} }
base::PostTaskWithTraits( base::PostTask(FROM_HERE, {content::BrowserThread::UI},
FROM_HERE, {content::BrowserThread::UI}, base::BindOnce(std::move(done_callback_), success, feedback));
base::BindOnce(std::move(done_callback_), success, feedback));
simple_url_loader_.reset(); simple_url_loader_.reset();
} }
...@@ -116,8 +115,8 @@ void TraceCrashServiceUploader::OnURLLoaderUploadProgress(uint64_t current, ...@@ -116,8 +115,8 @@ void TraceCrashServiceUploader::OnURLLoaderUploadProgress(uint64_t current,
if (progress_callback_.is_null()) if (progress_callback_.is_null())
return; return;
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI}, base::PostTask(FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(progress_callback_, current, total)); base::BindOnce(progress_callback_, current, total));
} }
void TraceCrashServiceUploader::DoUpload( void TraceCrashServiceUploader::DoUpload(
...@@ -131,8 +130,8 @@ void TraceCrashServiceUploader::DoUpload( ...@@ -131,8 +130,8 @@ void TraceCrashServiceUploader::DoUpload(
progress_callback_ = progress_callback; progress_callback_ = progress_callback;
done_callback_ = std::move(done_callback); done_callback_ = std::move(done_callback);
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {base::TaskPriority::BEST_EFFORT}, FROM_HERE, {base::ThreadPool(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(&TraceCrashServiceUploader::DoCompressOnBackgroundThread, base::BindOnce(&TraceCrashServiceUploader::DoCompressOnBackgroundThread,
base::Unretained(this), file_contents, upload_mode, base::Unretained(this), file_contents, upload_mode,
upload_url_, std::move(metadata))); upload_url_, std::move(metadata)));
...@@ -207,7 +206,7 @@ void TraceCrashServiceUploader::DoCompressOnBackgroundThread( ...@@ -207,7 +206,7 @@ void TraceCrashServiceUploader::DoCompressOnBackgroundThread(
SetupMultipart(product, version, std::move(metadata), "trace.json.gz", SetupMultipart(product, version, std::move(metadata), "trace.json.gz",
compressed_contents, &post_data); compressed_contents, &post_data);
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {content::BrowserThread::UI}, FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&TraceCrashServiceUploader::CreateAndStartURLLoader, base::BindOnce(&TraceCrashServiceUploader::CreateAndStartURLLoader,
base::Unretained(this), upload_url, post_data)); base::Unretained(this), upload_url, post_data));
...@@ -216,7 +215,7 @@ void TraceCrashServiceUploader::DoCompressOnBackgroundThread( ...@@ -216,7 +215,7 @@ void TraceCrashServiceUploader::DoCompressOnBackgroundThread(
void TraceCrashServiceUploader::OnUploadError( void TraceCrashServiceUploader::OnUploadError(
const std::string& error_message) { const std::string& error_message) {
LOG(ERROR) << error_message; LOG(ERROR) << error_message;
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {content::BrowserThread::UI}, FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(std::move(done_callback_), false, error_message)); base::BindOnce(std::move(done_callback_), false, error_message));
} }
......
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