Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/android/java_thread.h" | |
| 6 | |
| 7 #include <jni.h> | |
| 8 | |
| 9 #include "base/android/jni_android.h" | |
| 10 #include "base/android/jni_string.h" | |
| 11 #include "base/message_loop.h" | |
| 12 #include "base/synchronization/waitable_event.h" | |
| 13 #include "jni/JavaThread_jni.h" | |
| 14 | |
| 15 namespace base { | |
| 16 | |
| 17 namespace android { | |
| 18 | |
| 19 JavaHandlerThread::JavaHandlerThread(const char* name) | |
| 20 : started_(false) { | |
| 21 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 22 | |
| 23 java_thread_.Reset(Java_JavaHandlerThread_create( | |
| 24 env, ConvertUTF8ToJavaString(env, name).Release())); | |
| 25 } | |
| 26 | |
| 27 void JavaHandlerThread::Start() { | |
| 28 // Check the thread has not already been started. | |
| 29 DCHECK(!started_); | |
|
joth
2013/07/17 21:16:19
nit: the comment is kind of spurious :)
nit: we'd
| |
| 30 | |
| 31 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 32 base::WaitableEvent initialize_event(false, false); | |
| 33 Java_JavaHandlerThread_start(env, | |
| 34 java_thread_.obj(), | |
| 35 reinterpret_cast<jint>(this), | |
| 36 reinterpret_cast<jint>(&initialize_event)); | |
| 37 // Wait for thread to be initialized so it is ready to be used when Start | |
| 38 // returns. | |
| 39 initialize_event.Wait(); | |
| 40 started_ = true; | |
| 41 } | |
| 42 | |
| 43 void JavaHandlerThread::Stop() { | |
| 44 } | |
| 45 | |
| 46 void JavaHandlerThread::InitializeThread(JNIEnv* env, jobject obj, jint event) { | |
| 47 // TYPE_UI to get the Android java style message loop. | |
| 48 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); | |
| 49 MessageLoopForUI::current()->Start(); | |
| 50 reinterpret_cast<base::WaitableEvent*>(event)->Signal(); | |
| 51 } | |
| 52 | |
| 53 // static | |
| 54 bool JavaHandlerThread::RegisterBindings(JNIEnv* env) { | |
| 55 return RegisterNativesImpl(env); | |
| 56 } | |
| 57 | |
| 58 } // namespace android | |
| 59 } // namespace base | |
| OLD | NEW |