1 // Copyright 2016 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 #include "base/android/callback_android.h"
6
7 #include "base/android/jni_array.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "jni/Callback_jni.h"
11
12 namespace base {
13 namespace android {
14
RunObjectCallbackAndroid(const JavaRef<jobject> & callback,const JavaRef<jobject> & arg)15 void RunObjectCallbackAndroid(const JavaRef<jobject>& callback,
16 const JavaRef<jobject>& arg) {
17 Java_Helper_onObjectResultFromNative(AttachCurrentThread(), callback, arg);
18 }
19
RunBooleanCallbackAndroid(const JavaRef<jobject> & callback,bool arg)20 void RunBooleanCallbackAndroid(const JavaRef<jobject>& callback, bool arg) {
21 Java_Helper_onBooleanResultFromNative(AttachCurrentThread(), callback,
22 static_cast<jboolean>(arg));
23 }
24
RunIntCallbackAndroid(const JavaRef<jobject> & callback,int arg)25 void RunIntCallbackAndroid(const JavaRef<jobject>& callback, int arg) {
26 Java_Helper_onIntResultFromNative(AttachCurrentThread(), callback, arg);
27 }
28
RunStringCallbackAndroid(const JavaRef<jobject> & callback,const std::string & arg)29 void RunStringCallbackAndroid(const JavaRef<jobject>& callback,
30 const std::string& arg) {
31 JNIEnv* env = AttachCurrentThread();
32 ScopedJavaLocalRef<jstring> java_string = ConvertUTF8ToJavaString(env, arg);
33 Java_Helper_onObjectResultFromNative(env, callback, java_string);
34 }
35
RunByteArrayCallbackAndroid(const JavaRef<jobject> & callback,const std::vector<uint8_t> & arg)36 void RunByteArrayCallbackAndroid(const JavaRef<jobject>& callback,
37 const std::vector<uint8_t>& arg) {
38 JNIEnv* env = AttachCurrentThread();
39 ScopedJavaLocalRef<jbyteArray> j_bytes = ToJavaByteArray(env, arg);
40 Java_Helper_onObjectResultFromNative(env, callback, j_bytes);
41 }
42
43 } // namespace android
44 } // namespace base
45