Chromium Code Reviews| Index: base/test/scoped_task_scheduler.h |
| diff --git a/base/test/scoped_task_scheduler.h b/base/test/scoped_task_scheduler.h |
| index f2b252b601f81d83df4baab85d62375b908ffa80..2e6e39e624b3d2c48fbc28ec83e81fff51e9ee67 100644 |
| --- a/base/test/scoped_task_scheduler.h |
| +++ b/base/test/scoped_task_scheduler.h |
| @@ -6,6 +6,7 @@ |
| #define BASE_TEST_SCOPED_TASK_SCHEDULER_H_ |
| #include "base/macros.h" |
| +#include "base/threading/thread_checker.h" |
| namespace base { |
| @@ -13,24 +14,49 @@ class TaskScheduler; |
| namespace test { |
| -// Initializes a TaskScheduler and allows usage of the |
| -// base/task_scheduler/post_task.h API within its scope. |
| +// Allows usage of the base/task_scheduler/post_task.h API within its scope. |
| +// |
| +// To run pending tasks synchronously, call RunLoop::Run/RunUntilIdle() on the |
| +// thread where the ScopedTaskScheduler lives. The destructor of runs remaining |
|
gab
2016/12/08 20:15:45
rm "of"
fdoray
2016/12/09 16:26:41
Done.
|
| +// BLOCK_SHUTDOWN tasks synchronously. |
| +// |
| +// Example usage: |
| +// |
| +// base::test::ScopedTaskScheduler scoped_task_scheduler; |
|
robliao
2016/12/09 01:32:54
Nit: It might be clearer to have a leading section
fdoray
2016/12/09 16:26:41
Done.
|
| +// base::PostTask(FROM_HERE, base::Bind(&A)); |
| +// base::RunLoop::RunUntilIdle(); // Returns after running A. |
| +// |
| +// base::RunLoop run_loop; |
| +// base::PostTask(FROM_HERE, base::Bind(&B)); |
| +// base::PostTask(FROM_HERE, base::Bind(&RunLoop::Quit, &run_loop)); |
| +// base::PostTask(FROM_HERE, base::Bind(&C)); |
| +// base::PostTaskWithTraits( |
| +// base::TaskTraits().WithShutdownBehavior( |
| +// base::TaskShutdownBehavior::BLOCK_SHUTDOWN), |
| +// base::Bind(&D)); |
| +// run_loop.Run(); // Returns after running B and RunLoop::Quit. |
| +// |
| +// D runs at the end of this scope because it is BLOCK_SHUTDOWN. |
| class ScopedTaskScheduler { |
| public: |
| - // Initializes a TaskScheduler with default arguments. |
| + enum Options { |
| + DEFAULT = 0x0, |
|
robliao
2016/12/09 01:32:54
Is this going to be a future set of flags? If not,
fdoray
2016/12/09 16:26:41
Removed.
|
| + |
| + // Run TaskScheduler on a MessageLoopForUI instead of a MessageLoopForIO. |
| + // TaskScheduler tasks can't use FileDescriptorWatcher with this option. |
| + UI_MAIN_LOOP = 0x1, |
| + }; |
| + |
| + // Registers a TaskScheduler. |
| ScopedTaskScheduler(); |
| + ScopedTaskScheduler(Options options); |
| - // Waits until all TaskScheduler tasks blocking shutdown complete their |
| - // execution (see TaskShutdownBehavior). Then, joins all TaskScheduler threads |
| - // and deletes the TaskScheduler. |
| - // |
| - // Note that joining TaskScheduler threads may involve waiting for |
| - // CONTINUE_ON_SHUTDOWN tasks to complete their execution. Normally, in |
| - // production, the process exits without joining TaskScheduler threads. |
| + // Runs all pending BLOCK_SHUTDOWN tasks and unregisters the TaskScheduler. |
| ~ScopedTaskScheduler(); |
| private: |
| const TaskScheduler* task_scheduler_ = nullptr; |
| + ThreadChecker thread_checker_; |
| DISALLOW_COPY_AND_ASSIGN(ScopedTaskScheduler); |
| }; |