Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_ | |
| 6 #define BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/message_loop/message_loop.h" | |
| 10 | |
| 11 namespace base { | |
| 12 | |
| 13 class TaskScheduler; | |
| 14 | |
| 15 namespace test { | |
| 16 | |
| 17 // ScopedTaskEnvironment allows usage of these APIs within its scope: | |
| 18 // - ThreadTaskRunnerHandle, on the thread where it lives | |
|
gab
2017/04/05 20:44:24
(Thread|Sequenced)TaskRunnerHandle
fdoray
2017/04/06 14:00:23
Done.
| |
| 19 // - base/task_scheduler/post_task.h, on any thread | |
| 20 // | |
| 21 // Tests that need either of these APIs should instantiate a | |
| 22 // ScopedTaskEnvironment. | |
| 23 // | |
| 24 // Tasks posted to the ThreadTaskRunnerHandle run synchronously when | |
| 25 // RunLoop::Run(UntilIdle) is called on the thread where the | |
| 26 // ScopedTaskEnvironment lives. | |
| 27 // | |
| 28 // Tasks posted through base/task_scheduler/post_task.h run on dedicated threads | |
| 29 // as they are posted. | |
| 30 // | |
| 31 // Future improvements documented in: | |
|
gab
2017/04/05 20:44:24
// Design and future improvements documented in
fdoray
2017/04/06 14:00:22
Done.
| |
| 32 // https://docs.google.com/document/d/1QabRo8c7D9LsYY3cEcaPQbOCLo8Tu-6VLykYXyl3P kk/edit | |
| 33 class ScopedTaskEnvironment { | |
| 34 public: | |
| 35 ScopedTaskEnvironment(); | |
| 36 | |
| 37 // Runs pending ThreadTaskRunnerHandle tasks and pending BLOCK_SHUTDOWN | |
| 38 // TaskScheduler tasks. Then, unregisters the TaskScheduler and the | |
| 39 // ThreadTaskRunnerHandle. | |
| 40 ~ScopedTaskEnvironment(); | |
| 41 | |
| 42 private: | |
| 43 MessageLoop message_loop_; | |
|
gab
2017/04/05 20:44:24
// Note: |message_loop_| is an implementation deta
fdoray
2017/04/06 14:00:23
Done.
| |
| 44 const TaskScheduler* task_scheduler_ = nullptr; | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(ScopedTaskEnvironment); | |
| 47 }; | |
| 48 | |
| 49 } // namespace test | |
| 50 } // namespace base | |
| 51 | |
| 52 #endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_ | |
| OLD | NEW |