value_map_pref_store.h 2.1 KB

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