OLD | NEW |
1 # Threading and Tasks in Chrome | 1 # Threading and Tasks in Chrome |
2 | 2 |
3 [TOC] | 3 [TOC] |
4 | 4 |
5 ## Overview | 5 ## Overview |
6 | 6 |
7 ### Threads | 7 ### Threads |
8 | 8 |
9 Every Chrome process has | 9 Every Chrome process has |
10 | 10 |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 | 649 |
650 Dependency injection of TaskRunners can still seldomly be useful to unit test a | 650 Dependency injection of TaskRunners can still seldomly be useful to unit test a |
651 component when triggering a specific race in a specific way is essential to the | 651 component when triggering a specific race in a specific way is essential to the |
652 test. For such cases the preferred approach is the following: | 652 test. For such cases the preferred approach is the following: |
653 | 653 |
654 ```cpp | 654 ```cpp |
655 class FooWithCustomizableTaskRunnerForTesting { | 655 class FooWithCustomizableTaskRunnerForTesting { |
656 public: | 656 public: |
657 | 657 |
658 void SetBackgroundTaskRunnerForTesting( | 658 void SetBackgroundTaskRunnerForTesting( |
659 scoped_refptr<base::SequenceTaskRunner> background_task_runner); | 659 scoped_refptr<base::SequencedTaskRunner> background_task_runner); |
660 | 660 |
661 private: | 661 private: |
662 scoped_refptr<base::SequenceTaskRunner> background_task_runner_ = | 662 scoped_refptr<base::SequencedTaskRunner> background_task_runner_ = |
663 base::CreateSequenceTaskRunnerWithTraits( | 663 base::CreateSequencedTaskRunnerWithTraits( |
664 {base::MayBlock(), base::TaskPriority::BACKGROUND}); | 664 {base::MayBlock(), base::TaskPriority::BACKGROUND}); |
665 } | 665 } |
666 ``` | 666 ``` |
667 | 667 |
668 Note that this still allows removing all layers of plumbing between //chrome and | 668 Note that this still allows removing all layers of plumbing between //chrome and |
669 that component since unit tests will use the leaf layer directly. | 669 that component since unit tests will use the leaf layer directly. |
OLD | NEW |