• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_CHANGE_REGISTRAR_ANDROID_H_
6 #define COMPONENTS_PREFS_ANDROID_PREF_CHANGE_REGISTRAR_ANDROID_H_
7 
8 #include "base/android/scoped_java_ref.h"
9 #include "base/memory/raw_ptr.h"
10 #include "components/prefs/pref_change_registrar.h"
11 
12 using base::android::JavaParamRef;
13 using base::android::ScopedJavaGlobalRef;
14 
15 class PrefService;
16 
17 // This class contains a PrefChangeRegistrar that observes PrefService changes
18 // for Android.
19 class PrefChangeRegistrarAndroid {
20  public:
21   PrefChangeRegistrarAndroid(JNIEnv* env,
22                              const JavaParamRef<jobject>& obj,
23                              PrefService* prefs);
24   void Destroy(JNIEnv*, const JavaParamRef<jobject>&);
25 
26   PrefChangeRegistrarAndroid(const PrefChangeRegistrarAndroid&) = delete;
27   PrefChangeRegistrarAndroid& operator=(const PrefChangeRegistrarAndroid&) =
28       delete;
29 
30   void Add(JNIEnv* env,
31            const JavaParamRef<jobject>& obj,
32            const JavaParamRef<jstring>& j_preference);
33   void Remove(JNIEnv* env,
34               const JavaParamRef<jobject>& obj,
35               const JavaParamRef<jstring>& j_preference);
36 
37  private:
38   ~PrefChangeRegistrarAndroid();
39   void OnPreferenceChange(std::string preference);
40 
41   PrefChangeRegistrar pref_change_registrar_;
42   ScopedJavaGlobalRef<jobject> pref_change_registrar_jobject_;
43 };
44 
45 #endif  // COMPONENTS_PREFS_ANDROID_PREF_CHANGE_REGISTRAR_ANDROID_H_
46