Hello all,
tl;dr; you should now prefer SequencedTaskRunners obtained from base/task_scheduler/post_task.h to run tasks off the UI/IO threads in a thread-safe fashion.
Chromium has evolved from an initial dedicated thread (BrowserThread::FILE, etc.). As such our codebase has many single-thread constructs (SingleThreadTaskRunner, ThreadTaskRunnerHandle, ThreadChecker, etc.) in classes that are merely thread-unsafe but not thread-affine per se.
SequencedTaskRunners provide thread-safety as well and are much prefered to SingleThreadTaskRunners as they provide more flexibility for scheduling.
We just made a
scripted pass over the codebase to migrate away from base::NonThreadSafe (gone gone!) to SequenceChecker. It turned out that < 5% of the code truly needed thread-affinity (ThreadChecker).
As you start using SequencedTaskRunner, either in new components or replacing existing SingleThreadTaskRunners, if you run into DCHECKs in any leaf dependency (outside of your component) per it using ThreadChecker/ThreadTaskRunnerHandle/etc. : you may ideally fix those components (they're not typically thread-affine unless using TLS or third-party APIs that are affine) or, alternatively, you can temporarily use base::CreateSingleThreadTaskRunnerWithTraits(...) with a TODO tagged with a bug # marked as a blocker for
https://crbug.com/675631 (one of us will take a look at it and flip your code to use a SequencedTaskRunner when fixed).
PS: We automated much of the migration to TaskScheduler away from old APIs but are getting to the harder cases (requiring manual steps). We will soon reach out to individual owners with precise migration docs to complete this on a component-by-component basis.
Thanks!
Gab on behalf of the TaskScheduler team.