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 #include "base/android/java_handler_thread.h" | 5 #include "base/android/java_handler_thread.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // Wait for thread to shut down before returning. | 54 // Wait for thread to shut down before returning. |
55 base::ThreadRestrictions::ScopedAllowWait wait_allowed; | 55 base::ThreadRestrictions::ScopedAllowWait wait_allowed; |
56 shutdown_event.Wait(); | 56 shutdown_event.Wait(); |
57 } | 57 } |
58 | 58 |
59 void JavaHandlerThread::InitializeThread(JNIEnv* env, | 59 void JavaHandlerThread::InitializeThread(JNIEnv* env, |
60 const JavaParamRef<jobject>& obj, | 60 const JavaParamRef<jobject>& obj, |
61 jlong event) { | 61 jlong event) { |
62 // TYPE_JAVA to get the Android java style message loop. | 62 // TYPE_JAVA to get the Android java style message loop. |
63 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_JAVA)); | 63 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_JAVA)); |
64 static_cast<MessageLoopForUI*>(message_loop_.get())->Start(); | 64 StartMessageLoop(); |
65 reinterpret_cast<base::WaitableEvent*>(event)->Signal(); | 65 reinterpret_cast<base::WaitableEvent*>(event)->Signal(); |
66 } | 66 } |
67 | 67 |
68 void JavaHandlerThread::StopThread(JNIEnv* env, | 68 void JavaHandlerThread::StopThread(JNIEnv* env, |
69 const JavaParamRef<jobject>& obj, | 69 const JavaParamRef<jobject>& obj, |
70 jlong event) { | 70 jlong event) { |
| 71 StopMessageLoop(); |
| 72 reinterpret_cast<base::WaitableEvent*>(event)->Signal(); |
| 73 } |
| 74 |
| 75 void JavaHandlerThread::StartMessageLoop() { |
| 76 static_cast<MessageLoopForUI*>(message_loop_.get())->Start(); |
| 77 } |
| 78 |
| 79 void JavaHandlerThread::StopMessageLoop() { |
71 static_cast<MessageLoopForUI*>(message_loop_.get())->QuitWhenIdle(); | 80 static_cast<MessageLoopForUI*>(message_loop_.get())->QuitWhenIdle(); |
72 reinterpret_cast<base::WaitableEvent*>(event)->Signal(); | |
73 } | 81 } |
74 | 82 |
75 // static | 83 // static |
76 bool JavaHandlerThread::RegisterBindings(JNIEnv* env) { | 84 bool JavaHandlerThread::RegisterBindings(JNIEnv* env) { |
77 return RegisterNativesImpl(env); | 85 return RegisterNativesImpl(env); |
78 } | 86 } |
79 | 87 |
80 } // namespace android | 88 } // namespace android |
81 } // namespace base | 89 } // namespace base |
OLD | NEW |