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_ASYNC_TASK_SCHEDULER_H_ |
| 6 #define BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 |
| 10 namespace base { |
| 11 |
| 12 class TaskScheduler; |
| 13 |
| 14 namespace test { |
| 15 |
| 16 // Allows usage of the base/task_scheduler/post_task.h API within its scope. |
| 17 // Tasks run asynchronously, one at a time. |
| 18 // |
| 19 // To wait until all posted tasks have run, use |
| 20 // TaskScheduler::GetInstance()->FlushForTesting(). |
| 21 // |
| 22 // When possible, use ScopedTaskScheduler instead of this. Tasks posted within |
| 23 // the scope of a ScopedTaskScheduler run synchronously, which makes tests |
| 24 // easier to understand. |
| 25 class ScopedAsyncTaskScheduler { |
| 26 public: |
| 27 // Registers a single-threaded TaskScheduler. |
| 28 ScopedAsyncTaskScheduler(); |
| 29 |
| 30 // Shuts down and unregisters the TaskScheduler. |
| 31 ~ScopedAsyncTaskScheduler(); |
| 32 |
| 33 private: |
| 34 const TaskScheduler* task_scheduler_ = nullptr; |
| 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(ScopedAsyncTaskScheduler); |
| 37 }; |
| 38 |
| 39 } // namespace test |
| 40 } // namespace base |
| 41 |
| 42 #endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_ |
OLD | NEW |