| 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> |
| 11 | 11 |
| 12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 | 15 |
| 16 class MessageLoop; | 16 class MessageLoop; |
| 17 | 17 |
| 18 namespace android { | 18 namespace android { |
| 19 | 19 |
| 20 // A Java Thread with a native message loop. To run tasks, post them | 20 // A Java Thread with a native message loop. To run tasks, post them |
| 21 // to the message loop and they will be scheduled along with Java tasks | 21 // to the message loop and they will be scheduled along with Java tasks |
| 22 // on the thread. | 22 // on the thread. |
| 23 // This is useful for callbacks where the receiver expects a thread | 23 // This is useful for callbacks where the receiver expects a thread |
| 24 // with a prepared Looper. | 24 // with a prepared Looper. |
| 25 class BASE_EXPORT JavaHandlerThread { | 25 class BASE_EXPORT JavaHandlerThread { |
| 26 public: | 26 public: |
| 27 JavaHandlerThread(const char* name); | 27 // Create new thread. |
| 28 explicit JavaHandlerThread(const char* name); |
| 29 // Wrap and connect to an existing JavaHandlerThread. |
| 30 // |obj| is an instance of JavaHandlerThread. |
| 31 explicit JavaHandlerThread( |
| 32 const base::android::ScopedJavaLocalRef<jobject>& obj); |
| 28 virtual ~JavaHandlerThread(); | 33 virtual ~JavaHandlerThread(); |
| 29 | 34 |
| 30 base::MessageLoop* message_loop() const { return message_loop_.get(); } | 35 base::MessageLoop* message_loop() const { return message_loop_.get(); } |
| 31 void Start(); | 36 void Start(); |
| 32 void Stop(); | 37 void Stop(); |
| 33 | 38 |
| 34 // Called from java on the newly created thread. | 39 // Called from java on the newly created thread. |
| 35 // Start() will not return before this methods has finished. | 40 // Start() will not return before this methods has finished. |
| 36 void InitializeThread(JNIEnv* env, | 41 void InitializeThread(JNIEnv* env, |
| 37 const JavaParamRef<jobject>& obj, | 42 const JavaParamRef<jobject>& obj, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 49 std::unique_ptr<base::MessageLoop> message_loop_; | 54 std::unique_ptr<base::MessageLoop> message_loop_; |
| 50 | 55 |
| 51 private: | 56 private: |
| 52 ScopedJavaGlobalRef<jobject> java_thread_; | 57 ScopedJavaGlobalRef<jobject> java_thread_; |
| 53 }; | 58 }; |
| 54 | 59 |
| 55 } // namespace android | 60 } // namespace android |
| 56 } // namespace base | 61 } // namespace base |
| 57 | 62 |
| 58 #endif // BASE_ANDROID_JAVA_HANDLER_THREAD_H_ | 63 #endif // BASE_ANDROID_JAVA_HANDLER_THREAD_H_ |
| OLD | NEW |