PSA: Task posting to BrowserThreads is changing

61 views
Skip to first unread message

Eric Seckler

unread,
Aug 29, 2018, 10:21:47 AM8/29/18
to Chromium-dev, scheduler-dev
TL;DR: We are replacing BrowserThread::PostTask*/GetTaskRunnerForThread() with base::PostTaskWithTraits*/CreateSingleThreadTaskRunnerWithTraits(). Same for ios's WebThread.

To unify the way that tasks are posted in chromium code and pave the way for task scheduling on the UI thread, we are deprecating the static methods to post tasks and obtain task runners on content::BrowserThread and web::WebThread. Instead, we are making it possible to specify a BrowserThread::ID (or WebThread::ID) as part of base::TaskTraits. As of today's patches, tasks for the UI and IO threads can now be posted via the base/task/post_task.h API.

To be precise, were you previously wrote:

   content::BrowserThread::PostTask(
       content::BrowserThread::IO, FROM_HERE, base::BindOnce(..));

   content::BrowserThread::PostDelayedTask(
       content::BrowserThread::UI, FROM_HERE, base::BindOnce(..), delay);

   auto runner = content::BrowserThread::GetTaskRunnerForThread(
       content::BrowserThread::UI);


You can now write:

   #include "base/task/post_task.h"
   #include "content/public/browser/browser_task_traits.h"

   base::PostTaskWithTraits(
       FROM_HERE, {content::BrowserThread::IO}, base::BindOnce(..));

   base::PostDelayedTaskWithTraits(
       FROM_HERE, {content::BrowserThread::UI}, base::BindOnce(..), delay);

   auto runner = base::CreateSingleThreadTaskRunnerWithTraits(
       {content::BrowserThread::UI});


The same goes for WebThread under //ios.

In the coming days, we will mass-migrate existing callsites to post_task.h (tracking bug) and eventually remove the old methods from BrowserThread / WebThread. We'll send an update once that happened.
Reply all
Reply to author
Forward
0 new messages