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

Unified Diff: base/threading/thread_task_runner_handle.h

Issue 2657013002: Introduce ThreadTaskRunnerHandle::OverrideForTesting and TestMockTimeTaskRunner::ScopedContext. (Closed)
Patch Set: review:xunjeli#33 Created 3 years, 10 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/test_simple_task_runner.cc ('k') | base/threading/thread_task_runner_handle.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/thread_task_runner_handle.h
diff --git a/base/threading/thread_task_runner_handle.h b/base/threading/thread_task_runner_handle.h
index c8e58935f0977259349857bf91d71c63bf734567..8baf4544c9ed31e83ef2870c3364603d5f79b506 100644
--- a/base/threading/thread_task_runner_handle.h
+++ b/base/threading/thread_task_runner_handle.h
@@ -32,8 +32,30 @@ class BASE_EXPORT ThreadTaskRunnerHandle {
scoped_refptr<SingleThreadTaskRunner> task_runner);
~ThreadTaskRunnerHandle();
+ // A ThreadTaskRunnerHandle::NestedForTesting is the same thing as a
+ // ThreadTaskRunnerHandle except that it allows overriding an existing
+ // ThreadTaskRunnerHandle in its scope. Nesting ThreadTaskRunnerHandles isn't
+ // generally desired but it can be useful in unit tests where multiple task
+ // runners are sharing the main thread for simplicity and determinism.
+ class BASE_EXPORT NestedForTesting {
danakj 2017/02/16 17:57:24 Proposal to make the changes less invasive. 1) Ov
gab 2017/02/16 21:03:36 That's what I wanted to do at first, but then hit
+ public:
+ explicit NestedForTesting(
+ scoped_refptr<SingleThreadTaskRunner> task_runner);
+ ~NestedForTesting();
+
+ private:
+ friend class ThreadTaskRunnerHandle;
+
+ scoped_refptr<SingleThreadTaskRunner> task_runner_;
+ const NestedForTesting* const previous_handle_;
+
+ DISALLOW_COPY_AND_ASSIGN(NestedForTesting);
+ };
+
private:
- scoped_refptr<SingleThreadTaskRunner> task_runner_;
+ // The impl uses NestedForTesting to avoid code duplication but this is the
+ // only allowed non-test usage.
+ std::unique_ptr<NestedForTesting> handle_;
DISALLOW_COPY_AND_ASSIGN(ThreadTaskRunnerHandle);
};
« no previous file with comments | « base/test/test_simple_task_runner.cc ('k') | base/threading/thread_task_runner_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698