OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_pump_android.h" | 5 #include "base/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/logging.h" | 10 #include "base/logging.h" |
11 #include "jni/system_message_handler_jni.h" | 11 #include "jni/system_message_handler_jni.h" |
12 | 12 |
13 using base::android::AutoJObject; | 13 using base::android::ScopedJavaReference; |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 const char* kClassPathName = "com/android/chromeview/base/SystemMessageHandler"; | 17 const char* kClassPathName = "com/android/chromeview/base/SystemMessageHandler"; |
18 | 18 |
19 jobject g_system_message_handler_obj = NULL; | 19 jobject g_system_message_handler_obj = NULL; |
20 | 20 |
21 } // namespace | 21 } // namespace |
22 | 22 |
23 // ---------------------------------------------------------------------------- | 23 // ---------------------------------------------------------------------------- |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 void MessagePumpForUI::Start(Delegate* delegate) { | 75 void MessagePumpForUI::Start(Delegate* delegate) { |
76 state_ = new MessageLoop::AutoRunState(MessageLoop::current()); | 76 state_ = new MessageLoop::AutoRunState(MessageLoop::current()); |
77 | 77 |
78 DCHECK(!g_system_message_handler_obj); | 78 DCHECK(!g_system_message_handler_obj); |
79 | 79 |
80 JNIEnv* env = base::android::AttachCurrentThread(); | 80 JNIEnv* env = base::android::AttachCurrentThread(); |
81 DCHECK(env); | 81 DCHECK(env); |
82 | 82 |
83 jclass clazz = env->FindClass(kClassPathName); | 83 jclass clazz = env->FindClass(kClassPathName); |
84 DCHECK(!clazz); | 84 DCHECK(clazz); |
85 | 85 |
86 jmethodID constructor = base::android::GetMethodID(env, clazz, "<init>", | 86 jmethodID constructor = base::android::GetMethodID(env, clazz, "<init>", |
87 "(I)V"); | 87 "(I)V"); |
88 AutoJObject client = AutoJObject::FromLocalRef( | 88 ScopedJavaReference<jobject> client(env, env->NewObject(clazz, constructor, |
89 env, env->NewObject(clazz, constructor, delegate)); | 89 delegate)); |
90 DCHECK(!client.obj()); | 90 DCHECK(client.obj()); |
91 | 91 |
92 g_system_message_handler_obj = env->NewGlobalRef(client.obj()); | 92 g_system_message_handler_obj = env->NewGlobalRef(client.obj()); |
93 | 93 |
94 base::android::CheckException(env); | 94 base::android::CheckException(env); |
95 } | 95 } |
96 | 96 |
97 void MessagePumpForUI::Quit() { | 97 void MessagePumpForUI::Quit() { |
98 if (g_system_message_handler_obj) { | 98 if (g_system_message_handler_obj) { |
99 JNIEnv* env = base::android::AttachCurrentThread(); | 99 JNIEnv* env = base::android::AttachCurrentThread(); |
100 DCHECK(env); | 100 DCHECK(env); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 millis); | 138 millis); |
139 base::android::CheckException(env); | 139 base::android::CheckException(env); |
140 } | 140 } |
141 | 141 |
142 // Register native methods | 142 // Register native methods |
143 bool RegisterSystemMessageHandler(JNIEnv* env) { | 143 bool RegisterSystemMessageHandler(JNIEnv* env) { |
144 return RegisterNativesImpl(env); | 144 return RegisterNativesImpl(env); |
145 } | 145 } |
146 | 146 |
147 } // namespace base | 147 } // namespace base |
OLD | NEW |