• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_ANDROID_CALLBACK_ANDROID_H_
6 #define BASE_ANDROID_CALLBACK_ANDROID_H_
7 
8 #include <jni.h>
9 
10 #include <string>
11 #include <vector>
12 
13 #include "base/android/scoped_java_ref.h"
14 #include "base/base_export.h"
15 #include "base/functional/callback.h"
16 #include "base/time/time.h"
17 #include "base/types/optional_ref.h"
18 
19 // Provides helper utility methods that run the given callback with the
20 // specified argument.
21 namespace base {
22 namespace android {
23 
24 void BASE_EXPORT RunObjectCallbackAndroid(const JavaRef<jobject>& callback,
25                                           const JavaRef<jobject>& arg);
26 
27 void BASE_EXPORT RunBooleanCallbackAndroid(const JavaRef<jobject>& callback,
28                                            bool arg);
29 
30 void BASE_EXPORT RunIntCallbackAndroid(const JavaRef<jobject>& callback,
31                                        int32_t arg);
32 
33 void BASE_EXPORT RunLongCallbackAndroid(const JavaRef<jobject>& callback,
34                                         int64_t arg);
35 
36 void BASE_EXPORT RunTimeCallbackAndroid(const JavaRef<jobject>& callback,
37                                         base::Time time);
38 
39 void BASE_EXPORT RunStringCallbackAndroid(const JavaRef<jobject>& callback,
40                                           const std::string& arg);
41 
42 void BASE_EXPORT RunOptionalStringCallbackAndroid(
43     const JavaRef<jobject>& callback,
44     base::optional_ref<const std::string> optional_string_arg);
45 
46 void BASE_EXPORT RunByteArrayCallbackAndroid(const JavaRef<jobject>& callback,
47                                              const std::vector<uint8_t>& arg);
48 
49 void BASE_EXPORT RunRunnableAndroid(const JavaRef<jobject>& runnable);
50 
51 }  // namespace android
52 }  // namespace base
53 
54 namespace jni_zero {
55 
56 template <>
57 inline base::RepeatingClosure FromJniType<base::RepeatingClosure>(
58     JNIEnv* env,
59     const JavaRef<jobject>& obj) {
60   return base::BindRepeating(&base::android::RunRunnableAndroid,
61                              base::android::ScopedJavaGlobalRef<jobject>(obj));
62 }
63 
64 }  // namespace jni_zero
65 
66 #endif  // BASE_ANDROID_CALLBACK_ANDROID_H_
67