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

Unified Diff: base/test/scoped_task_environment.h

Issue 2891363005: Add ScopedTaskEnvironment::ExecutionControlMode. (Closed)
Patch Set: CR-gab-31 Created 3 years, 7 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/task_scheduler/task_tracker_posix.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
index f46b516d7c16ddea6d7a6b710fd9a7832045dc29..5166a5e776c790d03585f8afd56847d186962983 100644
--- a/base/test/scoped_task_environment.h
+++ b/base/test/scoped_task_environment.h
@@ -26,7 +26,9 @@ namespace test {
// RunLoop::Run(UntilIdle) or ScopedTaskEnvironment::RunUntilIdle is called on
// the thread where the ScopedTaskEnvironment lives.
//
-// Tasks posted through base/task_scheduler/post_task.h run on dedicated threads
+// Tasks posted through base/task_scheduler/post_task.h run on dedicated
+// threads. If ExecutionMode is QUEUED, they run when RunUntilIdle() or
+// ~ScopedTaskEnvironment is called. If ExecutionMode is ASYNC, they run
// as they are posted.
//
// All methods of ScopedTaskEnvironment must be called from the same thread.
@@ -61,8 +63,18 @@ class ScopedTaskEnvironment {
IO,
};
+ enum class ExecutionMode {
+ // Tasks are queued and only executed when RunUntilIdle() is explicitly
+ // called.
+ QUEUED,
+ // Tasks run as they are posted. RunUntilIdle() can still be used to block
+ // until done.
+ ASYNC,
+ };
+
ScopedTaskEnvironment(
- MainThreadType main_thread_type = MainThreadType::DEFAULT);
+ MainThreadType main_thread_type = MainThreadType::DEFAULT,
+ ExecutionMode execution_control_mode = ExecutionMode::ASYNC);
// Waits until no undelayed TaskScheduler tasks remain. Then, unregisters the
// TaskScheduler and the (Thread|Sequenced)TaskRunnerHandle.
@@ -71,11 +83,15 @@ class ScopedTaskEnvironment {
// Returns a TaskRunner that schedules tasks on the main thread.
scoped_refptr<base::SingleThreadTaskRunner> GetMainThreadTaskRunner();
- // Synchronously runs (Thread|Sequenced)TaskRunnerHandle tasks until no
- // undelayed (Thread|Sequenced)TaskRunnerHandle or TaskScheduler tasks remain.
+ // Runs tasks until both the (Thread|Sequenced)TaskRunnerHandle and the
+ // TaskScheduler queues are empty.
void RunUntilIdle();
private:
+ class TestTaskTracker;
+
+ const ExecutionMode execution_control_mode_;
+
// 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.
@@ -83,6 +99,9 @@ class ScopedTaskEnvironment {
const TaskScheduler* task_scheduler_ = nullptr;
+ // Owned by |task_scheduler_|.
+ TestTaskTracker* const task_tracker_;
+
DISALLOW_COPY_AND_ASSIGN(ScopedTaskEnvironment);
};
« no previous file with comments | « base/task_scheduler/task_tracker_posix.h ('k') | base/test/scoped_task_environment.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698