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

Unified Diff: base/threading/thread_task_runner_handle.h

Issue 2657013002: Introduce ThreadTaskRunnerHandle::OverrideForTesting and TestMockTimeTaskRunner::ScopedContext. (Closed)
Patch Set: nvm : still need the completion closure e.g. profile_impl_io_data.cc -> Clear() 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
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 {
+ 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);
};

Powered by Google App Engine
This is Rietveld 408576698