| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 // This file is autogenerated by | |
| 6 // base/android/jni_generator/jni_generator.py | |
| 7 // For | |
| 8 // org/chromium/foo/Foo | |
| 9 | |
| 10 #ifndef org_chromium_foo_Foo_JNI | |
| 11 #define org_chromium_foo_Foo_JNI | |
| 12 | |
| 13 #include <jni.h> | |
| 14 | |
| 15 #include "base/android/jni_generator/jni_generator_helper.h" | |
| 16 | |
| 17 #include "base/android/jni_int_wrapper.h" | |
| 18 | |
| 19 // Step 1: forward declarations. | |
| 20 namespace { | |
| 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 | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 static void DoSomething(JNIEnv* env, jclass jcaller, | |
| 29 jobject callback); | |
| 30 | |
| 31 // Step 2: method stubs. | |
| 32 | |
| 33 static base::subtle::AtomicWord g_Foo_calledByNative = 0; | |
| 34 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { | |
| 35 /* Must call RegisterNativesImpl() */ | |
| 36 CHECK_CLAZZ(env, Foo_clazz(env), | |
| 37 Foo_clazz(env)); | |
| 38 jmethodID method_id = | |
| 39 base::android::MethodID::LazyGet< | |
| 40 base::android::MethodID::TYPE_STATIC>( | |
| 41 env, Foo_clazz(env), | |
| 42 "calledByNative", | |
| 43 | |
| 44 "(" | |
| 45 "Lorg/chromium/foo/Bar$Callback;" | |
| 46 ")" | |
| 47 "V", | |
| 48 &g_Foo_calledByNative); | |
| 49 | |
| 50 env->CallStaticVoidMethod(Foo_clazz(env), | |
| 51 method_id, callback); | |
| 52 jni_generator::CheckException(env); | |
| 53 | |
| 54 } | |
| 55 | |
| 56 // Step 3: RegisterNatives. | |
| 57 | |
| 58 static const JNINativeMethod kMethodsFoo[] = { | |
| 59 { "nativeDoSomething", | |
| 60 "(" | |
| 61 "Lorg/chromium/foo/Bar$Callback;" | |
| 62 ")" | |
| 63 "V", reinterpret_cast<void*>(DoSomething) }, | |
| 64 }; | |
| 65 | |
| 66 static bool RegisterNativesImpl(JNIEnv* env) { | |
| 67 | |
| 68 g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
| 69 base::android::GetClass(env, kFooClassPath).obj())); | |
| 70 | |
| 71 const int kMethodsFooSize = arraysize(kMethodsFoo); | |
| 72 | |
| 73 if (env->RegisterNatives(Foo_clazz(env), | |
| 74 kMethodsFoo, | |
| 75 kMethodsFooSize) < 0) { | |
| 76 jni_generator::HandleRegistrationError( | |
| 77 env, Foo_clazz(env), __FILE__); | |
| 78 return false; | |
| 79 } | |
| 80 | |
| 81 return true; | |
| 82 } | |
| 83 | |
| 84 #endif // org_chromium_foo_Foo_JNI | |
| OLD | NEW |