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

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

Issue 8515002: Take out and generalize user prefs overriding from IncognitoUserPrefStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Properly rebased Created 9 years, 1 month 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PREFS_INCOGNITO_USER_PREF_STORE_H_ 5 #ifndef CHROME_BROWSER_PREFS_OVERLAY_USER_PREF_STORE_H_
6 #define CHROME_BROWSER_PREFS_INCOGNITO_USER_PREF_STORE_H_ 6 #define CHROME_BROWSER_PREFS_OVERLAY_USER_PREF_STORE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/hash_tables.h"
Mattias Nissler (ping if slow) 2011/11/14 12:04:55 remove this and instead #include <map>
mnaganov (inactive) 2011/11/14 12:07:31 Done.
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/observer_list.h" 14 #include "base/observer_list.h"
14 #include "chrome/browser/prefs/pref_value_map.h" 15 #include "chrome/browser/prefs/pref_value_map.h"
15 #include "chrome/common/persistent_pref_store.h" 16 #include "chrome/common/persistent_pref_store.h"
16 17
17 // PersistentPrefStore that directs all write operations into an in-memory 18 // PersistentPrefStore that directs all write operations into an in-memory
18 // PrefValueMap. Read operations are first answered by the PrefValueMap. 19 // PrefValueMap. Read operations are first answered by the PrefValueMap.
19 // If the PrefValueMap does not contain a value for the requested key, 20 // 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 // the look-up is passed on to an underlying PersistentPrefStore |underlay_|.
21 class IncognitoUserPrefStore : public PersistentPrefStore, 22 class OverlayUserPrefStore : public PersistentPrefStore,
22 public PrefStore::Observer { 23 public PrefStore::Observer {
23 public: 24 public:
24 explicit IncognitoUserPrefStore(PersistentPrefStore* underlay); 25 explicit OverlayUserPrefStore(PersistentPrefStore* underlay);
25 virtual ~IncognitoUserPrefStore(); 26 virtual ~OverlayUserPrefStore();
26 27
27 // Returns true if a value has been set for the |key| in this 28 // Returns true if a value has been set for the |key| in this
28 // IncognitoUserPrefStore, i.e. if it potentially overrides a value 29 // OverlayUserPrefStore, i.e. if it potentially overrides a value
29 // from the |underlay_|. 30 // from the |underlay_|.
30 virtual bool IsSetInOverlay(const std::string& key) const; 31 virtual bool IsSetInOverlay(const std::string& key) const;
31 32
32 // Methods of PrefStore. 33 // Methods of PrefStore.
33 virtual void AddObserver(PrefStore::Observer* observer); 34 virtual void AddObserver(PrefStore::Observer* observer);
34 virtual void RemoveObserver(PrefStore::Observer* observer); 35 virtual void RemoveObserver(PrefStore::Observer* observer);
35 virtual bool IsInitializationComplete() const; 36 virtual bool IsInitializationComplete() const;
36 virtual ReadResult GetValue(const std::string& key, 37 virtual ReadResult GetValue(const std::string& key,
37 const base::Value** result) const; 38 const base::Value** result) const;
38 39
39 // Methods of PersistentPrefStore. 40 // Methods of PersistentPrefStore.
40 virtual ReadResult GetMutableValue(const std::string& key, 41 virtual ReadResult GetMutableValue(const std::string& key,
41 base::Value** result); 42 base::Value** result);
42 virtual void SetValue(const std::string& key, base::Value* value); 43 virtual void SetValue(const std::string& key, base::Value* value);
43 virtual void SetValueSilently(const std::string& key, base::Value* value); 44 virtual void SetValueSilently(const std::string& key, base::Value* value);
44 virtual void RemoveValue(const std::string& key); 45 virtual void RemoveValue(const std::string& key);
45 virtual bool ReadOnly() const; 46 virtual bool ReadOnly() const;
46 virtual PrefReadError ReadPrefs(); 47 virtual PrefReadError ReadPrefs();
47 virtual void ReadPrefsAsync(ReadErrorDelegate* delegate); 48 virtual void ReadPrefsAsync(ReadErrorDelegate* delegate);
48 virtual bool WritePrefs(); 49 virtual bool WritePrefs();
49 virtual void ScheduleWritePrefs(); 50 virtual void ScheduleWritePrefs();
50 virtual void CommitPendingWrite(); 51 virtual void CommitPendingWrite();
51 virtual void ReportValueChanged(const std::string& key); 52 virtual void ReportValueChanged(const std::string& key);
52 53
54 protected:
55 void RegisterOverlayProperty(const std::string& key);
56 void RegisterOverlayProperty(const std::string& overlay_key,
57 const std::string& underlay_key);
58
53 private: 59 private:
60 friend class OverlayUserPrefStoreTest;
61
62 typedef std::map<std::string, std::string> NamesMap;
63
54 // Methods of PrefStore::Observer. 64 // Methods of PrefStore::Observer.
55 virtual void OnPrefValueChanged(const std::string& key); 65 virtual void OnPrefValueChanged(const std::string& key);
56 virtual void OnInitializationCompleted(bool succeeded); 66 virtual void OnInitializationCompleted(bool succeeded);
57 67
68 const std::string& GetOverlayKey(const std::string& underlay_key) const;
69 const std::string& GetUnderlayKey(const std::string& overlay_key) const;
70
58 // Returns true if |key| corresponds to a preference that shall be stored in 71 // Returns true if |key| corresponds to a preference that shall be stored in
59 // an in-memory PrefStore that is not persisted to disk. All preferences 72 // an in-memory PrefStore that is not persisted to disk.
60 // that store information about the browsing history or behavior of the user 73 bool ShallBeStoredInOverlay(const std::string& key) const;
61 // should have this property.
62 virtual bool ShallBeStoredInOverlay(const std::string& key) const;
63 74
64 ObserverList<PrefStore::Observer, true> observers_; 75 ObserverList<PrefStore::Observer, true> observers_;
65 PrefValueMap overlay_; 76 PrefValueMap overlay_;
66 scoped_refptr<PersistentPrefStore> underlay_; 77 scoped_refptr<PersistentPrefStore> underlay_;
78 NamesMap overlay_to_underlay_names_map_;
79 NamesMap underlay_to_overlay_names_map_;
67 80
68 DISALLOW_COPY_AND_ASSIGN(IncognitoUserPrefStore); 81 DISALLOW_COPY_AND_ASSIGN(OverlayUserPrefStore);
69 }; 82 };
70 83
71 #endif // CHROME_BROWSER_PREFS_INCOGNITO_USER_PREF_STORE_H_ 84 #endif // CHROME_BROWSER_PREFS_OVERLAY_USER_PREF_STORE_H_
OLDNEW
« no previous file with comments | « chrome/browser/prefs/incognito_user_pref_store_unittest.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