Chromium Code Reviews| Index: base/threading/thread_task_runner_handle.h |
| diff --git a/base/threading/thread_task_runner_handle.h b/base/threading/thread_task_runner_handle.h |
| index c8e58935f0977259349857bf91d71c63bf734567..8baf4544c9ed31e83ef2870c3364603d5f79b506 100644 |
| --- a/base/threading/thread_task_runner_handle.h |
| +++ b/base/threading/thread_task_runner_handle.h |
| @@ -32,8 +32,30 @@ class BASE_EXPORT ThreadTaskRunnerHandle { |
| scoped_refptr<SingleThreadTaskRunner> task_runner); |
| ~ThreadTaskRunnerHandle(); |
| + // A ThreadTaskRunnerHandle::NestedForTesting is the same thing as a |
| + // ThreadTaskRunnerHandle except that it allows overriding an existing |
| + // ThreadTaskRunnerHandle in its scope. Nesting ThreadTaskRunnerHandles isn't |
| + // generally desired but it can be useful in unit tests where multiple task |
| + // runners are sharing the main thread for simplicity and determinism. |
| + class BASE_EXPORT NestedForTesting { |
|
danakj
2017/02/16 17:57:24
Proposal to make the changes less invasive.
1) Ov
gab
2017/02/16 21:03:36
That's what I wanted to do at first, but then hit
|
| + public: |
| + explicit NestedForTesting( |
| + scoped_refptr<SingleThreadTaskRunner> task_runner); |
| + ~NestedForTesting(); |
| + |
| + private: |
| + friend class ThreadTaskRunnerHandle; |
| + |
| + scoped_refptr<SingleThreadTaskRunner> task_runner_; |
| + const NestedForTesting* const previous_handle_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NestedForTesting); |
| + }; |
| + |
| private: |
| - scoped_refptr<SingleThreadTaskRunner> task_runner_; |
| + // The impl uses NestedForTesting to avoid code duplication but this is the |
| + // only allowed non-test usage. |
| + std::unique_ptr<NestedForTesting> handle_; |
| DISALLOW_COPY_AND_ASSIGN(ThreadTaskRunnerHandle); |
| }; |