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, | |
40 base::WaitableEvent* test_done_event); | |
41 ~JavaHandlerThreadForTesting() override; | 41 ~JavaHandlerThreadForTesting() override; |
42 | 42 |
| 43 static std::unique_ptr<JavaHandlerThreadForTesting> Create( |
| 44 const char* name, |
| 45 base::WaitableEvent* test_done_event); |
| 46 // Create the Java peer first and test that it works before connecting to the |
| 47 // native object. |
| 48 static std::unique_ptr<JavaHandlerThreadForTesting> CreateJavaFirst( |
| 49 base::WaitableEvent* test_done_event); |
| 50 |
43 void StartMessageLoop() override; | 51 void StartMessageLoop() override; |
44 void StopMessageLoop() override; | 52 void StopMessageLoop() override; |
45 | 53 |
46 private: | 54 private: |
| 55 JavaHandlerThreadForTesting(const char* name, |
| 56 base::WaitableEvent* test_done_event); |
| 57 explicit JavaHandlerThreadForTesting(base::WaitableEvent* test_done_event); |
| 58 |
47 std::unique_ptr<JavaMessageHandlerFactory> message_handler_factory_; | 59 std::unique_ptr<JavaMessageHandlerFactory> message_handler_factory_; |
48 base::WaitableEvent* test_done_event_; | 60 base::WaitableEvent* test_done_event_; |
49 }; | 61 }; |
50 | 62 |
51 } // namespace android | 63 } // namespace android |
52 } // namespace base | 64 } // namespace base |
53 | 65 |
54 #endif // BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_ | 66 #endif // BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_ |
OLD | NEW |