Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Unified Diff: base/test/scoped_async_task_scheduler.h

Issue 2622633004: Add base::test::ScopedAsyncTaskScheduler. (Closed)
Patch Set: CR gab #11 (grammar) Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/test/BUILD.gn ('k') | base/test/scoped_async_task_scheduler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..66757d3a7c70c165d474ec944ca8e425d05663aa
--- /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 makes tests
+// easier 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_
« no previous file with comments | « base/test/BUILD.gn ('k') | base/test/scoped_async_task_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698