Index: base/test/scoped_async_task_scheduler.h |
diff --git a/base/test/scoped_async_task_scheduler.h b/base/test/scoped_async_task_scheduler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c3240c0b7bea4e3e8d6b41911b054c5f40a9520a |
--- /dev/null |
+++ b/base/test/scoped_async_task_scheduler.h |
@@ -0,0 +1,42 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_ |
+#define BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_ |
+ |
+#include "base/macros.h" |
+ |
+namespace base { |
+ |
+class TaskScheduler; |
+ |
+namespace test { |
+ |
+// Allows usage of the base/task_scheduler/post_task.h API within its scope. |
+// Tasks run asynchronously, one at a time. |
+// |
+// To wait until all posted tasks have run, use |
+// TaskScheduler::GetInstance()->FlushForTesting(). |
+// |
+// When possible, use ScopedTaskScheduler instead of this. Tasks posted within |
+// the scope of a ScopedTaskScheduler run synchronously, which make tests easier |
gab
2017/01/09 20:27:11
nit: s/make/makes/
fdoray
2017/01/09 20:28:34
Done.
|
+// to understand. |
+class ScopedAsyncTaskScheduler { |
+ public: |
+ // Registers a single-threaded TaskScheduler. |
+ ScopedAsyncTaskScheduler(); |
+ |
+ // Shuts down and unregisters the TaskScheduler. |
+ ~ScopedAsyncTaskScheduler(); |
+ |
+ private: |
+ const TaskScheduler* task_scheduler_ = nullptr; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ScopedAsyncTaskScheduler); |
+}; |
+ |
+} // namespace test |
+} // namespace base |
+ |
+#endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_ |