Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: base/android/java_thread.cc

Issue 18584006: Making a way to create thread with a Java Looper for Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style fixes, and make the waitable event a stack variable Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 JavaThread::JavaThread(const char* name)
20 : started_(false) {
21 JNIEnv* env = base::android::AttachCurrentThread();
22
23 java_thread_.Reset(Java_JavaThread_create(
24 env, ConvertUTF8ToJavaString(env, name).Release()));
25 }
26
27 void JavaThread::Start() {
28 // Check the thread has not already been started.
29 DCHECK(!started_);
30
31 JNIEnv* env = base::android::AttachCurrentThread();
32 base::WaitableEvent initialize_event(false, false);
33 Java_JavaThread_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
41 // 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.
42 started_ = true;
43 }
44
45 void JavaThread::Stop() {
46 }
47
48 void JavaThread::InitializeThread(JNIEnv* env, jobject obj, jint event) {
49 // TYPE_UI to get the Android java style message loop.
50 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
51 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
52 reinterpret_cast<base::WaitableEvent*>(event)->Signal();
53 }
54
55 // static
56 bool JavaThread::RegisterBindings(JNIEnv* env) {
57 return RegisterNativesImpl(env);
58 }
59
60 } // namespace android
61
62 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698