1 // Copyright 2012 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_VALUE_MAP_PREF_STORE_H_ 6 #define COMPONENTS_PREFS_VALUE_MAP_PREF_STORE_H_ 7 8 #include <stdint.h> 9 10 #include <map> 11 #include <string_view> 12 13 #include "base/observer_list.h" 14 #include "base/values.h" 15 #include "components/prefs/pref_value_map.h" 16 #include "components/prefs/prefs_export.h" 17 #include "components/prefs/writeable_pref_store.h" 18 19 // A basic PrefStore implementation that uses a simple name-value map for 20 // storing the preference values. 21 class COMPONENTS_PREFS_EXPORT ValueMapPrefStore : public WriteablePrefStore { 22 public: 23 ValueMapPrefStore(); 24 25 ValueMapPrefStore(const ValueMapPrefStore&) = delete; 26 ValueMapPrefStore& operator=(const ValueMapPrefStore&) = delete; 27 28 // PrefStore overrides: 29 bool GetValue(std::string_view key, const base::Value** value) const override; 30 base::Value::Dict GetValues() const override; 31 void AddObserver(PrefStore::Observer* observer) override; 32 void RemoveObserver(PrefStore::Observer* observer) override; 33 bool HasObservers() const override; 34 35 // WriteablePrefStore overrides: 36 void SetValue(std::string_view key, 37 base::Value value, 38 uint32_t flags) override; 39 void RemoveValue(std::string_view key, uint32_t flags) override; 40 bool GetMutableValue(std::string_view key, base::Value** value) override; 41 void ReportValueChanged(std::string_view key, uint32_t flags) override; 42 void SetValueSilently(std::string_view key, 43 base::Value value, 44 uint32_t flags) override; 45 void RemoveValuesByPrefixSilently(std::string_view prefix) override; 46 47 protected: 48 ~ValueMapPrefStore() override; 49 50 // Notify observers about the initialization completed event. 51 void NotifyInitializationCompleted(); 52 53 private: 54 PrefValueMap prefs_; 55 56 base::ObserverList<PrefStore::Observer, true> observers_; 57 }; 58 59 #endif // COMPONENTS_PREFS_VALUE_MAP_PREF_STORE_H_ 60