blob: 3481713f8935afaf60a5ee7e3d09bf1f057e1fb6 [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_DEFAULT_PREF_STORE_H_
6#define COMPONENTS_PREFS_DEFAULT_PREF_STORE_H_
brettw58cd1f12016-01-30 05:56:057
8#include <string>
9
10#include "base/macros.h"
11#include "base/observer_list.h"
brettw58cd1f12016-01-30 05:56:0512#include "base/values.h"
brettwf00b9b42016-02-01 22:11:3813#include "components/prefs/base_prefs_export.h"
14#include "components/prefs/pref_store.h"
15#include "components/prefs/pref_value_map.h"
brettw58cd1f12016-01-30 05:56:0516
17// Used within a PrefRegistry to keep track of default preference values.
brettw066508682016-02-03 08:22:0218class COMPONENTS_PREFS_EXPORT DefaultPrefStore : public PrefStore {
brettw58cd1f12016-01-30 05:56:0519 public:
20 typedef PrefValueMap::const_iterator const_iterator;
21
22 DefaultPrefStore();
23
24 // PrefStore implementation:
25 bool GetValue(const std::string& key,
26 const base::Value** result) const override;
27 void AddObserver(PrefStore::Observer* observer) override;
28 void RemoveObserver(PrefStore::Observer* observer) override;
29 bool HasObservers() const override;
30
31 // Sets a |value| for |key|. Should only be called if a value has not been
32 // set yet; otherwise call ReplaceDefaultValue().
dcheng5f043bc2016-04-22 19:09:0633 void SetDefaultValue(const std::string& key,
34 std::unique_ptr<base::Value> value);
brettw58cd1f12016-01-30 05:56:0535
36 // Replaces the the value for |key| with a new value. Should only be called
37 // if a value has alreday been set; otherwise call SetDefaultValue().
38 void ReplaceDefaultValue(const std::string& key,
dcheng5f043bc2016-04-22 19:09:0639 std::unique_ptr<base::Value> value);
brettw58cd1f12016-01-30 05:56:0540
41 const_iterator begin() const;
42 const_iterator end() const;
43
44 private:
45 ~DefaultPrefStore() override;
46
47 PrefValueMap prefs_;
48
49 base::ObserverList<PrefStore::Observer, true> observers_;
50
51 DISALLOW_COPY_AND_ASSIGN(DefaultPrefStore);
52};
53
brettw066508682016-02-03 08:22:0254#endif // COMPONENTS_PREFS_DEFAULT_PREF_STORE_H_