• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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 COMPONENTS_PREFS_ANDROID_PREF_SERVICE_ANDROID_H_
6 #define COMPONENTS_PREFS_ANDROID_PREF_SERVICE_ANDROID_H_
7 
8 #include <jni.h>
9 
10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/memory/raw_ptr.h"
13 
14 class PrefService;
15 
16 // The native side of the PrefServiceAndroid is created and destroyed by the
17 // Java.
18 class PrefServiceAndroid {
19  public:
20   explicit PrefServiceAndroid(PrefService* pref_service);
21   PrefServiceAndroid(const PrefServiceAndroid& other) = delete;
22   PrefServiceAndroid& operator=(const PrefServiceAndroid& other) = delete;
23   ~PrefServiceAndroid();
24 
25   base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
26 
27   void ClearPref(JNIEnv* env,
28                  const base::android::JavaParamRef<jstring>& j_preference);
29   jboolean HasPrefPath(
30       JNIEnv* env,
31       const base::android::JavaParamRef<jstring>& j_preference);
32   jboolean GetBoolean(JNIEnv* env,
33                       const base::android::JavaParamRef<jstring>& j_preference);
34   void SetBoolean(JNIEnv* env,
35                   const base::android::JavaParamRef<jstring>& j_preference,
36                   const jboolean j_value);
37   jint GetInteger(JNIEnv* env,
38                   const base::android::JavaParamRef<jstring>& j_preference);
39   void SetInteger(JNIEnv* env,
40                   const base::android::JavaParamRef<jstring>& j_preference,
41                   const jint j_value);
42   base::android::ScopedJavaLocalRef<jstring> GetString(
43       JNIEnv* env,
44       const base::android::JavaParamRef<jstring>& j_preference);
45   void SetString(JNIEnv* env,
46                  const base::android::JavaParamRef<jstring>& j_preference,
47                  const base::android::JavaParamRef<jstring>& j_value);
48   jboolean IsManagedPreference(
49       JNIEnv* env,
50       const base::android::JavaParamRef<jstring>& j_preference);
51   jboolean IsDefaultValuePreference(
52       JNIEnv* env,
53       const base::android::JavaParamRef<jstring>& j_preference);
54 
55  private:
56   raw_ptr<PrefService> pref_service_;
57   base::android::ScopedJavaGlobalRef<jobject> java_ref_;
58 };
59 
60 #endif  // COMPONENTS_PREFS_ANDROID_PREF_SERVICE_ANDROID_H_
61