brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
brettw | 06650868 | 2016-02-03 08:22:02 | [diff] [blame] | 5 | #ifndef COMPONENTS_PREFS_VALUE_MAP_PREF_STORE_H_ |
| 6 | #define COMPONENTS_PREFS_VALUE_MAP_PREF_STORE_H_ |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 7 | |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | #include <map> |
| 11 | #include <string> |
| 12 | |
| 13 | #include "base/macros.h" |
| 14 | #include "base/observer_list.h" |
brettw | f00b9b4 | 2016-02-01 22:11:38 | [diff] [blame] | 15 | #include "components/prefs/pref_value_map.h" |
Brett Wilson | 5c6cf26 | 2017-09-09 02:05:54 | [diff] [blame] | 16 | #include "components/prefs/prefs_export.h" |
brettw | f00b9b4 | 2016-02-01 22:11:38 | [diff] [blame] | 17 | #include "components/prefs/writeable_pref_store.h" |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 18 | |
| 19 | // A basic PrefStore implementation that uses a simple name-value map for |
| 20 | // storing the preference values. |
brettw | 06650868 | 2016-02-03 08:22:02 | [diff] [blame] | 21 | class COMPONENTS_PREFS_EXPORT ValueMapPrefStore : public WriteablePrefStore { |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 22 | public: |
| 23 | ValueMapPrefStore(); |
| 24 | |
| 25 | // PrefStore overrides: |
| 26 | bool GetValue(const std::string& key, |
| 27 | const base::Value** value) const override; |
tibell | e23659b4 | 2017-02-23 01:44:13 | [diff] [blame] | 28 | std::unique_ptr<base::DictionaryValue> GetValues() const override; |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 29 | void AddObserver(PrefStore::Observer* observer) override; |
| 30 | void RemoveObserver(PrefStore::Observer* observer) override; |
| 31 | bool HasObservers() const override; |
| 32 | |
| 33 | // WriteablePrefStore overrides: |
| 34 | void SetValue(const std::string& key, |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 35 | std::unique_ptr<base::Value> value, |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 36 | uint32_t flags) override; |
| 37 | void RemoveValue(const std::string& key, uint32_t flags) override; |
| 38 | bool GetMutableValue(const std::string& key, base::Value** value) override; |
| 39 | void ReportValueChanged(const std::string& key, uint32_t flags) override; |
| 40 | void SetValueSilently(const std::string& key, |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 41 | std::unique_ptr<base::Value> value, |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 42 | uint32_t flags) override; |
| 43 | |
| 44 | protected: |
| 45 | ~ValueMapPrefStore() override; |
| 46 | |
| 47 | // Notify observers about the initialization completed event. |
| 48 | void NotifyInitializationCompleted(); |
| 49 | |
| 50 | private: |
| 51 | PrefValueMap prefs_; |
| 52 | |
| 53 | base::ObserverList<PrefStore::Observer, true> observers_; |
| 54 | |
| 55 | DISALLOW_COPY_AND_ASSIGN(ValueMapPrefStore); |
| 56 | }; |
| 57 | |
brettw | 06650868 | 2016-02-03 08:22:02 | [diff] [blame] | 58 | #endif // COMPONENTS_PREFS_VALUE_MAP_PREF_STORE_H_ |