docs: Update threading_and_tasks.md for BrowserThread task traits.
Bug: 878356, 867421
Change-Id: I0991a840a0787b6863bea79ee4079e5db7fdfe0b
Reviewed-on: https://chromium-review.googlesource.com/1194074
Commit-Queue: Eric Seckler <[email protected]>
Reviewed-by: Sami Kyöstilä <[email protected]>
Reviewed-by: François Doray <[email protected]>
Reviewed-by: Gabriel Charette <[email protected]>
Cr-Commit-Position: refs/heads/master@{#587525}
diff --git a/docs/threading_and_tasks.md b/docs/threading_and_tasks.md
index 9ccf60f..86cc50c 100644
--- a/docs/threading_and_tasks.md
+++ b/docs/threading_and_tasks.md
@@ -254,14 +254,16 @@
### Posting to the Main Thread or to the IO Thread in the Browser Process
-To post tasks to the main thread or to the IO thread, get the appropriate
-SingleThreadTaskRunner using `content::BrowserThread::GetTaskRunnerForThread`.
+To post tasks to the main thread or to the IO thread, use
+`base::PostTaskWithTraits()` or get the appropriate SingleThreadTaskRunner using
+`base::CreateSingleThreadTaskRunnerWithTraits`, supplying a `BrowserThread::ID`
+as trait. For this, you'll also need to include
+[`content/public/browser/browser_task_traits.h`](https://cs.chromium.org/chromium/src/content/public/browser/browser_task_traits.h).
```cpp
-content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::UI)
- ->PostTask(FROM_HERE, ...);
+base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI}, ...);
-content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::IO)
+base::CreateSingleThreadTaskRunnerWithTraits({content::BrowserThread::IO})
->PostTask(FROM_HERE, ...);
```
@@ -374,8 +376,12 @@
Tasks that don’t match this description must be posted with explicit TaskTraits.
[`base/task/task_traits.h`](https://cs.chromium.org/chromium/src/base/task/task_traits.h)
-provides exhaustive documentation of available traits. Below are some examples
-of how to specify `TaskTraits`.
+provides exhaustive documentation of available traits. The content layer also
+provides additional traits in
+[`content/public/browser/browser_task_traits.h`](https://cs.chromium.org/chromium/src/content/public/browser/browser_task_traits.h)
+to facilitate posting a task onto a BrowserThread.
+
+Below are some examples of how to specify `TaskTraits`.
```cpp
// This task has no explicit TaskTraits. It cannot block. Its priority
@@ -401,6 +407,11 @@
base::PostTaskWithTraits(
FROM_HERE, {base::TaskShutdownBehavior::BLOCK_SHUTDOWN},
base::BindOnce(...));
+
+// This task will run on the Browser UI thread.
+base::PostTaskWithTraits(
+ FROM_HERE, {content::BrowserThread::UI},
+ base::BindOnce(...));
```
## Keeping the Browser Responsive