|  | // Copyright 2014 The Chromium Authors. All rights reserved. | 
|  | // Use of this source code is governed by a BSD-style license that can be | 
|  | // found in the LICENSE file. | 
|  |  | 
|  | // This file is autogenerated by | 
|  | //     base/android/jni_generator/jni_generator.py | 
|  | // For | 
|  | //     org/chromium/foo/Foo | 
|  |  | 
|  | #ifndef org_chromium_foo_Foo_JNI | 
|  | #define org_chromium_foo_Foo_JNI | 
|  |  | 
|  | #include <jni.h> | 
|  |  | 
|  | #include "base/android/jni_generator/jni_generator_helper.h" | 
|  |  | 
|  | #include "base/android/jni_int_wrapper.h" | 
|  |  | 
|  | // Step 1: forward declarations. | 
|  | namespace { | 
|  | const char kFooClassPath[] = "org/chromium/foo/Foo"; | 
|  | // Leaking this jclass as we cannot use LazyInstance from some threads. | 
|  | jclass g_Foo_clazz = NULL; | 
|  | #define Foo_clazz(env) g_Foo_clazz | 
|  |  | 
|  | }  // namespace | 
|  |  | 
|  | static void DoSomething(JNIEnv* env, jclass jcaller, | 
|  | jobject callback); | 
|  |  | 
|  | // Step 2: method stubs. | 
|  |  | 
|  | static base::subtle::AtomicWord g_Foo_calledByNative = 0; | 
|  | static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { | 
|  | /* Must call RegisterNativesImpl()  */ | 
|  | CHECK_CLAZZ(env, Foo_clazz(env), | 
|  | Foo_clazz(env)); | 
|  | jmethodID method_id = | 
|  | base::android::MethodID::LazyGet< | 
|  | base::android::MethodID::TYPE_STATIC>( | 
|  | env, Foo_clazz(env), | 
|  | "calledByNative", | 
|  |  | 
|  | "(" | 
|  | "Lorg/chromium/foo/Bar$Callback;" | 
|  | ")" | 
|  | "V", | 
|  | &g_Foo_calledByNative); | 
|  |  | 
|  | env->CallStaticVoidMethod(Foo_clazz(env), | 
|  | method_id, callback); | 
|  | jni_generator::CheckException(env); | 
|  |  | 
|  | } | 
|  |  | 
|  | // Step 3: RegisterNatives. | 
|  |  | 
|  | static const JNINativeMethod kMethodsFoo[] = { | 
|  | { "nativeDoSomething", | 
|  | "(" | 
|  | "Lorg/chromium/foo/Bar$Callback;" | 
|  | ")" | 
|  | "V", reinterpret_cast<void*>(DoSomething) }, | 
|  | }; | 
|  |  | 
|  | static bool RegisterNativesImpl(JNIEnv* env) { | 
|  | g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | 
|  | base::android::GetClass(env, kFooClassPath).obj())); | 
|  |  | 
|  | const int kMethodsFooSize = arraysize(kMethodsFoo); | 
|  |  | 
|  | if (env->RegisterNatives(Foo_clazz(env), | 
|  | kMethodsFoo, | 
|  | kMethodsFooSize) < 0) { | 
|  | jni_generator::HandleRegistrationError( | 
|  | env, Foo_clazz(env), __FILE__); | 
|  | return false; | 
|  | } | 
|  |  | 
|  | return true; | 
|  | } | 
|  |  | 
|  | #endif  // org_chromium_foo_Foo_JNI |