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

Side by Side Diff: base/android/jni_generator/golden_sample_for_tests_jni.h

Issue 11038015: Android: lazy initialization for method id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removes EXCEPTIONCHECK. Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // This file is autogenerated by 5 // This file is autogenerated by
6 // base/android/jni_generator/jni_generator_tests.py 6 // base/android/jni_generator/jni_generator_tests.py
7 // For 7 // For
8 // org/chromium/example/jni_generator/SampleForTests 8 // org/chromium/example/jni_generator/SampleForTests
9 9
10 #ifndef org_chromium_example_jni_generator_SampleForTests_JNI 10 #ifndef org_chromium_example_jni_generator_SampleForTests_JNI
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 jint nativeCPPClass) { 59 jint nativeCPPClass) {
60 DCHECK(nativeCPPClass) << "Method"; 60 DCHECK(nativeCPPClass) << "Method";
61 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); 61 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
62 return native->Method(env, obj); 62 return native->Method(env, obj);
63 } 63 }
64 64
65 static jdouble MethodOtherP0(JNIEnv* env, jobject obj, 65 static jdouble MethodOtherP0(JNIEnv* env, jobject obj,
66 jint nativePtr) { 66 jint nativePtr) {
67 DCHECK(nativePtr) << "MethodOtherP0"; 67 DCHECK(nativePtr) << "MethodOtherP0";
68 CPPClass::InnerClass* native = 68 CPPClass::InnerClass* native =
69 reinterpret_cast<CPPClass::InnerClass*>(nativePtr); 69 reinterpret_cast<CPPClass::InnerClass*>(nativePtr);
70 return native->MethodOtherP0(env, obj); 70 return native->MethodOtherP0(env, obj);
71 } 71 }
72 72
73 static jstring InnerMethod(JNIEnv* env, jobject obj, 73 static jstring InnerMethod(JNIEnv* env, jobject obj,
74 jint nativeCPPClass) { 74 jint nativeCPPClass) {
75 DCHECK(nativeCPPClass) << "InnerMethod"; 75 DCHECK(nativeCPPClass) << "InnerMethod";
76 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); 76 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
77 return native->InnerMethod(env, obj).Release(); 77 return native->InnerMethod(env, obj).Release();
78 } 78 }
79 79
80 static jmethodID g_SampleForTests_javaMethod = 0; 80 static base::subtle::AtomicWord g_SampleForTests_javaMethod = 0;
81 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj, jint foo, 81 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj, jint foo,
82 jint bar) { 82 jint bar) {
83 /* Must call RegisterNativesImpl() */ 83 /* Must call RegisterNativesImpl() */
84 DCHECK(g_SampleForTests_clazz); 84 DCHECK(g_SampleForTests_clazz);
85 DCHECK(g_SampleForTests_javaMethod); 85 jmethodID method_id =
86 jint ret = 86 base::android::MethodID::LazyGet<
87 env->CallIntMethod(obj, 87 base::android::MethodID::METHODTYPE_NORMAL>(
88 g_SampleForTests_javaMethod, foo, bar); 88 env, g_SampleForTests_clazz,
89 base::android::CheckException(env); 89 "javaMethod",
90 return ret;
91 }
92
93 static jmethodID g_SampleForTests_staticJavaMethod = 0;
94 static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) {
95 /* Must call RegisterNativesImpl() */
96 DCHECK(g_SampleForTests_clazz);
97 DCHECK(g_SampleForTests_staticJavaMethod);
98 jboolean ret =
99 env->CallStaticBooleanMethod(g_SampleForTests_clazz,
100 g_SampleForTests_staticJavaMethod);
101 base::android::CheckException(env);
102 return ret;
103 }
104
105 static jmethodID g_SampleForTests_packagePrivateJavaMethod = 0;
106 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject
107 obj) {
108 /* Must call RegisterNativesImpl() */
109 DCHECK(g_SampleForTests_clazz);
110 DCHECK(g_SampleForTests_packagePrivateJavaMethod);
111
112 env->CallVoidMethod(obj,
113 g_SampleForTests_packagePrivateJavaMethod);
114 base::android::CheckException(env);
115
116 }
117
118 static jmethodID g_SampleForTests_methodThatThrowsException = 0;
119 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject
120 obj) {
121 /* Must call RegisterNativesImpl() */
122 DCHECK(g_SampleForTests_clazz);
123 DCHECK(g_SampleForTests_methodThatThrowsException);
124
125 env->CallVoidMethod(obj,
126 g_SampleForTests_methodThatThrowsException);
127
128 }
129
130 static jmethodID g_InnerClass_JavaInnerMethod = 0;
131 static jfloat Java_InnerClass_JavaInnerMethod(JNIEnv* env, jobject obj) {
132 /* Must call RegisterNativesImpl() */
133 DCHECK(g_InnerClass_clazz);
134 DCHECK(g_InnerClass_JavaInnerMethod);
135 jfloat ret =
136 env->CallFloatMethod(obj,
137 g_InnerClass_JavaInnerMethod);
138 base::android::CheckException(env);
139 return ret;
140 }
141
142 static jmethodID g_InnerClass_javaInnerFunction = 0;
143 static void Java_InnerClass_javaInnerFunction(JNIEnv* env) {
144 /* Must call RegisterNativesImpl() */
145 DCHECK(g_InnerClass_clazz);
146 DCHECK(g_InnerClass_javaInnerFunction);
147
148 env->CallStaticVoidMethod(g_InnerClass_clazz,
149 g_InnerClass_javaInnerFunction);
150 base::android::CheckException(env);
151
152 }
153
154 // Step 3: GetMethodIDs and RegisterNatives.
155 static void GetMethodIDsImpl(JNIEnv* env) {
156 g_InnerClass_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
157 base::android::GetUnscopedClass(env, kInnerClassClassPath)));
158 g_SampleForTests_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
159 base::android::GetUnscopedClass(env, kSampleForTestsClassPath)));
160 g_SampleForTests_javaMethod =
161 base::android::GetMethodID(
162 env, g_SampleForTests_clazz,
163 "javaMethod",
164 90
165 "(" 91 "("
166 "I" 92 "I"
167 "I" 93 "I"
168 ")" 94 ")"
169 "I"); 95 "I",
96 &g_SampleForTests_javaMethod);
170 97
171 g_SampleForTests_staticJavaMethod = 98 jint ret =
172 base::android::GetStaticMethodID( 99 env->CallIntMethod(obj,
173 env, g_SampleForTests_clazz, 100 method_id, foo, bar);
174 "staticJavaMethod", 101 base::android::CheckException(env);
102 return ret;
103 }
104
105 static base::subtle::AtomicWord g_SampleForTests_staticJavaMethod = 0;
106 static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) {
107 /* Must call RegisterNativesImpl() */
108 DCHECK(g_SampleForTests_clazz);
109 jmethodID method_id =
110 base::android::MethodID::LazyGet<
111 base::android::MethodID::METHODTYPE_STATIC>(
112 env, g_SampleForTests_clazz,
113 "staticJavaMethod",
175 114
176 "(" 115 "("
177 ")" 116 ")"
178 "Z"); 117 "Z",
118 &g_SampleForTests_staticJavaMethod);
179 119
180 g_SampleForTests_packagePrivateJavaMethod = 120 jboolean ret =
181 base::android::GetMethodID( 121 env->CallStaticBooleanMethod(g_SampleForTests_clazz,
182 env, g_SampleForTests_clazz, 122 method_id);
183 "packagePrivateJavaMethod", 123 base::android::CheckException(env);
124 return ret;
125 }
126
127 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod = 0;
128 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject
129 obj) {
130 /* Must call RegisterNativesImpl() */
131 DCHECK(g_SampleForTests_clazz);
132 jmethodID method_id =
133 base::android::MethodID::LazyGet<
134 base::android::MethodID::METHODTYPE_NORMAL>(
135 env, g_SampleForTests_clazz,
136 "packagePrivateJavaMethod",
184 137
185 "(" 138 "("
186 ")" 139 ")"
187 "V"); 140 "V",
141 &g_SampleForTests_packagePrivateJavaMethod);
188 142
189 g_SampleForTests_methodThatThrowsException = 143 env->CallVoidMethod(obj,
190 base::android::GetMethodID( 144 method_id);
191 env, g_SampleForTests_clazz, 145 base::android::CheckException(env);
192 "methodThatThrowsException", 146
147 }
148
149 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException = 0;
150 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject
151 obj) {
152 /* Must call RegisterNativesImpl() */
153 DCHECK(g_SampleForTests_clazz);
154 jmethodID method_id =
155 base::android::MethodID::LazyGet<
156 base::android::MethodID::METHODTYPE_NORMAL>(
157 env, g_SampleForTests_clazz,
158 "methodThatThrowsException",
193 159
194 "(" 160 "("
195 ")" 161 ")"
196 "V"); 162 "V",
163 &g_SampleForTests_methodThatThrowsException);
197 164
198 g_InnerClass_JavaInnerMethod = 165 env->CallVoidMethod(obj,
199 base::android::GetMethodID( 166 method_id);
200 env, g_InnerClass_clazz, 167
201 "JavaInnerMethod", 168 }
169
170 static base::subtle::AtomicWord g_InnerClass_JavaInnerMethod = 0;
171 static jfloat Java_InnerClass_JavaInnerMethod(JNIEnv* env, jobject obj) {
172 /* Must call RegisterNativesImpl() */
173 DCHECK(g_InnerClass_clazz);
174 jmethodID method_id =
175 base::android::MethodID::LazyGet<
176 base::android::MethodID::METHODTYPE_NORMAL>(
177 env, g_InnerClass_clazz,
178 "JavaInnerMethod",
202 179
203 "(" 180 "("
204 ")" 181 ")"
205 "F"); 182 "F",
183 &g_InnerClass_JavaInnerMethod);
206 184
207 g_InnerClass_javaInnerFunction = 185 jfloat ret =
208 base::android::GetStaticMethodID( 186 env->CallFloatMethod(obj,
209 env, g_InnerClass_clazz, 187 method_id);
210 "javaInnerFunction", 188 base::android::CheckException(env);
189 return ret;
190 }
191
192 static base::subtle::AtomicWord g_InnerClass_javaInnerFunction = 0;
193 static void Java_InnerClass_javaInnerFunction(JNIEnv* env) {
194 /* Must call RegisterNativesImpl() */
195 DCHECK(g_InnerClass_clazz);
196 jmethodID method_id =
197 base::android::MethodID::LazyGet<
198 base::android::MethodID::METHODTYPE_STATIC>(
199 env, g_InnerClass_clazz,
200 "javaInnerFunction",
211 201
212 "(" 202 "("
213 ")" 203 ")"
214 "V"); 204 "V",
205 &g_InnerClass_javaInnerFunction);
206
207 env->CallStaticVoidMethod(g_InnerClass_clazz,
208 method_id);
209 base::android::CheckException(env);
215 210
216 } 211 }
217 212
213 // Step 3: RegisterNatives.
214
218 static bool RegisterNativesImpl(JNIEnv* env) { 215 static bool RegisterNativesImpl(JNIEnv* env) {
219 GetMethodIDsImpl(env);
220 216
217 g_InnerClass_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
218 base::android::GetUnscopedClass(env, kInnerClassClassPath)));
219 g_SampleForTests_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
220 base::android::GetUnscopedClass(env, kSampleForTestsClassPath)));
221 static const JNINativeMethod kMethodsInnerClass[] = { 221 static const JNINativeMethod kMethodsInnerClass[] = {
222 { "nativeInnerFunction", 222 { "nativeInnerFunction",
223 "(" 223 "("
224 ")" 224 ")"
225 "I", reinterpret_cast<void*>(InnerFunction) }, 225 "I", reinterpret_cast<void*>(InnerFunction) },
226 { "nativeInnerMethod", 226 { "nativeInnerMethod",
227 "(" 227 "("
228 "I" 228 "I"
229 ")" 229 ")"
230 "Ljava/lang/String;", reinterpret_cast<void*>(InnerMethod) }, 230 "Ljava/lang/String;", reinterpret_cast<void*>(InnerMethod) },
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; 284 LOG(ERROR) << "RegisterNatives failed in " << __FILE__;
285 return false; 285 return false;
286 } 286 }
287 287
288 return true; 288 return true;
289 } 289 }
290 } // namespace android 290 } // namespace android
291 } // namespace base 291 } // namespace base
292 292
293 #endif // org_chromium_example_jni_generator_SampleForTests_JNI 293 #endif // org_chromium_example_jni_generator_SampleForTests_JNI
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698