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 JavaThread::JavaThread(const char* name) : started_(false) { | |
joth
2013/07/10 20:33:48
unindent
: started_(false) on its own line (unles
Kristian Monsen
2013/07/16 21:54:41
Done.
| |
20 JNIEnv* env = base::android::AttachCurrentThread(); | |
21 DCHECK(env); | |
joth
2013/07/10 20:33:48
spurious
Kristian Monsen
2013/07/16 21:54:41
Done.
| |
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 | |
joth
2013/07/10 20:33:48
nit: end sentence in . on all the comments
Kristian Monsen
2013/07/16 21:54:41
Done.
| |
29 DCHECK(!started_); | |
30 | |
31 JNIEnv* env = base::android::AttachCurrentThread(); | |
32 DCHECK(env); | |
joth
2013/07/10 20:33:48
ditto
Kristian Monsen
2013/07/16 21:54:41
Done.
| |
33 | |
34 waitable_event_ = new base::WaitableEvent(false, false); | |
joth
2013/07/10 20:33:48
cleaner as:
base::WaitableEvent event(false, fals
Kristian Monsen
2013/07/16 21:54:41
I made it a stack variable, see what you think?
| |
35 Java_JavaThread_start(env, java_thread_.obj(), reinterpret_cast<jint>(this)); | |
joth
2013/07/10 20:33:48
slight tempted to pass &event through as an additi
Kristian Monsen
2013/07/16 21:54:41
Done.
| |
36 // Wait for thread to be initialized so it is ready to be used when Start | |
37 // returns | |
38 waitable_event_->Wait(); | |
39 | |
40 // Delete object only used in initialization | |
41 delete waitable_event_; | |
42 waitable_event_ = NULL; | |
43 started_ = true; | |
44 } | |
45 | |
46 void JavaThread::Stop() { | |
47 } | |
48 | |
49 void JavaThread::InitializeThread(JNIEnv* env, jobject obj) { | |
50 // TYPE_UI to get the Android java style message loop | |
51 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); | |
52 MessageLoopForUI::current()->Start(); | |
joth
2013/07/10 20:33:48
message_loop_->Start() ? (/shrug)
Kristian Monsen
2013/07/16 21:54:41
Sadly not possible, Start() is an #ifdef ANDROID i
| |
53 waitable_event_->Signal(); | |
54 } | |
55 | |
56 // static | |
57 bool JavaThread::RegisterBindings(JNIEnv* env) { | |
58 return RegisterNativesImpl(env); | |
59 } | |
60 | |
61 } // namespace android | |
62 | |
63 } // namespace base | |
OLD | NEW |