| OLD | NEW |
| 1 // Copyright (c) 2012 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 #if __clang__ |
| 23 #pragma clang diagnostic push |
| 24 #pragma clang diagnostic ignored "-Wunused-function" |
| 25 #endif |
| 22 // Leaking this jclass as we cannot use LazyInstance from some threads. | 26 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 23 jclass g_Foo_clazz = NULL; | 27 jclass g_Foo_clazz = NULL; |
| 28 jclass Foo_clazz(JNIEnv*) { return g_Foo_clazz; } |
| 29 #if __clang__ |
| 30 #pragma clang diagnostic pop |
| 31 #endif |
| 24 | 32 |
| 25 } // namespace | 33 } // namespace |
| 26 | 34 |
| 27 static void DoSomething(JNIEnv* env, jclass jcaller, | 35 static void DoSomething(JNIEnv* env, jclass jcaller, |
| 28 jobject callback); | 36 jobject callback); |
| 29 | 37 |
| 30 // Step 2: method stubs. | 38 // Step 2: method stubs. |
| 31 | 39 |
| 32 static base::subtle::AtomicWord g_Foo_calledByNative = 0; | 40 static base::subtle::AtomicWord g_Foo_calledByNative = 0; |
| 33 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { | 41 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { |
| 34 /* Must call RegisterNativesImpl() */ | 42 /* Must call RegisterNativesImpl() */ |
| 35 CHECK_CLAZZ(env, g_Foo_clazz, | 43 CHECK_CLAZZ(env, Foo_clazz(env), |
| 36 g_Foo_clazz); | 44 Foo_clazz(env)); |
| 37 jmethodID method_id = | 45 jmethodID method_id = |
| 38 base::android::MethodID::LazyGet< | 46 base::android::MethodID::LazyGet< |
| 39 base::android::MethodID::TYPE_STATIC>( | 47 base::android::MethodID::TYPE_STATIC>( |
| 40 env, g_Foo_clazz, | 48 env, Foo_clazz(env), |
| 41 "calledByNative", | 49 "calledByNative", |
| 42 | 50 |
| 43 "(" | 51 "(" |
| 44 "Lorg/chromium/foo/Bar$Callback;" | 52 "Lorg/chromium/foo/Bar$Callback;" |
| 45 ")" | 53 ")" |
| 46 "V", | 54 "V", |
| 47 &g_Foo_calledByNative); | 55 &g_Foo_calledByNative); |
| 48 | 56 |
| 49 env->CallStaticVoidMethod(g_Foo_clazz, | 57 env->CallStaticVoidMethod(Foo_clazz(env), |
| 50 method_id, callback); | 58 method_id, callback); |
| 51 jni_generator::CheckException(env); | 59 jni_generator::CheckException(env); |
| 52 | 60 |
| 53 } | 61 } |
| 54 | 62 |
| 55 // Step 3: RegisterNatives. | 63 // Step 3: RegisterNatives. |
| 56 | 64 |
| 57 static const JNINativeMethod kMethodsFoo[] = { | 65 static const JNINativeMethod kMethodsFoo[] = { |
| 58 { "nativeDoSomething", | 66 { "nativeDoSomething", |
| 59 "(" | 67 "(" |
| 60 "Lorg/chromium/foo/Bar$Callback;" | 68 "Lorg/chromium/foo/Bar$Callback;" |
| 61 ")" | 69 ")" |
| 62 "V", reinterpret_cast<void*>(DoSomething) }, | 70 "V", reinterpret_cast<void*>(DoSomething) }, |
| 63 }; | 71 }; |
| 64 | 72 |
| 65 static bool RegisterNativesImpl(JNIEnv* env) { | 73 static bool RegisterNativesImpl(JNIEnv* env) { |
| 66 g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | 74 g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 67 base::android::GetClass(env, kFooClassPath).obj())); | 75 base::android::GetClass(env, kFooClassPath).obj())); |
| 68 | 76 |
| 69 const int kMethodsFooSize = arraysize(kMethodsFoo); | 77 const int kMethodsFooSize = arraysize(kMethodsFoo); |
| 70 | 78 |
| 71 if (env->RegisterNatives(g_Foo_clazz, | 79 if (env->RegisterNatives(Foo_clazz(env), |
| 72 kMethodsFoo, | 80 kMethodsFoo, |
| 73 kMethodsFooSize) < 0) { | 81 kMethodsFooSize) < 0) { |
| 74 jni_generator::HandleRegistrationError( | 82 jni_generator::HandleRegistrationError( |
| 75 env, g_Foo_clazz, __FILE__); | 83 env, Foo_clazz(env), __FILE__); |
| 76 return false; | 84 return false; |
| 77 } | 85 } |
| 78 | 86 |
| 79 return true; | 87 return true; |
| 80 } | 88 } |
| 81 | 89 |
| 82 #endif // org_chromium_foo_Foo_JNI | 90 #endif // org_chromium_foo_Foo_JNI |
| OLD | NEW |