blob: 11828e8b02e1709a99446a8c7972d68ce085b495 [file] [log] [blame]
brettw58cd1f12016-01-30 05:56:051// 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
brettw066508682016-02-03 08:22:025#ifndef COMPONENTS_PREFS_VALUE_MAP_PREF_STORE_H_
6#define COMPONENTS_PREFS_VALUE_MAP_PREF_STORE_H_
brettw58cd1f12016-01-30 05:56:057
8#include <stdint.h>
9
10#include <map>
11#include <string>
12
13#include "base/macros.h"
14#include "base/observer_list.h"
brettwf00b9b42016-02-01 22:11:3815#include "components/prefs/pref_value_map.h"
Brett Wilson5c6cf262017-09-09 02:05:5416#include "components/prefs/prefs_export.h"
brettwf00b9b42016-02-01 22:11:3817#include "components/prefs/writeable_pref_store.h"
brettw58cd1f12016-01-30 05:56:0518
19// A basic PrefStore implementation that uses a simple name-value map for
20// storing the preference values.
brettw066508682016-02-03 08:22:0221class COMPONENTS_PREFS_EXPORT ValueMapPrefStore : public WriteablePrefStore {
brettw58cd1f12016-01-30 05:56:0522 public:
23 ValueMapPrefStore();
24
25 // PrefStore overrides:
26 bool GetValue(const std::string& key,
27 const base::Value** value) const override;
tibelle23659b42017-02-23 01:44:1328 std::unique_ptr<base::DictionaryValue> GetValues() const override;
brettw58cd1f12016-01-30 05:56:0529 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,
dcheng5f043bc2016-04-22 19:09:0635 std::unique_ptr<base::Value> value,
brettw58cd1f12016-01-30 05:56:0536 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,
dcheng5f043bc2016-04-22 19:09:0641 std::unique_ptr<base::Value> value,
brettw58cd1f12016-01-30 05:56:0542 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
brettw066508682016-02-03 08:22:0258#endif // COMPONENTS_PREFS_VALUE_MAP_PREF_STORE_H_