OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_ | 5 #ifndef BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_ |
6 #define BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_ | 6 #define BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_ |
7 | 7 |
8 #include <memory> | |
9 | |
8 #include "base/android/java_handler_thread.h" | 10 #include "base/android/java_handler_thread.h" |
9 #include "base/android/java_message_handler_factory.h" | 11 #include "base/android/java_message_handler_factory.h" |
10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
11 #include "base/test/android/test_system_message_handler_link_android.h" | 13 #include "base/test/android/test_system_message_handler_link_android.h" |
12 | 14 |
13 namespace base { | 15 namespace base { |
14 | 16 |
15 namespace android { | 17 namespace android { |
16 | 18 |
17 // Factory class for creating a custom Java-side message handler. | 19 // Factory class for creating a custom Java-side message handler. |
(...skipping 11 matching lines...) Expand all Loading... | |
29 // Test-version of JavaHandlerThread, we need this class to start and stop the | 31 // Test-version of JavaHandlerThread, we need this class to start and stop the |
30 // message loop of the new thread in a different way than JavaHandlerThread | 32 // message loop of the new thread in a different way than JavaHandlerThread |
31 // does. | 33 // does. |
32 // This is partly because we need to create a test-only java-side message | 34 // This is partly because we need to create a test-only java-side message |
33 // handler to back the native message loop, and partly because our tests cause | 35 // handler to back the native message loop, and partly because our tests cause |
34 // the corresponding message pump to abort which means it won't reach its idle | 36 // the corresponding message pump to abort which means it won't reach its idle |
35 // work state and thus can't quit when idle. We here stop the pump more abruptly | 37 // work state and thus can't quit when idle. We here stop the pump more abruptly |
36 // instead. | 38 // instead. |
37 class JavaHandlerThreadForTesting : public JavaHandlerThread { | 39 class JavaHandlerThreadForTesting : public JavaHandlerThread { |
38 public: | 40 public: |
39 JavaHandlerThreadForTesting(const char* name, | 41 static std::unique_ptr<JavaHandlerThreadForTesting> Create( |
40 base::WaitableEvent* test_done_event); | 42 const char* name, |
43 base::WaitableEvent* test_done_event); | |
44 static std::unique_ptr<JavaHandlerThreadForTesting> CreateJavaFirst( | |
gab
2017/03/29 18:14:04
Add comments
boliu
2017/03/29 18:30:07
Done.
| |
45 base::WaitableEvent* test_done_event); | |
41 ~JavaHandlerThreadForTesting() override; | 46 ~JavaHandlerThreadForTesting() override; |
gab
2017/03/29 18:14:04
Destructor goes first since these are no longer co
boliu
2017/03/29 18:30:07
Done.
| |
42 | 47 |
43 void StartMessageLoop() override; | 48 void StartMessageLoop() override; |
44 void StopMessageLoop() override; | 49 void StopMessageLoop() override; |
45 | 50 |
46 private: | 51 private: |
52 JavaHandlerThreadForTesting(const char* name, | |
53 base::WaitableEvent* test_done_event); | |
54 explicit JavaHandlerThreadForTesting(base::WaitableEvent* test_done_event); | |
55 | |
47 std::unique_ptr<JavaMessageHandlerFactory> message_handler_factory_; | 56 std::unique_ptr<JavaMessageHandlerFactory> message_handler_factory_; |
48 base::WaitableEvent* test_done_event_; | 57 base::WaitableEvent* test_done_event_; |
49 }; | 58 }; |
50 | 59 |
51 } // namespace android | 60 } // namespace android |
52 } // namespace base | 61 } // namespace base |
53 | 62 |
54 #endif // BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_ | 63 #endif // BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_ |
OLD | NEW |