OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/message_loop/message_pump_android.h" | 5 #include "base/message_loop/message_pump_android.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "jni/SystemMessageHandler_jni.h" | 16 #include "jni/SystemMessageHandler_jni.h" |
16 | 17 |
17 using base::android::ScopedJavaLocalRef; | 18 using base::android::ScopedJavaLocalRef; |
18 | 19 |
19 // ---------------------------------------------------------------------------- | 20 // ---------------------------------------------------------------------------- |
20 // Native JNI methods called by Java. | 21 // Native JNI methods called by Java. |
21 // ---------------------------------------------------------------------------- | 22 // ---------------------------------------------------------------------------- |
22 // This method can not move to anonymous namespace as it has been declared as | 23 // This method can not move to anonymous namespace as it has been declared as |
23 // 'static' in system_message_handler_jni.h. | 24 // 'static' in system_message_handler_jni.h. |
24 static void DoRunLoopOnce(JNIEnv* env, jobject obj, jint native_delegate) { | 25 static void DoRunLoopOnce( |
| 26 JNIEnv* env, |
| 27 jobject obj, |
| 28 jint native_delegate, |
| 29 jint native_message_loop) { |
| 30 base::MessageLoop* message_loop = |
| 31 reinterpret_cast<base::MessageLoop*>(native_message_loop); |
| 32 if (message_loop != base::MessageLoop::current()) |
| 33 return; |
| 34 |
25 base::MessagePump::Delegate* delegate = | 35 base::MessagePump::Delegate* delegate = |
26 reinterpret_cast<base::MessagePump::Delegate*>(native_delegate); | 36 reinterpret_cast<base::MessagePump::Delegate*>(native_delegate); |
27 DCHECK(delegate); | 37 DCHECK(delegate); |
28 // This is based on MessagePumpForUI::DoRunLoop() from desktop. | 38 // This is based on MessagePumpForUI::DoRunLoop() from desktop. |
29 // Note however that our system queue is handled in the java side. | 39 // Note however that our system queue is handled in the java side. |
30 // In desktop we inspect and process a single system message and then | 40 // In desktop we inspect and process a single system message and then |
31 // we call DoWork() / DoDelayedWork(). | 41 // we call DoWork() / DoDelayedWork(). |
32 // On Android, the java message queue may contain messages for other handlers | 42 // On Android, the java message queue may contain messages for other handlers |
33 // that will be processed before calling here again. | 43 // that will be processed before calling here again. |
34 bool did_work = delegate->DoWork(); | 44 bool did_work = delegate->DoWork(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // return true (it only returns false if the RunLoop has been Quit already). | 84 // return true (it only returns false if the RunLoop has been Quit already). |
75 if (!run_loop_->BeforeRun()) | 85 if (!run_loop_->BeforeRun()) |
76 NOTREACHED(); | 86 NOTREACHED(); |
77 | 87 |
78 DCHECK(system_message_handler_obj_.is_null()); | 88 DCHECK(system_message_handler_obj_.is_null()); |
79 | 89 |
80 JNIEnv* env = base::android::AttachCurrentThread(); | 90 JNIEnv* env = base::android::AttachCurrentThread(); |
81 DCHECK(env); | 91 DCHECK(env); |
82 | 92 |
83 system_message_handler_obj_.Reset( | 93 system_message_handler_obj_.Reset( |
84 Java_SystemMessageHandler_create(env, reinterpret_cast<jint>(delegate))); | 94 Java_SystemMessageHandler_create(env, reinterpret_cast<jint>(delegate), |
| 95 reinterpret_cast<jint>(MessageLoop::current()))); |
85 } | 96 } |
86 | 97 |
87 void MessagePumpForUI::Quit() { | 98 void MessagePumpForUI::Quit() { |
88 if (!system_message_handler_obj_.is_null()) { | 99 if (!system_message_handler_obj_.is_null()) { |
89 JNIEnv* env = base::android::AttachCurrentThread(); | 100 JNIEnv* env = base::android::AttachCurrentThread(); |
90 DCHECK(env); | 101 DCHECK(env); |
91 | 102 |
92 Java_SystemMessageHandler_removeTimer(env, | 103 Java_SystemMessageHandler_removeTimer(env, |
93 system_message_handler_obj_.obj()); | 104 system_message_handler_obj_.obj()); |
94 system_message_handler_obj_.Reset(); | 105 system_message_handler_obj_.Reset(); |
(...skipping 29 matching lines...) Expand all Loading... |
124 Java_SystemMessageHandler_setDelayedTimer(env, | 135 Java_SystemMessageHandler_setDelayedTimer(env, |
125 system_message_handler_obj_.obj(), millis); | 136 system_message_handler_obj_.obj(), millis); |
126 } | 137 } |
127 | 138 |
128 // static | 139 // static |
129 bool MessagePumpForUI::RegisterBindings(JNIEnv* env) { | 140 bool MessagePumpForUI::RegisterBindings(JNIEnv* env) { |
130 return RegisterNativesImpl(env); | 141 return RegisterNativesImpl(env); |
131 } | 142 } |
132 | 143 |
133 } // namespace base | 144 } // namespace base |
OLD | NEW |