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