Commit 758a0522 authored by Sami Kyostila's avatar Sami Kyostila Committed by Commit Bot

ash: 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 with
       tools/git/mffr.py.

This CL was uploaded by git cl split.

R=oshima@chromium.org

Bug: 968047
Change-Id: I9ee81e17587644f1651afd664168c0f864df93ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1728877
Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarMitsuru Oshima (OOO 8/5,6) <oshima@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684397}
parent e05214e7
...@@ -51,9 +51,10 @@ void EncodeScreenshotAndRunCallback( ...@@ -51,9 +51,10 @@ void EncodeScreenshotAndRunCallback(
mojom::AssistantScreenContextController::RequestScreenshotCallback callback, mojom::AssistantScreenContextController::RequestScreenshotCallback callback,
std::unique_ptr<ui::LayerTreeOwner> layer_owner, std::unique_ptr<ui::LayerTreeOwner> layer_owner,
gfx::Image image) { gfx::Image image) {
base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskAndReplyWithResult(
FROM_HERE, FROM_HERE,
base::TaskTraits{base::MayBlock(), base::TaskPriority::USER_BLOCKING}, base::TaskTraits{base::ThreadPool(), base::MayBlock(),
base::TaskPriority::USER_BLOCKING},
base::BindOnce(&DownsampleAndEncodeImage, std::move(image)), base::BindOnce(&DownsampleAndEncodeImage, std::move(image)),
std::move(callback)); std::move(callback));
} }
......
...@@ -64,8 +64,8 @@ CursorView::CursorView(aura::Window* container, ...@@ -64,8 +64,8 @@ CursorView::CursorView(aura::Window* container,
base::Unretained(this))), base::Unretained(this))),
is_motion_blur_enabled_(is_motion_blur_enabled), is_motion_blur_enabled_(is_motion_blur_enabled),
ui_task_runner_(base::ThreadTaskRunnerHandle::Get()), ui_task_runner_(base::ThreadTaskRunnerHandle::Get()),
paint_task_runner_(base::CreateSingleThreadTaskRunnerWithTraits( paint_task_runner_(base::CreateSingleThreadTaskRunner(
{base::TaskPriority::USER_BLOCKING, {base::ThreadPool(), base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})),
new_location_(initial_location), new_location_(initial_location),
stationary_timer_( stationary_timer_(
......
...@@ -196,8 +196,9 @@ DisplayColorManager::DisplayColorManager( ...@@ -196,8 +196,9 @@ DisplayColorManager::DisplayColorManager(
display::Screen* screen_to_observe) display::Screen* screen_to_observe)
: configurator_(configurator), : configurator_(configurator),
matrix_buffer_(9, 0.0f), // 3x3 matrix. matrix_buffer_(9, 0.0f), // 3x3 matrix.
sequenced_task_runner_(base::CreateSequencedTaskRunnerWithTraits( sequenced_task_runner_(base::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE, {base::ThreadPool(), base::MayBlock(),
base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})),
displays_ctm_support_(DisplayCtmSupport::kNone), displays_ctm_support_(DisplayCtmSupport::kNone),
screen_to_observe_(screen_to_observe), screen_to_observe_(screen_to_observe),
......
...@@ -570,8 +570,9 @@ Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate, ...@@ -570,8 +570,9 @@ Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
ui::EventHandler::DisableCheckTargets(); ui::EventHandler::DisableCheckTargets();
AccelerometerReader::GetInstance()->Initialize( AccelerometerReader::GetInstance()->Initialize(
base::CreateSequencedTaskRunnerWithTraits( base::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::BEST_EFFORT, {base::ThreadPool(), base::MayBlock(),
base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})); base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}));
login_screen_controller_ = login_screen_controller_ =
......
...@@ -83,8 +83,8 @@ class AshContentTest::Tracer { ...@@ -83,8 +83,8 @@ class AshContentTest::Tracer {
// TODO(oshima): Figure out how interactive_ui_tests allows IO operation // TODO(oshima): Figure out how interactive_ui_tests allows IO operation
// in teardown. // in teardown.
base::RunLoop runloop; base::RunLoop runloop;
base::PostTaskWithTraitsAndReply( base::PostTaskAndReply(
FROM_HERE, {base::MayBlock()}, FROM_HERE, {base::ThreadPool(), base::MayBlock()},
base::BindOnce(&Tracer::CreateTmp, base::Unretained(this)), base::BindOnce(&Tracer::CreateTmp, base::Unretained(this)),
runloop.QuitClosure()); runloop.QuitClosure());
runloop.Run(); runloop.Run();
......
...@@ -470,8 +470,9 @@ const char WallpaperControllerImpl::kOriginalWallpaperSubDir[] = "original"; ...@@ -470,8 +470,9 @@ const char WallpaperControllerImpl::kOriginalWallpaperSubDir[] = "original";
WallpaperControllerImpl::WallpaperControllerImpl(PrefService* local_state) WallpaperControllerImpl::WallpaperControllerImpl(PrefService* local_state)
: color_profiles_(GetProminentColorProfiles()), : color_profiles_(GetProminentColorProfiles()),
wallpaper_reload_delay_(kWallpaperReloadDelay), wallpaper_reload_delay_(kWallpaperReloadDelay),
sequenced_task_runner_(base::CreateSequencedTaskRunnerWithTraits( sequenced_task_runner_(base::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE, {base::ThreadPool(), base::MayBlock(),
base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN})), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN})),
local_state_(local_state) { local_state_(local_state) {
DCHECK(!g_instance_); DCHECK(!g_instance_);
...@@ -1521,9 +1522,9 @@ void WallpaperControllerImpl::RemoveUserWallpaperImpl( ...@@ -1521,9 +1522,9 @@ void WallpaperControllerImpl::RemoveUserWallpaperImpl(
wallpaper_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir); wallpaper_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir);
files_to_remove.push_back(wallpaper_path.Append(wallpaper_files_id)); files_to_remove.push_back(wallpaper_path.Append(wallpaper_files_id));
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, FROM_HERE,
{base::MayBlock(), base::TaskPriority::BEST_EFFORT, {base::ThreadPool(), base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
base::BindOnce(&DeleteWallpaperInList, std::move(files_to_remove))); base::BindOnce(&DeleteWallpaperInList, std::move(files_to_remove)));
} }
...@@ -1831,8 +1832,9 @@ void WallpaperControllerImpl::SaveAndSetWallpaper( ...@@ -1831,8 +1832,9 @@ void WallpaperControllerImpl::SaveAndSetWallpaper(
// Block shutdown on this task. Otherwise, we may lose the custom wallpaper // Block shutdown on this task. Otherwise, we may lose the custom wallpaper
// that the user selected. // that the user selected.
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = scoped_refptr<base::SequencedTaskRunner> blocking_task_runner =
base::CreateSequencedTaskRunnerWithTraits( base::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::USER_BLOCKING, {base::ThreadPool(), base::MayBlock(),
base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN}); base::TaskShutdownBehavior::BLOCK_SHUTDOWN});
blocking_task_runner->PostTask( blocking_task_runner->PostTask(
FROM_HERE, base::BindOnce(&SaveCustomWallpaper, wallpaper_files_id, FROM_HERE, base::BindOnce(&SaveCustomWallpaper, wallpaper_files_id,
......
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