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

Side by Side Diff: base/test/thread_test_helper.h

Issue 1113953002: Revert of base: Remove use of MessageLoopProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « base/test/task_runner_test_template.h ('k') | base/test/thread_test_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_TEST_THREAD_TEST_HELPER_H_ 5 #ifndef BASE_TEST_THREAD_TEST_HELPER_H_
6 #define BASE_TEST_THREAD_TEST_HELPER_H_ 6 #define BASE_TEST_THREAD_TEST_HELPER_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 12
13 namespace base { 13 namespace base {
14 14
15 // Helper class that executes code on a given thread while blocking on the 15 // Helper class that executes code on a given thread while blocking on the
16 // invoking thread. To use, derive from this class and overwrite RunTest. An 16 // invoking thread. To use, derive from this class and overwrite RunTest. An
17 // alternative use of this class is to use it directly. It will then block 17 // alternative use of this class is to use it directly. It will then block
18 // until all pending tasks on a given thread have been executed. 18 // until all pending tasks on a given thread have been executed.
19 class ThreadTestHelper : public RefCountedThreadSafe<ThreadTestHelper> { 19 class ThreadTestHelper : public RefCountedThreadSafe<ThreadTestHelper> {
20 public: 20 public:
21 explicit ThreadTestHelper( 21 explicit ThreadTestHelper(
22 scoped_refptr<SingleThreadTaskRunner> target_thread); 22 const scoped_refptr<MessageLoopProxy>& target_thread);
23 23
24 // True if RunTest() was successfully executed on the target thread. 24 // True if RunTest() was successfully executed on the target thread.
25 bool Run() WARN_UNUSED_RESULT; 25 bool Run() WARN_UNUSED_RESULT;
26 26
27 virtual void RunTest(); 27 virtual void RunTest();
28 28
29 protected: 29 protected:
30 friend class RefCountedThreadSafe<ThreadTestHelper>; 30 friend class RefCountedThreadSafe<ThreadTestHelper>;
31 31
32 virtual ~ThreadTestHelper(); 32 virtual ~ThreadTestHelper();
33 33
34 // Use this method to store the result of RunTest(). 34 // Use this method to store the result of RunTest().
35 void set_test_result(bool test_result) { test_result_ = test_result; } 35 void set_test_result(bool test_result) { test_result_ = test_result; }
36 36
37 private: 37 private:
38 void RunInThread(); 38 void RunInThread();
39 39
40 bool test_result_; 40 bool test_result_;
41 scoped_refptr<SingleThreadTaskRunner> target_thread_; 41 scoped_refptr<MessageLoopProxy> target_thread_;
42 WaitableEvent done_event_; 42 WaitableEvent done_event_;
43 43
44 DISALLOW_COPY_AND_ASSIGN(ThreadTestHelper); 44 DISALLOW_COPY_AND_ASSIGN(ThreadTestHelper);
45 }; 45 };
46 46
47 } // namespace base 47 } // namespace base
48 48
49 #endif // BASE_TEST_THREAD_TEST_HELPER_H_ 49 #endif // BASE_TEST_THREAD_TEST_HELPER_H_
OLDNEW
« no previous file with comments | « base/test/task_runner_test_template.h ('k') | base/test/thread_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698