chrome: 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.
[email protected]
Bug: 968047
Change-Id: I87eaadb182875ed512ed3527a506aad45a881be6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1728663
Auto-Submit: Sami Kyöstilä <[email protected]>
Reviewed-by: Lei Zhang <[email protected]>
Commit-Queue: Lei Zhang <[email protected]>
Cr-Commit-Position: refs/heads/master@{#682846}
diff --git a/chrome/browser/pepper_flash_settings_manager.cc b/chrome/browser/pepper_flash_settings_manager.cc
index 74a3682..a3b6139 100644
--- a/chrome/browser/pepper_flash_settings_manager.cc
+++ b/chrome/browser/pepper_flash_settings_manager.cc
@@ -227,8 +227,8 @@
void PepperFlashSettingsManager::Core::Initialize() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- base::PostTaskWithTraits(FROM_HERE, {BrowserThread::IO},
- base::BindOnce(&Core::InitializeOnIOThread, this));
+ base::PostTask(FROM_HERE, {BrowserThread::IO},
+ base::BindOnce(&Core::InitializeOnIOThread, this));
}
void PepperFlashSettingsManager::Core::Detach() {
@@ -239,18 +239,17 @@
// UI thread (which posts a task to delete this object on the I/O thread)
// while the I/O thread doesn't know about it, methods on the I/O thread might
// increase the ref count again and cause double deletion.
- base::PostTaskWithTraits(FROM_HERE, {BrowserThread::IO},
- base::BindOnce(&Core::DetachOnIOThread, this));
+ base::PostTask(FROM_HERE, {BrowserThread::IO},
+ base::BindOnce(&Core::DetachOnIOThread, this));
}
void PepperFlashSettingsManager::Core::DeauthorizeContentLicenses(
uint32_t request_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- base::PostTaskWithTraits(
- FROM_HERE, {BrowserThread::IO},
- base::BindOnce(&Core::DeauthorizeContentLicensesOnIOThread, this,
- request_id));
+ base::PostTask(FROM_HERE, {BrowserThread::IO},
+ base::BindOnce(&Core::DeauthorizeContentLicensesOnIOThread,
+ this, request_id));
}
void PepperFlashSettingsManager::Core::GetPermissionSettings(
@@ -258,10 +257,9 @@
PP_Flash_BrowserOperations_SettingType setting_type) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- base::PostTaskWithTraits(
- FROM_HERE, {BrowserThread::IO},
- base::BindOnce(&Core::GetPermissionSettingsOnIOThread, this, request_id,
- setting_type));
+ base::PostTask(FROM_HERE, {BrowserThread::IO},
+ base::BindOnce(&Core::GetPermissionSettingsOnIOThread, this,
+ request_id, setting_type));
}
void PepperFlashSettingsManager::Core::SetDefaultPermission(
@@ -271,7 +269,7 @@
bool clear_site_specific) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- base::PostTaskWithTraits(
+ base::PostTask(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&Core::SetDefaultPermissionOnIOThread, this, request_id,
setting_type, permission, clear_site_specific));
@@ -283,16 +281,15 @@
const ppapi::FlashSiteSettings& sites) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- base::PostTaskWithTraits(
- FROM_HERE, {BrowserThread::IO},
- base::BindOnce(&Core::SetSitePermissionOnIOThread, this, request_id,
- setting_type, sites));
+ base::PostTask(FROM_HERE, {BrowserThread::IO},
+ base::BindOnce(&Core::SetSitePermissionOnIOThread, this,
+ request_id, setting_type, sites));
}
void PepperFlashSettingsManager::Core::GetSitesWithData(uint32_t request_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- base::PostTaskWithTraits(
+ base::PostTask(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&Core::GetSitesWithDataOnIOThread, this, request_id));
}
@@ -303,9 +300,9 @@
uint64_t max_age) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- base::PostTaskWithTraits(FROM_HERE, {BrowserThread::IO},
- base::BindOnce(&Core::ClearSiteDataOnIOThread, this,
- request_id, site, flags, max_age));
+ base::PostTask(FROM_HERE, {BrowserThread::IO},
+ base::BindOnce(&Core::ClearSiteDataOnIOThread, this,
+ request_id, site, flags, max_age));
}
bool PepperFlashSettingsManager::Core::OnMessageReceived(
@@ -442,8 +439,9 @@
}
#if defined(OS_CHROMEOS)
- base::PostTaskWithTraits(
- FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
+ base::PostTask(
+ FROM_HERE,
+ {base::ThreadPool(), base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(&Core::DeauthorizeContentLicensesAsync, this, request_id,
browser_context_path_));
#else
@@ -463,10 +461,9 @@
DeviceIDFetcher::GetLegacyDeviceIDPath(profile_path);
bool success = base::DeleteFile(device_id_path, false);
- base::PostTaskWithTraits(
- FROM_HERE, {BrowserThread::IO},
- base::BindOnce(&Core::DeauthorizeContentLicensesInPlugin, this,
- request_id, success));
+ base::PostTask(FROM_HERE, {BrowserThread::IO},
+ base::BindOnce(&Core::DeauthorizeContentLicensesInPlugin, this,
+ request_id, success));
}
void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesInPlugin(
@@ -672,9 +669,8 @@
pending_responses_.end());
pending_responses_.clear();
- base::PostTaskWithTraits(
- FROM_HERE, {BrowserThread::UI},
- base::BindOnce(&Core::NotifyError, this, notifications));
+ base::PostTask(FROM_HERE, {BrowserThread::UI},
+ base::BindOnce(&Core::NotifyError, this, notifications));
}
void PepperFlashSettingsManager::Core::
@@ -804,7 +800,7 @@
DCHECK_EQ(iter->second, DEAUTHORIZE_CONTENT_LICENSES);
pending_responses_.erase(iter);
- base::PostTaskWithTraits(
+ base::PostTask(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&Core::NotifyDeauthorizeContentLicensesCompleted, this,
request_id, success));
@@ -828,7 +824,7 @@
DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS);
pending_responses_.erase(iter);
- base::PostTaskWithTraits(
+ base::PostTask(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&Core::NotifyGetPermissionSettingsCompleted, this,
request_id, success, default_permission, sites));
@@ -850,10 +846,9 @@
DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION);
pending_responses_.erase(iter);
- base::PostTaskWithTraits(
- FROM_HERE, {BrowserThread::UI},
- base::BindOnce(&Core::NotifySetDefaultPermissionCompleted, this,
- request_id, success));
+ base::PostTask(FROM_HERE, {BrowserThread::UI},
+ base::BindOnce(&Core::NotifySetDefaultPermissionCompleted,
+ this, request_id, success));
}
void PepperFlashSettingsManager::Core::OnSetSitePermissionResult(
@@ -872,10 +867,9 @@
DCHECK_EQ(iter->second, SET_SITE_PERMISSION);
pending_responses_.erase(iter);
- base::PostTaskWithTraits(
- FROM_HERE, {BrowserThread::UI},
- base::BindOnce(&Core::NotifySetSitePermissionCompleted, this, request_id,
- success));
+ base::PostTask(FROM_HERE, {BrowserThread::UI},
+ base::BindOnce(&Core::NotifySetSitePermissionCompleted, this,
+ request_id, success));
}
void PepperFlashSettingsManager::Core::OnGetSitesWithDataResult(
@@ -892,10 +886,9 @@
DCHECK_EQ(iter->second, GET_SITES_WITH_DATA);
pending_responses_.erase(iter);
- base::PostTaskWithTraits(
- FROM_HERE, {BrowserThread::UI},
- base::BindOnce(&Core::NotifyGetSitesWithDataCompleted, this, request_id,
- sites));
+ base::PostTask(FROM_HERE, {BrowserThread::UI},
+ base::BindOnce(&Core::NotifyGetSitesWithDataCompleted, this,
+ request_id, sites));
}
void PepperFlashSettingsManager::Core::OnClearSiteDataResult(
@@ -914,9 +907,9 @@
DCHECK_EQ(iter->second, CLEAR_SITE_DATA);
pending_responses_.erase(iter);
- base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
- base::BindOnce(&Core::NotifyClearSiteDataCompleted,
- this, request_id, success));
+ base::PostTask(FROM_HERE, {BrowserThread::UI},
+ base::BindOnce(&Core::NotifyClearSiteDataCompleted, this,
+ request_id, success));
}
PepperFlashSettingsManager::PepperFlashSettingsManager(