Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 PostDelayedTask(JNIEnv* env, | |
| 39 jobject jcaller, | |
| 40 jlong runLoopID, | |
| 41 jobject runnable, | |
| 42 jlong delay) { | |
| 43 reinterpret_cast<base::MessageLoop*>(runLoopID)->PostDelayedTask( | |
| 44 FROM_HERE, base::Bind(&Java_BaseRunLoop_runRunnable, env, runnable), | |
|
qsr
2015/02/06 17:16:14
Do not keep env. You should post to a local method
etiennej
2015/02/09 14:09:51
Done.
| |
| 45 base::TimeDelta::FromMicroseconds(delay)); | |
| 46 } | |
| 47 | |
| 48 static void DeleteMessageLoop(JNIEnv* env, jobject jcaller, jlong runLoopID) { | |
| 49 base::MessageLoop* message_loop = | |
| 50 reinterpret_cast<base::MessageLoop*>(runLoopID); | |
| 51 delete message_loop; | |
| 52 } | |
| 53 | |
| 54 bool RegisterBaseRunLoop(JNIEnv* env) { | |
| 55 return RegisterNativesImpl(env); | |
| 56 } | |
| 57 | |
| 58 } // namespace android | |
| 59 } // namespace mojo | |
| 60 | |
| 61 | |
| OLD | NEW |