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( ...@@ -350,9 +350,8 @@ NotificationDatabase::Status NotificationDatabase::DeleteNotificationData(
NotificationDatabaseData data; NotificationDatabaseData data;
Status status = ReadNotificationData(notification_id, origin, &data); Status status = ReadNotificationData(notification_id, origin, &data);
if (status == STATUS_OK && record_notification_to_ukm_callback_) { if (status == STATUS_OK && record_notification_to_ukm_callback_) {
base::PostTaskWithTraits( base::PostTask(FROM_HERE, {BrowserThread::UI},
FROM_HERE, {BrowserThread::UI}, base::BindOnce(record_notification_to_ukm_callback_, data));
base::BindOnce(record_notification_to_ukm_callback_, data));
} }
leveldb::WriteBatch batch; leveldb::WriteBatch batch;
...@@ -507,10 +506,9 @@ NotificationDatabase::DeleteAllNotificationDataInternal( ...@@ -507,10 +506,9 @@ NotificationDatabase::DeleteAllNotificationDataInternal(
} }
if (record_notification_to_ukm_callback_) { if (record_notification_to_ukm_callback_) {
base::PostTaskWithTraits( base::PostTask(FROM_HERE, {BrowserThread::UI},
FROM_HERE, {BrowserThread::UI}, base::BindOnce(record_notification_to_ukm_callback_,
base::BindOnce(record_notification_to_ukm_callback_, notification_database_data));
notification_database_data));
} }
std::string notification_id = notification_database_data.notification_id; std::string notification_id = notification_database_data.notification_id;
......
...@@ -87,7 +87,7 @@ void ServiceWorkerNotificationEventFinished( ...@@ -87,7 +87,7 @@ void ServiceWorkerNotificationEventFinished(
NotificationDispatchCompleteCallback dispatch_complete_callback, NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode service_worker_status) { blink::ServiceWorkerStatusCode service_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, {BrowserThread::UI},
base::BindOnce(std::move(dispatch_complete_callback), base::BindOnce(std::move(dispatch_complete_callback),
ConvertServiceWorkerStatus(service_worker_status))); ConvertServiceWorkerStatus(service_worker_status)));
...@@ -149,9 +149,8 @@ void DispatchNotificationEventOnRegistration( ...@@ -149,9 +149,8 @@ void DispatchNotificationEventOnRegistration(
break; break;
} }
base::PostTaskWithTraits( base::PostTask(FROM_HERE, {BrowserThread::UI},
FROM_HERE, {BrowserThread::UI}, base::BindOnce(std::move(dispatch_complete_callback), status));
base::BindOnce(std::move(dispatch_complete_callback), status));
} }
// Finds the ServiceWorkerRegistration associated with the |origin| and // Finds the ServiceWorkerRegistration associated with the |origin| and
...@@ -176,7 +175,7 @@ void FindServiceWorkerRegistration( ...@@ -176,7 +175,7 @@ void FindServiceWorkerRegistration(
return; return;
} }
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&ServiceWorkerContextWrapper::FindReadyRegistrationForId, base::BindOnce(&ServiceWorkerContextWrapper::FindReadyRegistrationForId,
service_worker_context, service_worker_context,
...@@ -248,7 +247,7 @@ void DoDispatchNotificationClickEvent( ...@@ -248,7 +247,7 @@ void DoDispatchNotificationClickEvent(
NotificationDispatchCompleteCallback dispatch_complete_callback) { NotificationDispatchCompleteCallback dispatch_complete_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, {BrowserThread::UI},
base::BindOnce(&notifications::LogNotificationClickedEventToDevTools, base::BindOnce(&notifications::LogNotificationClickedEventToDevTools,
browser_context, notification_database_data, action_index, browser_context, notification_database_data, action_index,
...@@ -290,7 +289,7 @@ void DeleteNotificationDataFromDatabase( ...@@ -290,7 +289,7 @@ void DeleteNotificationDataFromDatabase(
NotificationDispatchCompleteCallback dispatch_complete_callback, NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode status_code) { blink::ServiceWorkerStatusCode status_code) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, {BrowserThread::UI},
base::BindOnce( base::BindOnce(
&PlatformNotificationContext::DeleteNotificationData, &PlatformNotificationContext::DeleteNotificationData,
......
...@@ -63,16 +63,16 @@ void PlatformNotificationServiceProxy::VerifyServiceWorkerScope( ...@@ -63,16 +63,16 @@ void PlatformNotificationServiceProxy::VerifyServiceWorkerScope(
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (status == blink::ServiceWorkerStatusCode::kOk && if (status == blink::ServiceWorkerStatusCode::kOk &&
registration->scope().GetOrigin() == data.origin) { registration->scope().GetOrigin() == data.origin) {
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE}, FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&PlatformNotificationServiceProxy::DoDisplayNotification, base::BindOnce(&PlatformNotificationServiceProxy::DoDisplayNotification,
AsWeakPtr(), data, registration->scope(), AsWeakPtr(), data, registration->scope(),
std::move(callback))); std::move(callback)));
} else { } else {
base::PostTaskWithTraits( base::PostTask(FROM_HERE,
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE}, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(std::move(callback), /* success= */ false, base::BindOnce(std::move(callback), /* success= */ false,
/* notification_id= */ "")); /* notification_id= */ ""));
} }
} }
...@@ -80,14 +80,14 @@ void PlatformNotificationServiceProxy::DisplayNotification( ...@@ -80,14 +80,14 @@ void PlatformNotificationServiceProxy::DisplayNotification(
const NotificationDatabaseData& data, const NotificationDatabaseData& data,
DisplayResultCallback callback) { DisplayResultCallback callback) {
if (!service_worker_context_) { if (!service_worker_context_) {
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE}, FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&PlatformNotificationServiceProxy::DoDisplayNotification, base::BindOnce(&PlatformNotificationServiceProxy::DoDisplayNotification,
AsWeakPtr(), data, GURL(), std::move(callback))); AsWeakPtr(), data, GURL(), std::move(callback)));
return; return;
} }
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {BrowserThread::IO, base::TaskPriority::USER_VISIBLE}, FROM_HERE, {BrowserThread::IO, base::TaskPriority::USER_VISIBLE},
base::BindOnce( base::BindOnce(
&ServiceWorkerContextWrapper::FindReadyRegistrationForId, &ServiceWorkerContextWrapper::FindReadyRegistrationForId,
...@@ -102,7 +102,7 @@ void PlatformNotificationServiceProxy::CloseNotification( ...@@ -102,7 +102,7 @@ void PlatformNotificationServiceProxy::CloseNotification(
const std::string& notification_id) { const std::string& notification_id) {
if (!notification_service_) if (!notification_service_)
return; return;
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE}, FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&PlatformNotificationServiceProxy::DoCloseNotification, base::BindOnce(&PlatformNotificationServiceProxy::DoCloseNotification,
AsWeakPtr(), notification_id)); AsWeakPtr(), notification_id));
...@@ -117,7 +117,7 @@ void PlatformNotificationServiceProxy::DoCloseNotification( ...@@ -117,7 +117,7 @@ void PlatformNotificationServiceProxy::DoCloseNotification(
void PlatformNotificationServiceProxy::ScheduleTrigger(base::Time timestamp) { void PlatformNotificationServiceProxy::ScheduleTrigger(base::Time timestamp) {
if (!notification_service_) if (!notification_service_)
return; return;
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE}, FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&PlatformNotificationServiceProxy::DoScheduleTrigger, base::BindOnce(&PlatformNotificationServiceProxy::DoScheduleTrigger,
AsWeakPtr(), timestamp)); AsWeakPtr(), timestamp));
...@@ -133,7 +133,7 @@ void PlatformNotificationServiceProxy::ScheduleNotification( ...@@ -133,7 +133,7 @@ void PlatformNotificationServiceProxy::ScheduleNotification(
DCHECK(data.notification_data.show_trigger_timestamp.has_value()); DCHECK(data.notification_data.show_trigger_timestamp.has_value());
if (!notification_service_) if (!notification_service_)
return; return;
base::PostTaskWithTraits( base::PostTask(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE}, FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&PlatformNotificationServiceProxy::DoScheduleNotification, base::BindOnce(&PlatformNotificationServiceProxy::DoScheduleNotification,
AsWeakPtr(), data)); AsWeakPtr(), data));
...@@ -172,10 +172,10 @@ bool PlatformNotificationServiceProxy::ShouldLogClose(const GURL& origin) { ...@@ -172,10 +172,10 @@ bool PlatformNotificationServiceProxy::ShouldLogClose(const GURL& origin) {
void PlatformNotificationServiceProxy::LogClose( void PlatformNotificationServiceProxy::LogClose(
const NotificationDatabaseData& data) { const NotificationDatabaseData& data) {
base::PostTaskWithTraits( base::PostTask(FROM_HERE,
FROM_HERE, {BrowserThread::UI, base::TaskPriority::BEST_EFFORT}, {BrowserThread::UI, base::TaskPriority::BEST_EFFORT},
base::BindOnce(&PlatformNotificationServiceProxy::DoLogClose, AsWeakPtr(), base::BindOnce(&PlatformNotificationServiceProxy::DoLogClose,
data)); AsWeakPtr(), data));
} }
void PlatformNotificationServiceProxy::DoLogClose( 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