Commit 1c837f08 authored by Sami Kyostila's avatar Sami Kyostila Committed by Commit Bot

content/browser/notifications: 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=knollr@chromium.org

Bug: 968047
Change-Id: I6c06f32b24ff208b5020f45f70b3c09d08fd9881
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1728558
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarRichard Knoll <knollr@chromium.org>
Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682745}
parent addf63d2
......@@ -350,9 +350,8 @@ NotificationDatabase::Status NotificationDatabase::DeleteNotificationData(
NotificationDatabaseData data;
Status status = ReadNotificationData(notification_id, origin, &data);
if (status == STATUS_OK && record_notification_to_ukm_callback_) {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(record_notification_to_ukm_callback_, data));
base::PostTask(FROM_HERE, {BrowserThread::UI},
base::BindOnce(record_notification_to_ukm_callback_, data));
}
leveldb::WriteBatch batch;
......@@ -507,10 +506,9 @@ NotificationDatabase::DeleteAllNotificationDataInternal(
}
if (record_notification_to_ukm_callback_) {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(record_notification_to_ukm_callback_,
notification_database_data));
base::PostTask(FROM_HERE, {BrowserThread::UI},
base::BindOnce(record_notification_to_ukm_callback_,
notification_database_data));
}
std::string notification_id = notification_database_data.notification_id;
......
......@@ -87,7 +87,7 @@ void ServiceWorkerNotificationEventFinished(
NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode service_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTaskWithTraits(
base::PostTask(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(std::move(dispatch_complete_callback),
ConvertServiceWorkerStatus(service_worker_status)));
......@@ -149,9 +149,8 @@ void DispatchNotificationEventOnRegistration(
break;
}
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(std::move(dispatch_complete_callback), status));
base::PostTask(FROM_HERE, {BrowserThread::UI},
base::BindOnce(std::move(dispatch_complete_callback), status));
}
// Finds the ServiceWorkerRegistration associated with the |origin| and
......@@ -176,7 +175,7 @@ void FindServiceWorkerRegistration(
return;
}
base::PostTaskWithTraits(
base::PostTask(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&ServiceWorkerContextWrapper::FindReadyRegistrationForId,
service_worker_context,
......@@ -248,7 +247,7 @@ void DoDispatchNotificationClickEvent(
NotificationDispatchCompleteCallback dispatch_complete_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTaskWithTraits(
base::PostTask(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&notifications::LogNotificationClickedEventToDevTools,
browser_context, notification_database_data, action_index,
......@@ -290,7 +289,7 @@ void DeleteNotificationDataFromDatabase(
NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode status_code) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTaskWithTraits(
base::PostTask(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(
&PlatformNotificationContext::DeleteNotificationData,
......
......@@ -63,16 +63,16 @@ void PlatformNotificationServiceProxy::VerifyServiceWorkerScope(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (status == blink::ServiceWorkerStatusCode::kOk &&
registration->scope().GetOrigin() == data.origin) {
base::PostTaskWithTraits(
base::PostTask(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&PlatformNotificationServiceProxy::DoDisplayNotification,
AsWeakPtr(), data, registration->scope(),
std::move(callback)));
} else {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(std::move(callback), /* success= */ false,
/* notification_id= */ ""));
base::PostTask(FROM_HERE,
{BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(std::move(callback), /* success= */ false,
/* notification_id= */ ""));
}
}
......@@ -80,14 +80,14 @@ void PlatformNotificationServiceProxy::DisplayNotification(
const NotificationDatabaseData& data,
DisplayResultCallback callback) {
if (!service_worker_context_) {
base::PostTaskWithTraits(
base::PostTask(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&PlatformNotificationServiceProxy::DoDisplayNotification,
AsWeakPtr(), data, GURL(), std::move(callback)));
return;
}
base::PostTaskWithTraits(
base::PostTask(
FROM_HERE, {BrowserThread::IO, base::TaskPriority::USER_VISIBLE},
base::BindOnce(
&ServiceWorkerContextWrapper::FindReadyRegistrationForId,
......@@ -102,7 +102,7 @@ void PlatformNotificationServiceProxy::CloseNotification(
const std::string& notification_id) {
if (!notification_service_)
return;
base::PostTaskWithTraits(
base::PostTask(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&PlatformNotificationServiceProxy::DoCloseNotification,
AsWeakPtr(), notification_id));
......@@ -117,7 +117,7 @@ void PlatformNotificationServiceProxy::DoCloseNotification(
void PlatformNotificationServiceProxy::ScheduleTrigger(base::Time timestamp) {
if (!notification_service_)
return;
base::PostTaskWithTraits(
base::PostTask(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&PlatformNotificationServiceProxy::DoScheduleTrigger,
AsWeakPtr(), timestamp));
......@@ -133,7 +133,7 @@ void PlatformNotificationServiceProxy::ScheduleNotification(
DCHECK(data.notification_data.show_trigger_timestamp.has_value());
if (!notification_service_)
return;
base::PostTaskWithTraits(
base::PostTask(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&PlatformNotificationServiceProxy::DoScheduleNotification,
AsWeakPtr(), data));
......@@ -172,10 +172,10 @@ bool PlatformNotificationServiceProxy::ShouldLogClose(const GURL& origin) {
void PlatformNotificationServiceProxy::LogClose(
const NotificationDatabaseData& data) {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::BEST_EFFORT},
base::BindOnce(&PlatformNotificationServiceProxy::DoLogClose, AsWeakPtr(),
data));
base::PostTask(FROM_HERE,
{BrowserThread::UI, base::TaskPriority::BEST_EFFORT},
base::BindOnce(&PlatformNotificationServiceProxy::DoLogClose,
AsWeakPtr(), data));
}
void PlatformNotificationServiceProxy::DoLogClose(
......
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