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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/android/system/base_run_loop.cc
diff --git a/mojo/android/system/base_run_loop.cc b/mojo/android/system/base_run_loop.cc
new file mode 100644
index 0000000000000000000000000000000000000000..df33f01a3c2720c9af58f7078e30e102752ea6f1
--- /dev/null
+++ b/mojo/android/system/base_run_loop.cc
@@ -0,0 +1,72 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/android/system/base_run_loop.h"
+
+#include <jni.h>
+
+#include "base/android/base_jni_registrar.h"
+#include "base/android/jni_android.h"
+#include "base/android/jni_registrar.h"
+#include "base/bind.h"
+#include "base/message_loop/message_loop.h"
+#include "jni/BaseRunLoop_jni.h"
+#include "mojo/common/message_pump_mojo.h"
+
+namespace mojo {
+namespace android {
+
+static jlong CreateBaseRunLoop(JNIEnv* env, jobject jcaller) {
+ base::MessageLoop* message_loop =
+ new base::MessageLoop(common::MessagePumpMojo::Create());
+ return reinterpret_cast<uintptr_t>(message_loop);
+}
+
+static void Run(JNIEnv* env, jobject jcaller, jlong runLoopID) {
+ reinterpret_cast<base::MessageLoop*>(runLoopID)->Run();
+}
+
+static void RunUntilIdle(JNIEnv* env, jobject jcaller, jlong runLoopID) {
+ reinterpret_cast<base::MessageLoop*>(runLoopID)->RunUntilIdle();
+}
+
+static void Quit(JNIEnv* env, jobject jcaller, jlong runLoopID) {
+ reinterpret_cast<base::MessageLoop*>(runLoopID)->Quit();
+}
+
+static void RunJavaRunnable(
+ const base::android::ScopedJavaGlobalRef<jobject>& runnable_ref) {
+ Java_BaseRunLoop_runRunnable(base::android::AttachCurrentThread(),
+ runnable_ref.obj());
+}
+
+static void PostDelayedTask(JNIEnv* env,
+ jobject jcaller,
+ jlong runLoopID,
+ jobject runnable,
+ jlong delay) {
+ base::android::ScopedJavaGlobalRef<jobject> runnable_ref;
+ // ScopedJavaGlobalRef do not hold onto the env reference, so it is safe to
+ // use it across threads. |RunJavaRunnable| will acquire a new JNIEnv before
+ // running the Runnable.
+ runnable_ref.Reset(env, runnable);
+ reinterpret_cast<base::MessageLoop*>(runLoopID)->PostDelayedTask(
+ FROM_HERE, base::Bind(&RunJavaRunnable, runnable_ref),
+ base::TimeDelta::FromMicroseconds(delay));
+}
+
+static void DeleteMessageLoop(JNIEnv* env, jobject jcaller, jlong runLoopID) {
+ base::MessageLoop* message_loop =
+ reinterpret_cast<base::MessageLoop*>(runLoopID);
+ delete message_loop;
+}
+
+bool RegisterBaseRunLoop(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace android
+} // namespace mojo
+
+
« 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