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

Unified Diff: mojo/android/system/base_run_loop.cc

Issue 1217573005: Do not use android specific API in mojo/java. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Do not use android APIs Created 5 years, 6 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
« no previous file with comments | « no previous file | mojo/java/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index df33f01a3c2720c9af58f7078e30e102752ea6f1..3d05e30c57d7979b4944253d4072887a81ddc4d3 100644
--- a/mojo/android/system/base_run_loop.cc
+++ b/mojo/android/system/base_run_loop.cc
@@ -17,22 +17,46 @@
namespace mojo {
namespace android {
+namespace {
+
+struct MessageLoopHolder {
+ MessageLoopHolder() {
+ if (base::MessageLoop::current()) {
+ message_loop = base::MessageLoop::current();
+ owned = false;
+ } else {
+ message_loop = new base::MessageLoop(common::MessagePumpMojo::Create());
+ owned = true;
+ }
+ }
+
+ ~MessageLoopHolder() {
+ if (owned) {
+ delete message_loop;
+ message_loop = nullptr;
+ }
+ }
+
+ base::MessageLoop* message_loop;
+ bool owned;
+};
+
+} // namespace
+
static jlong CreateBaseRunLoop(JNIEnv* env, jobject jcaller) {
- base::MessageLoop* message_loop =
- new base::MessageLoop(common::MessagePumpMojo::Create());
- return reinterpret_cast<uintptr_t>(message_loop);
+ return reinterpret_cast<uintptr_t>(new MessageLoopHolder());
}
static void Run(JNIEnv* env, jobject jcaller, jlong runLoopID) {
- reinterpret_cast<base::MessageLoop*>(runLoopID)->Run();
+ reinterpret_cast<MessageLoopHolder*>(runLoopID)->message_loop->Run();
}
static void RunUntilIdle(JNIEnv* env, jobject jcaller, jlong runLoopID) {
- reinterpret_cast<base::MessageLoop*>(runLoopID)->RunUntilIdle();
+ reinterpret_cast<MessageLoopHolder*>(runLoopID)->message_loop->RunUntilIdle();
}
static void Quit(JNIEnv* env, jobject jcaller, jlong runLoopID) {
- reinterpret_cast<base::MessageLoop*>(runLoopID)->Quit();
+ reinterpret_cast<MessageLoopHolder*>(runLoopID)->message_loop->Quit();
}
static void RunJavaRunnable(
@@ -51,15 +75,16 @@ static void PostDelayedTask(JNIEnv* env,
// 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));
+ reinterpret_cast<MessageLoopHolder*>(runLoopID)
+ ->message_loop->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;
+ MessageLoopHolder* native_loop =
+ reinterpret_cast<MessageLoopHolder*>(runLoopID);
+ delete native_loop;
}
bool RegisterBaseRunLoop(JNIEnv* env) {
« no previous file with comments | « no previous file | mojo/java/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698