Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: chrome/browser/prefs/overlay_user_pref_store.h

Issue 11243002: Move the bits of Prefs where production code has only trivially easy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments, fix gypi problem Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
5 #ifndef CHROME_BROWSER_PREFS_OVERLAY_USER_PREF_STORE_H_
6 #define CHROME_BROWSER_PREFS_OVERLAY_USER_PREF_STORE_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/observer_list.h"
14 #include "chrome/browser/prefs/pref_value_map.h"
15 #include "chrome/common/persistent_pref_store.h"
16
17 // PersistentPrefStore that directs all write operations into an in-memory
18 // PrefValueMap. Read operations are first answered by the PrefValueMap.
19 // If the PrefValueMap does not contain a value for the requested key,
20 // the look-up is passed on to an underlying PersistentPrefStore |underlay_|.
21 class OverlayUserPrefStore : public PersistentPrefStore,
22 public PrefStore::Observer {
23 public:
24 explicit OverlayUserPrefStore(PersistentPrefStore* underlay);
25
26 // Returns true if a value has been set for the |key| in this
27 // OverlayUserPrefStore, i.e. if it potentially overrides a value
28 // from the |underlay_|.
29 virtual bool IsSetInOverlay(const std::string& key) const;
30
31 // Methods of PrefStore.
32 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE;
33 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE;
34 virtual size_t NumberOfObservers() const OVERRIDE;
35 virtual bool IsInitializationComplete() const OVERRIDE;
36 virtual ReadResult GetValue(const std::string& key,
37 const base::Value** result) const OVERRIDE;
38
39 // Methods of PersistentPrefStore.
40 virtual ReadResult GetMutableValue(const std::string& key,
41 base::Value** result) OVERRIDE;
42 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE;
43 virtual void SetValueSilently(const std::string& key,
44 base::Value* value) OVERRIDE;
45 virtual void RemoveValue(const std::string& key) OVERRIDE;
46 virtual void MarkNeedsEmptyValue(const std::string& key) OVERRIDE;
47 virtual bool ReadOnly() const OVERRIDE;
48 virtual PrefReadError GetReadError() const OVERRIDE;
49 virtual PrefReadError ReadPrefs() OVERRIDE;
50 virtual void ReadPrefsAsync(ReadErrorDelegate* delegate) OVERRIDE;
51 virtual void CommitPendingWrite() OVERRIDE;
52 virtual void ReportValueChanged(const std::string& key) OVERRIDE;
53
54 // Methods of PrefStore::Observer.
55 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE;
56 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE;
57
58 void RegisterOverlayPref(const std::string& key);
59 void RegisterOverlayPref(const std::string& overlay_key,
60 const std::string& underlay_key);
61
62 protected:
63 virtual ~OverlayUserPrefStore();
64
65 private:
66 typedef std::map<std::string, std::string> NamesMap;
67
68 const std::string& GetOverlayKey(const std::string& underlay_key) const;
69 const std::string& GetUnderlayKey(const std::string& overlay_key) const;
70
71 // Returns true if |key| corresponds to a preference that shall be stored in
72 // an in-memory PrefStore that is not persisted to disk.
73 bool ShallBeStoredInOverlay(const std::string& key) const;
74
75 ObserverList<PrefStore::Observer, true> observers_;
76 PrefValueMap overlay_;
77 scoped_refptr<PersistentPrefStore> underlay_;
78 NamesMap overlay_to_underlay_names_map_;
79 NamesMap underlay_to_overlay_names_map_;
80
81 DISALLOW_COPY_AND_ASSIGN(OverlayUserPrefStore);
82 };
83
84 #endif // CHROME_BROWSER_PREFS_OVERLAY_USER_PREF_STORE_H_
OLDNEW
« no previous file with comments | « chrome/browser/prefs/default_pref_store.cc ('k') | chrome/browser/prefs/overlay_user_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698