OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_H_ | 5 #ifndef BASE_ANDROID_JAVA_HANDLER_THREAD_H_ |
6 #define BASE_ANDROID_JAVA_HANDLER_THREAD_H_ | 6 #define BASE_ANDROID_JAVA_HANDLER_THREAD_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 12 matching lines...) Expand all Loading... |
23 // on the thread. | 23 // on the thread. |
24 // This is useful for callbacks where the receiver expects a thread | 24 // This is useful for callbacks where the receiver expects a thread |
25 // with a prepared Looper. | 25 // with a prepared Looper. |
26 class BASE_EXPORT JavaHandlerThread { | 26 class BASE_EXPORT JavaHandlerThread { |
27 public: | 27 public: |
28 JavaHandlerThread(const char* name); | 28 JavaHandlerThread(const char* name); |
29 virtual ~JavaHandlerThread(); | 29 virtual ~JavaHandlerThread(); |
30 | 30 |
31 base::MessageLoop* message_loop() const { return message_loop_.get(); } | 31 base::MessageLoop* message_loop() const { return message_loop_.get(); } |
32 void Start(); | 32 void Start(); |
| 33 void StartForTesting(base::WaitableEvent* test_done_event); |
33 void Stop(); | 34 void Stop(); |
| 35 void StopForTesting(); |
34 | 36 |
35 // Called from java on the newly created thread. | 37 // Called from java on the newly created thread. |
36 // Start() will not return before this methods has finished. | 38 // Start() will not return before this methods has finished. |
37 void InitializeThread(JNIEnv* env, | 39 void InitializeThread(JNIEnv* env, |
38 const JavaParamRef<jobject>& obj, | 40 const JavaParamRef<jobject>& obj, |
39 jlong event); | 41 jlong event); |
| 42 void InitializeThreadForTesting(JNIEnv* env, |
| 43 const JavaParamRef<jobject>& obj, |
| 44 jlong event, |
| 45 jlong test_done_event); |
40 void StopThread(JNIEnv* env, | 46 void StopThread(JNIEnv* env, |
41 const JavaParamRef<jobject>& obj, | 47 const JavaParamRef<jobject>& obj, |
42 jlong event); | 48 jlong event); |
| 49 void StopThreadForTesting(JNIEnv* env, |
| 50 const JavaParamRef<jobject>& obj, |
| 51 jlong event); |
43 | 52 |
44 static bool RegisterBindings(JNIEnv* env); | 53 static bool RegisterBindings(JNIEnv* env); |
45 | 54 |
46 private: | 55 private: |
47 std::unique_ptr<base::MessageLoop> message_loop_; | 56 std::unique_ptr<base::MessageLoop> message_loop_; |
48 ScopedJavaGlobalRef<jobject> java_thread_; | 57 ScopedJavaGlobalRef<jobject> java_thread_; |
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_H_ | 63 #endif // BASE_ANDROID_JAVA_HANDLER_THREAD_H_ |
OLD | NEW |