OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/android/system/base_run_loop.h" | 5 #include "mojo/android/system/base_run_loop.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/base_jni_registrar.h" | 9 #include "base/android/base_jni_registrar.h" |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 message_loop = nullptr; | 36 message_loop = nullptr; |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 base::MessageLoop* message_loop; | 40 base::MessageLoop* message_loop; |
41 bool owned; | 41 bool owned; |
42 }; | 42 }; |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 static jlong CreateBaseRunLoop(JNIEnv* env, jobject jcaller) { | 46 static jlong CreateBaseRunLoop(JNIEnv* env, |
| 47 const JavaParamRef<jobject>& jcaller) { |
47 return reinterpret_cast<uintptr_t>(new MessageLoopHolder()); | 48 return reinterpret_cast<uintptr_t>(new MessageLoopHolder()); |
48 } | 49 } |
49 | 50 |
50 static void Run(JNIEnv* env, jobject jcaller, jlong runLoopID) { | 51 static void Run(JNIEnv* env, |
| 52 const JavaParamRef<jobject>& jcaller, |
| 53 jlong runLoopID) { |
51 reinterpret_cast<MessageLoopHolder*>(runLoopID)->message_loop->Run(); | 54 reinterpret_cast<MessageLoopHolder*>(runLoopID)->message_loop->Run(); |
52 } | 55 } |
53 | 56 |
54 static void RunUntilIdle(JNIEnv* env, jobject jcaller, jlong runLoopID) { | 57 static void RunUntilIdle(JNIEnv* env, |
| 58 const JavaParamRef<jobject>& jcaller, |
| 59 jlong runLoopID) { |
55 reinterpret_cast<MessageLoopHolder*>(runLoopID)->message_loop->RunUntilIdle(); | 60 reinterpret_cast<MessageLoopHolder*>(runLoopID)->message_loop->RunUntilIdle(); |
56 } | 61 } |
57 | 62 |
58 static void Quit(JNIEnv* env, jobject jcaller, jlong runLoopID) { | 63 static void Quit(JNIEnv* env, |
| 64 const JavaParamRef<jobject>& jcaller, |
| 65 jlong runLoopID) { |
59 reinterpret_cast<MessageLoopHolder*>(runLoopID)->message_loop->Quit(); | 66 reinterpret_cast<MessageLoopHolder*>(runLoopID)->message_loop->Quit(); |
60 } | 67 } |
61 | 68 |
62 static void RunJavaRunnable( | 69 static void RunJavaRunnable( |
63 const base::android::ScopedJavaGlobalRef<jobject>& runnable_ref) { | 70 const base::android::ScopedJavaGlobalRef<jobject>& runnable_ref) { |
64 Java_BaseRunLoop_runRunnable(base::android::AttachCurrentThread(), | 71 Java_BaseRunLoop_runRunnable(base::android::AttachCurrentThread(), |
65 runnable_ref.obj()); | 72 runnable_ref.obj()); |
66 } | 73 } |
67 | 74 |
68 static void PostDelayedTask(JNIEnv* env, | 75 static void PostDelayedTask(JNIEnv* env, |
69 jobject jcaller, | 76 const JavaParamRef<jobject>& jcaller, |
70 jlong runLoopID, | 77 jlong runLoopID, |
71 jobject runnable, | 78 const JavaParamRef<jobject>& runnable, |
72 jlong delay) { | 79 jlong delay) { |
73 base::android::ScopedJavaGlobalRef<jobject> runnable_ref; | 80 base::android::ScopedJavaGlobalRef<jobject> runnable_ref; |
74 // ScopedJavaGlobalRef do not hold onto the env reference, so it is safe to | 81 // ScopedJavaGlobalRef do not hold onto the env reference, so it is safe to |
75 // use it across threads. |RunJavaRunnable| will acquire a new JNIEnv before | 82 // use it across threads. |RunJavaRunnable| will acquire a new JNIEnv before |
76 // running the Runnable. | 83 // running the Runnable. |
77 runnable_ref.Reset(env, runnable); | 84 runnable_ref.Reset(env, runnable); |
78 reinterpret_cast<MessageLoopHolder*>(runLoopID) | 85 reinterpret_cast<MessageLoopHolder*>(runLoopID) |
79 ->message_loop->PostDelayedTask( | 86 ->message_loop->PostDelayedTask( |
80 FROM_HERE, base::Bind(&RunJavaRunnable, runnable_ref), | 87 FROM_HERE, base::Bind(&RunJavaRunnable, runnable_ref), |
81 base::TimeDelta::FromMicroseconds(delay)); | 88 base::TimeDelta::FromMicroseconds(delay)); |
82 } | 89 } |
83 | 90 |
84 static void DeleteMessageLoop(JNIEnv* env, jobject jcaller, jlong runLoopID) { | 91 static void DeleteMessageLoop(JNIEnv* env, |
| 92 const JavaParamRef<jobject>& jcaller, |
| 93 jlong runLoopID) { |
85 MessageLoopHolder* native_loop = | 94 MessageLoopHolder* native_loop = |
86 reinterpret_cast<MessageLoopHolder*>(runLoopID); | 95 reinterpret_cast<MessageLoopHolder*>(runLoopID); |
87 delete native_loop; | 96 delete native_loop; |
88 } | 97 } |
89 | 98 |
90 bool RegisterBaseRunLoop(JNIEnv* env) { | 99 bool RegisterBaseRunLoop(JNIEnv* env) { |
91 return RegisterNativesImpl(env); | 100 return RegisterNativesImpl(env); |
92 } | 101 } |
93 | 102 |
94 } // namespace android | 103 } // namespace android |
95 } // namespace mojo | 104 } // namespace mojo |
96 | |
97 | |
OLD | NEW |