Index: base/android/java_thread.cc |
diff --git a/base/android/java_thread.cc b/base/android/java_thread.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fd4aa2d58453688e7c919a33ed02d2188eb64d09 |
--- /dev/null |
+++ b/base/android/java_thread.cc |
@@ -0,0 +1,62 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/android/java_thread.h" |
+ |
+#include <jni.h> |
+ |
+#include "base/android/jni_android.h" |
+#include "base/android/jni_string.h" |
+#include "base/message_loop.h" |
+#include "base/synchronization/waitable_event.h" |
+#include "jni/JavaThread_jni.h" |
+ |
+namespace base { |
+ |
+namespace android { |
+ |
+JavaThread::JavaThread(const char* name) |
+ : started_(false) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ |
+ java_thread_.Reset(Java_JavaThread_create( |
+ env, ConvertUTF8ToJavaString(env, name).Release())); |
+} |
+ |
+void JavaThread::Start() { |
+ // Check the thread has not already been started. |
+ DCHECK(!started_); |
+ |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ base::WaitableEvent initialize_event(false, false); |
+ Java_JavaThread_start(env, |
+ java_thread_.obj(), |
+ reinterpret_cast<jint>(this), |
+ reinterpret_cast<jint>(&initialize_event)); |
+ // Wait for thread to be initialized so it is ready to be used when Start |
+ // returns. |
+ initialize_event.Wait(); |
+ |
+ // Delete object only used in initialization. |
benm (inactive)
2013/07/17 10:52:29
nit, don't think this comment makes sense anymore?
Kristian Monsen
2013/07/17 21:02:37
Done.
|
+ started_ = true; |
+} |
+ |
+void JavaThread::Stop() { |
+} |
+ |
+void JavaThread::InitializeThread(JNIEnv* env, jobject obj, jint event) { |
+ // TYPE_UI to get the Android java style message loop. |
+ message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); |
+ MessageLoopForUI::current()->Start(); |
joth
2013/07/17 16:29:18
So if message_loop_ was of type MessageLoopForUI y
Kristian Monsen
2013/07/17 21:02:37
Yeah ...
But we call the MessageLoop CTOR, and cla
|
+ reinterpret_cast<base::WaitableEvent*>(event)->Signal(); |
+} |
+ |
+// static |
+bool JavaThread::RegisterBindings(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+ |
+} // namespace android |
+ |
+} // namespace base |