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

Side by Side Diff: base/android/java_handler_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 comment for TYPE_JAVA Created 7 years, 4 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
« no previous file with comments | « base/android/java_handler_thread.h ('k') | base/base.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_handler_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/message_loop.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread_restrictions.h"
14 #include "jni/JavaHandlerThread_jni.h"
15
16 namespace base {
17
18 namespace android {
19
20 JavaHandlerThread::JavaHandlerThread(const char* name) {
21 JNIEnv* env = base::android::AttachCurrentThread();
22
23 java_thread_.Reset(Java_JavaHandlerThread_create(
24 env, ConvertUTF8ToJavaString(env, name).Release()));
25 }
26
27 JavaHandlerThread::~JavaHandlerThread() {
28 }
29
30 void JavaHandlerThread::Start() {
31 // Check the thread has not already been started.
32 DCHECK(!message_loop_);
33
34 JNIEnv* env = base::android::AttachCurrentThread();
35 base::WaitableEvent initialize_event(false, false);
36 Java_JavaHandlerThread_start(env,
37 java_thread_.obj(),
38 reinterpret_cast<jint>(this),
39 reinterpret_cast<jint>(&initialize_event));
40 // Wait for thread to be initialized so it is ready to be used when Start
41 // returns.
42 base::ThreadRestrictions::ScopedAllowWait wait_allowed;
43 initialize_event.Wait();
44 }
45
46 void JavaHandlerThread::Stop() {
47 }
48
49 void JavaHandlerThread::InitializeThread(JNIEnv* env, jobject obj, jint event) {
50 // TYPE_JAVA to get the Android java style message loop.
51 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_JAVA));
52 static_cast<MessageLoopForUI*>(message_loop_.get())->Start();
53 reinterpret_cast<base::WaitableEvent*>(event)->Signal();
54 }
55
56 // static
57 bool JavaHandlerThread::RegisterBindings(JNIEnv* env) {
58 return RegisterNativesImpl(env);
59 }
60
61 } // namespace android
62 } // namespace base
OLDNEW
« no previous file with comments | « base/android/java_handler_thread.h ('k') | base/base.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698