| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.py | 6 // base/android/jni_generator/jni_generator.py |
| 7 // For | 7 // For |
| 8 // org/chromium/foo/Foo | 8 // org/chromium/foo/Foo |
| 9 | 9 |
| 10 #ifndef org_chromium_foo_Foo_JNI | 10 #ifndef org_chromium_foo_Foo_JNI |
| 11 #define org_chromium_foo_Foo_JNI | 11 #define org_chromium_foo_Foo_JNI |
| 12 | 12 |
| 13 #include <jni.h> | 13 #include <jni.h> |
| 14 | 14 |
| 15 #include "base/android/jni_generator/jni_generator_helper.h" | 15 #include "base/android/jni_generator/jni_generator_helper.h" |
| 16 | 16 |
| 17 #include "base/android/jni_int_wrapper.h" | 17 #include "base/android/jni_int_wrapper.h" |
| 18 | 18 |
| 19 // Step 1: forward declarations. | 19 // Step 1: forward declarations. |
| 20 namespace { | 20 namespace { |
| 21 const char kFooClassPath[] = "org/chromium/foo/Foo"; | 21 const char kFooClassPath[] = "org/chromium/foo/Foo"; |
| 22 // Leaking this jclass as we cannot use LazyInstance from some threads. | 22 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 23 jclass g_Foo_clazz = NULL; | 23 base::subtle::AtomicWord g_Foo_clazz __attribute__((unused)) = 0; |
| 24 #define Foo_clazz(env) g_Foo_clazz | 24 #define Foo_clazz(env) base::android::LazyGetClass(env, kFooClassPath, &g_Foo_cl
azz) |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 // Step 2: method stubs. | 28 // Step 2: method stubs. |
| 29 | 29 |
| 30 static void DoSomething(JNIEnv* env, const JavaParamRef<jclass>& jcaller, | 30 static void DoSomething(JNIEnv* env, const JavaParamRef<jclass>& jcaller, |
| 31 const JavaParamRef<jobject>& callback); | 31 const JavaParamRef<jobject>& callback); |
| 32 | 32 |
| 33 static void Java_org_chromium_foo_Foo_nativeDoSomething(JNIEnv* env, jclass | 33 extern "C" __attribute__((visibility("default"))) |
| 34 jcaller, | 34 void Java_org_chromium_foo_Foo_nativeDoSomething(JNIEnv* env, jclass jcaller, |
| 35 jobject callback) { | 35 jobject callback) { |
| 36 return DoSomething(env, JavaParamRef<jclass>(env, jcaller), | 36 return DoSomething(env, JavaParamRef<jclass>(env, jcaller), |
| 37 JavaParamRef<jobject>(env, callback)); | 37 JavaParamRef<jobject>(env, callback)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 static base::subtle::AtomicWord g_Foo_calledByNative = 0; | 40 static base::subtle::AtomicWord g_Foo_calledByNative = 0; |
| 41 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { | 41 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { |
| 42 /* Must call RegisterNativesImpl() */ | 42 /* Must call RegisterNativesImpl() */ |
| 43 CHECK_CLAZZ(env, Foo_clazz(env), | 43 CHECK_CLAZZ(env, Foo_clazz(env), |
| 44 Foo_clazz(env)); | 44 Foo_clazz(env)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 64 | 64 |
| 65 static const JNINativeMethod kMethodsFoo[] = { | 65 static const JNINativeMethod kMethodsFoo[] = { |
| 66 { "nativeDoSomething", | 66 { "nativeDoSomething", |
| 67 "(" | 67 "(" |
| 68 "Lorg/chromium/foo/Bar$Callback;" | 68 "Lorg/chromium/foo/Bar$Callback;" |
| 69 ")" | 69 ")" |
| 70 "V", reinterpret_cast<void*>(Java_org_chromium_foo_Foo_nativeDoSomething) }, | 70 "V", reinterpret_cast<void*>(Java_org_chromium_foo_Foo_nativeDoSomething) }, |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 static bool RegisterNativesImpl(JNIEnv* env) { | 73 static bool RegisterNativesImpl(JNIEnv* env) { |
| 74 | 74 if (base::android::IsManualJniRegistrationDisabled()) return true; |
| 75 g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
| 76 base::android::GetClass(env, kFooClassPath).obj())); | |
| 77 | 75 |
| 78 const int kMethodsFooSize = arraysize(kMethodsFoo); | 76 const int kMethodsFooSize = arraysize(kMethodsFoo); |
| 79 | 77 |
| 80 if (env->RegisterNatives(Foo_clazz(env), | 78 if (env->RegisterNatives(Foo_clazz(env), |
| 81 kMethodsFoo, | 79 kMethodsFoo, |
| 82 kMethodsFooSize) < 0) { | 80 kMethodsFooSize) < 0) { |
| 83 jni_generator::HandleRegistrationError( | 81 jni_generator::HandleRegistrationError( |
| 84 env, Foo_clazz(env), __FILE__); | 82 env, Foo_clazz(env), __FILE__); |
| 85 return false; | 83 return false; |
| 86 } | 84 } |
| 87 | 85 |
| 88 return true; | 86 return true; |
| 89 } | 87 } |
| 90 | 88 |
| 91 #endif // org_chromium_foo_Foo_JNI | 89 #endif // org_chromium_foo_Foo_JNI |
| OLD | NEW |