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

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: Update copyright year, and split a comment over two lines 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 JNIEnv* env = base::android::AttachCurrentThread();
21 DCHECK(env);
22
23 java_thread_.Reset(Java_JavaThread_create(
24 env, ConvertUTF8ToJavaString(env, name).Release()));
25 }
26
27 void JavaThread::Start() {
28 JNIEnv* env = base::android::AttachCurrentThread();
29 DCHECK(env);
30
31 waitable_event_ = new base::WaitableEvent(false, false);
32 Java_JavaThread_start(env, java_thread_.obj(), reinterpret_cast<jint>(this));
33 // Wait for thread to be initialized so it is ready to be used when Start
34 // returns
35 waitable_event_->Wait();
36
37 // Delete object only used in initialization
38 delete(waitable_event_);
benm (inactive) 2013/07/10 16:50:06 nit: no parens
Kristian Monsen 2013/07/10 17:50:19 Done.
39 waitable_event_ = NULL;
benm (inactive) 2013/07/10 16:50:06 maybe leave it non null and dcheck == null at the
Kristian Monsen 2013/07/10 17:50:19 I don't like to leave deleted variables around as
40 }
41
42 void JavaThread::Stop() {
benm (inactive) 2013/07/10 16:50:06 Do we need a way for java to call this so we can c
Kristian Monsen 2013/07/10 17:50:19 I think it is more the other way round. Currently
43 }
44
45 void JavaThread::InitializeThread(JNIEnv* env, jobject obj) {
46 // TYPE_UI to get the Android java style message loop
47 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
48 MessageLoopForUI::current()->Start();
49 waitable_event_->Signal();
50 }
51
52 // static
53 bool JavaThread::RegisterBindings(JNIEnv* env) {
54 return RegisterNativesImpl(env);
55 }
56
57 } // namespace android
58
59 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698