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
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;
27 static void DoSomething(JNIEnv* env, jclass jcaller,
31 // Step 2: method stubs.
33 static base::subtle::AtomicWord g_Foo_calledByNative = 0;
34 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback1,
36 /* Must call RegisterNativesImpl() */
37 CHECK_CLAZZ(env, g_Foo_clazz,
40 base::android::MethodID::LazyGet<
41 base::android::MethodID::TYPE_STATIC>(
46 "Lorg/chromium/foo/Bar1$Callback;"
47 "Lorg/chromium/foo/Bar2$Callback;"
50 &g_Foo_calledByNative);
52 env->CallStaticVoidMethod(g_Foo_clazz,
53 method_id, callback1, callback2);
54 jni_generator::CheckException(env);
58 // Step 3: RegisterNatives.
60 static const JNINativeMethod kMethodsFoo[] = {
61 { "nativeDoSomething",
63 "Lorg/chromium/foo/Bar1$Callback;"
64 "Lorg/chromium/foo/Bar2$Callback;"
66 "V", reinterpret_cast<void*>(DoSomething) },
69 static bool RegisterNativesImpl(JNIEnv* env) {
70 g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
71 base::android::GetClass(env, kFooClassPath).obj()));
73 const int kMethodsFooSize = arraysize(kMethodsFoo);
75 if (env->RegisterNatives(g_Foo_clazz,
77 kMethodsFooSize) < 0) {
78 jni_generator::HandleRegistrationError(
79 env, g_Foo_clazz, __FILE__);
86 #endif // org_chromium_foo_Foo_JNI