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

Unified Diff: base/test/scoped_task_environment.h

Issue 2796403002: Add base::test::ScopedTaskEnvironment. (Closed)
Patch Set: CR-gab-9 Created 3 years, 8 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/scoped_async_task_scheduler.h ('k') | base/test/scoped_task_environment.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/scoped_task_environment.h
diff --git a/base/test/scoped_task_environment.h b/base/test/scoped_task_environment.h
new file mode 100644
index 0000000000000000000000000000000000000000..2887d0765bacf5753eb4037a8f79931e22e9c022
--- /dev/null
+++ b/base/test/scoped_task_environment.h
@@ -0,0 +1,56 @@
+// 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_TASK_ENVIRONMENT_H_
+#define BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_
+
+#include "base/macros.h"
+#include "base/message_loop/message_loop.h"
+
+namespace base {
+
+class TaskScheduler;
+
+namespace test {
+
+// ScopedTaskEnvironment allows usage of these APIs within its scope:
+// - (Thread|Sequenced)TaskRunnerHandle, on the thread where it lives
+// - base/task_scheduler/post_task.h, on any thread
+//
+// Tests that need either of these APIs should instantiate a
+// ScopedTaskEnvironment.
+//
+// Tasks posted to the (Thread|Sequenced)TaskRunnerHandle run synchronously when
+// RunLoop::Run(UntilIdle) is called on the thread where the
+// ScopedTaskEnvironment lives.
+//
+// Tasks posted through base/task_scheduler/post_task.h run on dedicated threads
+// as they are posted.
+//
+// Design and future improvements documented in
+// https://docs.google.com/document/d/1QabRo8c7D9LsYY3cEcaPQbOCLo8Tu-6VLykYXyl3Pkk/edit
+class ScopedTaskEnvironment {
+ public:
+ ScopedTaskEnvironment();
+
+ // Runs pending (Thread|Sequenced)TaskRunnerHandle tasks and pending
+ // BLOCK_SHUTDOWN TaskScheduler tasks. Then, unregisters the TaskScheduler and
+ // the (Thread|Sequenced)TaskRunnerHandle.
+ ~ScopedTaskEnvironment();
+
+ private:
+ // Note: |message_loop_| is an implementation detail and will be replaced in
+ // the future, do NOT rely on the presence of a MessageLoop beyond
+ // (Thread|Sequenced)TaskRunnerHandle and RunLoop.
+ MessageLoop message_loop_;
+
+ const TaskScheduler* task_scheduler_ = nullptr;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedTaskEnvironment);
+};
+
+} // namespace test
+} // namespace base
+
+#endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_
« no previous file with comments | « base/test/scoped_async_task_scheduler.h ('k') | base/test/scoped_task_environment.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698