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

Side by Side Diff: mojo/android/system/base_run_loop.cc

Issue 898853006: Java content handler for Android. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "mojo/android/system/base_run_loop.h"
6
7 #include <jni.h>
8
9 #include "base/android/base_jni_registrar.h"
10 #include "base/android/jni_android.h"
11 #include "base/android/jni_registrar.h"
12 #include "base/bind.h"
13 #include "base/message_loop/message_loop.h"
14 #include "jni/BaseRunLoop_jni.h"
15 #include "mojo/common/message_pump_mojo.h"
16
17 namespace mojo {
18 namespace android {
19
20 static jlong CreateBaseRunLoop(JNIEnv* env, jobject jcaller) {
21 base::MessageLoop* message_loop =
22 new base::MessageLoop(common::MessagePumpMojo::Create());
23 return reinterpret_cast<uintptr_t>(message_loop);
24 }
25
26 static void Run(JNIEnv* env, jobject jcaller, jlong runLoopID) {
27 reinterpret_cast<base::MessageLoop*>(runLoopID)->Run();
28 }
29
30 static void RunUntilIdle(JNIEnv* env, jobject jcaller, jlong runLoopID) {
31 reinterpret_cast<base::MessageLoop*>(runLoopID)->RunUntilIdle();
32 }
33
34 static void Quit(JNIEnv* env, jobject jcaller, jlong runLoopID) {
35 reinterpret_cast<base::MessageLoop*>(runLoopID)->Quit();
36 }
37
38 static void RunJavaRunnable(
39 const base::android::ScopedJavaGlobalRef<jobject>& runnable_ref) {
40 Java_BaseRunLoop_runRunnable(base::android::AttachCurrentThread(),
41 runnable_ref.obj());
42 }
43
44 static void PostDelayedTask(JNIEnv* env,
45 jobject jcaller,
46 jlong runLoopID,
47 jobject runnable,
48 jlong delay) {
49 base::android::ScopedJavaGlobalRef<jobject> runnable_ref;
50 // ScopedJavaGlobalRef do not hold onto the env reference, so it is safe to
51 // use it across threads. |RunJavaRunnable| will acquire a new JNIEnv before
52 // running the Runnable.
53 runnable_ref.Reset(env, runnable);
54 reinterpret_cast<base::MessageLoop*>(runLoopID)->PostDelayedTask(
55 FROM_HERE, base::Bind(&RunJavaRunnable, runnable_ref),
56 base::TimeDelta::FromMicroseconds(delay));
57 }
58
59 static void DeleteMessageLoop(JNIEnv* env, jobject jcaller, jlong runLoopID) {
60 base::MessageLoop* message_loop =
61 reinterpret_cast<base::MessageLoop*>(runLoopID);
62 delete message_loop;
63 }
64
65 bool RegisterBaseRunLoop(JNIEnv* env) {
66 return RegisterNativesImpl(env);
67 }
68
69 } // namespace android
70 } // namespace mojo
71
72
OLDNEW
« no previous file with comments | « mojo/android/system/base_run_loop.h ('k') | mojo/android/system/src/org/chromium/mojo/system/impl/BaseRunLoop.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698