Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_ | 5 #ifndef BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_ |
| 6 #define BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_ | 6 #define BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_ |
| 7 | 7 |
| 8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 // Returns true if the SingleThreadTaskRunner is already created for | 25 // Returns true if the SingleThreadTaskRunner is already created for |
| 26 // the current thread. | 26 // the current thread. |
| 27 static bool IsSet(); | 27 static bool IsSet(); |
| 28 | 28 |
| 29 // Binds |task_runner| to the current thread. |task_runner| must belong | 29 // Binds |task_runner| to the current thread. |task_runner| must belong |
| 30 // to the current thread for this to succeed. | 30 // to the current thread for this to succeed. |
| 31 explicit ThreadTaskRunnerHandle( | 31 explicit ThreadTaskRunnerHandle( |
| 32 scoped_refptr<SingleThreadTaskRunner> task_runner); | 32 scoped_refptr<SingleThreadTaskRunner> task_runner); |
| 33 ~ThreadTaskRunnerHandle(); | 33 ~ThreadTaskRunnerHandle(); |
| 34 | 34 |
| 35 // A ThreadTaskRunnerHandle::NestedForTesting is the same thing as a | |
| 36 // ThreadTaskRunnerHandle except that it allows overriding an existing | |
| 37 // ThreadTaskRunnerHandle in its scope. Nesting ThreadTaskRunnerHandles isn't | |
| 38 // generally desired but it can be useful in unit tests where multiple task | |
| 39 // runners are sharing the main thread for simplicity and determinism. | |
| 40 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
| |
| 41 public: | |
| 42 explicit NestedForTesting( | |
| 43 scoped_refptr<SingleThreadTaskRunner> task_runner); | |
| 44 ~NestedForTesting(); | |
| 45 | |
| 46 private: | |
| 47 friend class ThreadTaskRunnerHandle; | |
| 48 | |
| 49 scoped_refptr<SingleThreadTaskRunner> task_runner_; | |
| 50 const NestedForTesting* const previous_handle_; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(NestedForTesting); | |
| 53 }; | |
| 54 | |
| 35 private: | 55 private: |
| 36 scoped_refptr<SingleThreadTaskRunner> task_runner_; | 56 // The impl uses NestedForTesting to avoid code duplication but this is the |
| 57 // only allowed non-test usage. | |
| 58 std::unique_ptr<NestedForTesting> handle_; | |
| 37 | 59 |
| 38 DISALLOW_COPY_AND_ASSIGN(ThreadTaskRunnerHandle); | 60 DISALLOW_COPY_AND_ASSIGN(ThreadTaskRunnerHandle); |
| 39 }; | 61 }; |
| 40 | 62 |
| 41 } // namespace base | 63 } // namespace base |
| 42 | 64 |
| 43 #endif // BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_ | 65 #endif // BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_ |
| OLD | NEW |