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
3 // found in the LICENSE file.
5 // This file is autogenerated by
6 // base/android/jni_generator/jni_generator.py
8 // org/chromium/foo/Foo
10 #ifndef org_chromium_foo_Foo_JNI
11 #define org_chromium_foo_Foo_JNI
15 #include "base/android/jni_generator/jni_generator_helper.h"
17 #include "base/android/jni_int_wrapper.h"
19 // Step 1: forward declarations.
21 const char kFooClassPath[] = "org/chromium/foo/Foo";
22 // Leaking this jclass as we cannot use LazyInstance from some threads.
23 jclass g_Foo_clazz = NULL;
24 #define Foo_clazz(env) g_Foo_clazz
28 // Step 2: method stubs.
30 static void DoSomething(JNIEnv* env, const JavaParamRef<jclass>& jcaller,
31 const JavaParamRef<jobject>& callback);
33 static void Java_org_chromium_foo_Foo_nativeDoSomething(JNIEnv* env, jclass
36 return DoSomething(env, JavaParamRef<jclass>(env, jcaller),
37 JavaParamRef<jobject>(env, callback));
40 static base::subtle::AtomicWord g_Foo_calledByNative = 0;
41 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) {
42 /* Must call RegisterNativesImpl() */
43 CHECK_CLAZZ(env, Foo_clazz(env),
46 base::android::MethodID::LazyGet<
47 base::android::MethodID::TYPE_STATIC>(
52 "Lorg/chromium/foo/Bar$Callback;"
55 &g_Foo_calledByNative);
57 env->CallStaticVoidMethod(Foo_clazz(env),
59 jni_generator::CheckException(env);
63 // Step 3: RegisterNatives.
65 static const JNINativeMethod kMethodsFoo[] = {
66 { "nativeDoSomething",
68 "Lorg/chromium/foo/Bar$Callback;"
70 "V", reinterpret_cast<void*>(Java_org_chromium_foo_Foo_nativeDoSomething) },
73 static bool RegisterNativesImpl(JNIEnv* env) {
75 g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
76 base::android::GetClass(env, kFooClassPath).obj()));
78 const int kMethodsFooSize = arraysize(kMethodsFoo);
80 if (env->RegisterNatives(Foo_clazz(env),
82 kMethodsFooSize) < 0) {
83 jni_generator::HandleRegistrationError(
84 env, Foo_clazz(env), __FILE__);
91 #endif // org_chromium_foo_Foo_JNI