Add ICU message format support
[chromium-blink-merge.git] / base / prefs / overlay_user_pref_store.h
blob737b4262f3e10500ef213a2869c81239db9d6da8
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.
5 #ifndef BASE_PREFS_OVERLAY_USER_PREF_STORE_H_
6 #define BASE_PREFS_OVERLAY_USER_PREF_STORE_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/observer_list.h"
14 #include "base/prefs/base_prefs_export.h"
15 #include "base/prefs/persistent_pref_store.h"
16 #include "base/prefs/pref_value_map.h"
18 // PersistentPrefStore that directs all write operations into an in-memory
19 // PrefValueMap. Read operations are first answered by the PrefValueMap.
20 // If the PrefValueMap does not contain a value for the requested key,
21 // the look-up is passed on to an underlying PersistentPrefStore |underlay_|.
22 class BASE_PREFS_EXPORT OverlayUserPrefStore : public PersistentPrefStore,
23 public PrefStore::Observer {
24 public:
25 explicit OverlayUserPrefStore(PersistentPrefStore* underlay);
27 // Returns true if a value has been set for the |key| in this
28 // OverlayUserPrefStore, i.e. if it potentially overrides a value
29 // from the |underlay_|.
30 virtual bool IsSetInOverlay(const std::string& key) const;
32 // Methods of PrefStore.
33 void AddObserver(PrefStore::Observer* observer) override;
34 void RemoveObserver(PrefStore::Observer* observer) override;
35 bool HasObservers() const override;
36 bool IsInitializationComplete() const override;
37 bool GetValue(const std::string& key,
38 const base::Value** result) const override;
40 // Methods of PersistentPrefStore.
41 bool GetMutableValue(const std::string& key, base::Value** result) override;
42 void SetValue(const std::string& key,
43 scoped_ptr<base::Value> value,
44 uint32 flags) override;
45 void SetValueSilently(const std::string& key,
46 scoped_ptr<base::Value> value,
47 uint32 flags) override;
48 void RemoveValue(const std::string& key, uint32 flags) override;
49 bool ReadOnly() const override;
50 PrefReadError GetReadError() const override;
51 PrefReadError ReadPrefs() override;
52 void ReadPrefsAsync(ReadErrorDelegate* delegate) override;
53 void CommitPendingWrite() override;
54 void SchedulePendingLossyWrites() override;
55 void ReportValueChanged(const std::string& key, uint32 flags) override;
57 // Methods of PrefStore::Observer.
58 void OnPrefValueChanged(const std::string& key) override;
59 void OnInitializationCompleted(bool succeeded) override;
61 void RegisterOverlayPref(const std::string& key);
62 void RegisterOverlayPref(const std::string& overlay_key,
63 const std::string& underlay_key);
65 protected:
66 ~OverlayUserPrefStore() override;
68 private:
69 typedef std::map<std::string, std::string> NamesMap;
71 const std::string& GetOverlayKey(const std::string& underlay_key) const;
72 const std::string& GetUnderlayKey(const std::string& overlay_key) const;
74 // Returns true if |key| corresponds to a preference that shall be stored in
75 // an in-memory PrefStore that is not persisted to disk.
76 bool ShallBeStoredInOverlay(const std::string& key) const;
78 base::ObserverList<PrefStore::Observer, true> observers_;
79 PrefValueMap overlay_;
80 scoped_refptr<PersistentPrefStore> underlay_;
81 NamesMap overlay_to_underlay_names_map_;
82 NamesMap underlay_to_overlay_names_map_;
84 DISALLOW_COPY_AND_ASSIGN(OverlayUserPrefStore);
87 #endif // BASE_PREFS_OVERLAY_USER_PREF_STORE_H_