1*6777b538SAndroid Build Coastguard Worker // Copyright 2012 The Chromium Authors 2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file. 4*6777b538SAndroid Build Coastguard Worker 5*6777b538SAndroid Build Coastguard Worker #ifndef COMPONENTS_PREFS_PREF_STORE_H_ 6*6777b538SAndroid Build Coastguard Worker #define COMPONENTS_PREFS_PREF_STORE_H_ 7*6777b538SAndroid Build Coastguard Worker 8*6777b538SAndroid Build Coastguard Worker #include <memory> 9*6777b538SAndroid Build Coastguard Worker #include <string> 10*6777b538SAndroid Build Coastguard Worker 11*6777b538SAndroid Build Coastguard Worker #include "base/memory/ref_counted.h" 12*6777b538SAndroid Build Coastguard Worker #include "base/strings/string_piece.h" 13*6777b538SAndroid Build Coastguard Worker #include "base/values.h" 14*6777b538SAndroid Build Coastguard Worker #include "components/prefs/prefs_export.h" 15*6777b538SAndroid Build Coastguard Worker 16*6777b538SAndroid Build Coastguard Worker // This is an abstract interface for reading and writing from/to a persistent 17*6777b538SAndroid Build Coastguard Worker // preference store, used by PrefService. An implementation using a JSON file 18*6777b538SAndroid Build Coastguard Worker // can be found in JsonPrefStore, while an implementation without any backing 19*6777b538SAndroid Build Coastguard Worker // store for testing can be found in TestingPrefStore. Furthermore, there is 20*6777b538SAndroid Build Coastguard Worker // CommandLinePrefStore, which bridges command line options to preferences and 21*6777b538SAndroid Build Coastguard Worker // ConfigurationPolicyPrefStore, which is used for hooking up configuration 22*6777b538SAndroid Build Coastguard Worker // policy with the preference subsystem. 23*6777b538SAndroid Build Coastguard Worker class COMPONENTS_PREFS_EXPORT PrefStore : public base::RefCounted<PrefStore> { 24*6777b538SAndroid Build Coastguard Worker public: 25*6777b538SAndroid Build Coastguard Worker // Observer interface for monitoring PrefStore. 26*6777b538SAndroid Build Coastguard Worker class COMPONENTS_PREFS_EXPORT Observer { 27*6777b538SAndroid Build Coastguard Worker public: 28*6777b538SAndroid Build Coastguard Worker // Called when the value for the given |key| in the store changes. 29*6777b538SAndroid Build Coastguard Worker virtual void OnPrefValueChanged(const std::string& key) = 0; 30*6777b538SAndroid Build Coastguard Worker // Notification about the PrefStore being fully initialized. 31*6777b538SAndroid Build Coastguard Worker virtual void OnInitializationCompleted(bool succeeded) = 0; 32*6777b538SAndroid Build Coastguard Worker 33*6777b538SAndroid Build Coastguard Worker protected: ~Observer()34*6777b538SAndroid Build Coastguard Worker virtual ~Observer() {} 35*6777b538SAndroid Build Coastguard Worker }; 36*6777b538SAndroid Build Coastguard Worker PrefStore()37*6777b538SAndroid Build Coastguard Worker PrefStore() {} 38*6777b538SAndroid Build Coastguard Worker 39*6777b538SAndroid Build Coastguard Worker PrefStore(const PrefStore&) = delete; 40*6777b538SAndroid Build Coastguard Worker PrefStore& operator=(const PrefStore&) = delete; 41*6777b538SAndroid Build Coastguard Worker 42*6777b538SAndroid Build Coastguard Worker // Add and remove observers. AddObserver(Observer * observer)43*6777b538SAndroid Build Coastguard Worker virtual void AddObserver(Observer* observer) {} RemoveObserver(Observer * observer)44*6777b538SAndroid Build Coastguard Worker virtual void RemoveObserver(Observer* observer) {} 45*6777b538SAndroid Build Coastguard Worker virtual bool HasObservers() const; 46*6777b538SAndroid Build Coastguard Worker 47*6777b538SAndroid Build Coastguard Worker // Whether the store has completed all asynchronous initialization. 48*6777b538SAndroid Build Coastguard Worker virtual bool IsInitializationComplete() const; 49*6777b538SAndroid Build Coastguard Worker 50*6777b538SAndroid Build Coastguard Worker // Get the value for a given preference |key| and stores it in |*result|. 51*6777b538SAndroid Build Coastguard Worker // |*result| is only modified if the return value is true and if |result| 52*6777b538SAndroid Build Coastguard Worker // is not NULL. Ownership of the |*result| value remains with the PrefStore. 53*6777b538SAndroid Build Coastguard Worker virtual bool GetValue(base::StringPiece key, 54*6777b538SAndroid Build Coastguard Worker const base::Value** result) const = 0; 55*6777b538SAndroid Build Coastguard Worker 56*6777b538SAndroid Build Coastguard Worker // Get all the values. 57*6777b538SAndroid Build Coastguard Worker virtual base::Value::Dict GetValues() const = 0; 58*6777b538SAndroid Build Coastguard Worker 59*6777b538SAndroid Build Coastguard Worker protected: 60*6777b538SAndroid Build Coastguard Worker friend class base::RefCounted<PrefStore>; ~PrefStore()61*6777b538SAndroid Build Coastguard Worker virtual ~PrefStore() {} 62*6777b538SAndroid Build Coastguard Worker }; 63*6777b538SAndroid Build Coastguard Worker 64*6777b538SAndroid Build Coastguard Worker #endif // COMPONENTS_PREFS_PREF_STORE_H_ 65