| OLD | NEW |
| 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_INCOGNITO_USER_PREF_STORE_H_ |
| 6 #define CHROME_BROWSER_PREFS_INCOGNITO_USER_PREF_STORE_H_ | 6 #define CHROME_BROWSER_PREFS_INCOGNITO_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/compiler_specific.h" | |
| 13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 14 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 15 #include "chrome/browser/prefs/pref_value_map.h" | 14 #include "chrome/browser/prefs/pref_value_map.h" |
| 16 #include "chrome/common/persistent_pref_store.h" | 15 #include "chrome/common/persistent_pref_store.h" |
| 17 | 16 |
| 18 // PersistentPrefStore that directs all write operations into an in-memory | 17 // PersistentPrefStore that directs all write operations into an in-memory |
| 19 // PrefValueMap. Read operations are first answered by the PrefValueMap. | 18 // PrefValueMap. Read operations are first answered by the PrefValueMap. |
| 20 // If the PrefValueMap does not contain a value for the requested key, | 19 // If the PrefValueMap does not contain a value for the requested key, |
| 21 // the look-up is passed on to an underlying PersistentPrefStore |underlay_|. | 20 // the look-up is passed on to an underlying PersistentPrefStore |underlay_|. |
| 22 class IncognitoUserPrefStore : public PersistentPrefStore, | 21 class IncognitoUserPrefStore : public PersistentPrefStore, |
| 23 public PrefStore::Observer { | 22 public PrefStore::Observer { |
| 24 public: | 23 public: |
| 25 explicit IncognitoUserPrefStore(PersistentPrefStore* underlay); | 24 explicit IncognitoUserPrefStore(PersistentPrefStore* underlay); |
| 26 virtual ~IncognitoUserPrefStore(); | 25 virtual ~IncognitoUserPrefStore(); |
| 27 | 26 |
| 28 // Returns true if a value has been set for the |key| in this | 27 // Returns true if a value has been set for the |key| in this |
| 29 // IncognitoUserPrefStore, i.e. if it potentially overrides a value | 28 // IncognitoUserPrefStore, i.e. if it potentially overrides a value |
| 30 // from the |underlay_|. | 29 // from the |underlay_|. |
| 31 virtual bool IsSetInOverlay(const std::string& key) const; | 30 virtual bool IsSetInOverlay(const std::string& key) const; |
| 32 | 31 |
| 33 // Methods of PrefStore. | 32 // Methods of PrefStore. |
| 34 virtual void AddObserver(PrefStore::Observer* observer); | 33 virtual void AddObserver(PrefStore::Observer* observer); |
| 35 virtual void RemoveObserver(PrefStore::Observer* observer); | 34 virtual void RemoveObserver(PrefStore::Observer* observer); |
| 36 virtual bool IsInitializationComplete() const; | 35 virtual bool IsInitializationComplete() const; |
| 37 virtual ReadResult GetValue(const std::string& key, | 36 virtual ReadResult GetValue(const std::string& key, |
| 38 const base::Value** result) const; | 37 const base::Value** result) const; |
| 39 | 38 |
| 40 // Methods of PersistentPrefStore. | 39 // Methods of PersistentPrefStore. |
| 41 virtual ReadResult GetMutableValue(const std::string& key, | 40 virtual ReadResult GetMutableValue(const std::string& key, |
| 42 base::Value** result) OVERRIDE; | 41 base::Value** result); |
| 43 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE; | 42 virtual void SetValue(const std::string& key, base::Value* value); |
| 44 virtual void SetValueSilently(const std::string& key, | 43 virtual void SetValueSilently(const std::string& key, base::Value* value); |
| 45 base::Value* value) OVERRIDE; | 44 virtual void RemoveValue(const std::string& key); |
| 46 virtual void RemoveValue(const std::string& key) OVERRIDE; | 45 virtual bool ReadOnly() const; |
| 47 virtual bool ReadOnly() const OVERRIDE; | 46 virtual PrefReadError ReadPrefs(); |
| 48 virtual PrefReadError ReadPrefs() OVERRIDE; | 47 virtual void ReadPrefsAsync(ReadErrorDelegate* delegate); |
| 49 virtual void ReadPrefsAsync(ReadErrorDelegate* delegate) OVERRIDE; | 48 virtual bool WritePrefs(); |
| 50 virtual bool WritePrefs() OVERRIDE; | 49 virtual void ScheduleWritePrefs(); |
| 51 virtual void ScheduleWritePrefs() OVERRIDE; | 50 virtual void CommitPendingWrite(); |
| 52 virtual void CommitPendingWrite() OVERRIDE; | 51 virtual void ReportValueChanged(const std::string& key); |
| 53 virtual void ReportValueChanged(const std::string& key) OVERRIDE; | |
| 54 virtual void CheckIfValueDestroyed(const std::string& key) OVERRIDE; | |
| 55 | 52 |
| 56 private: | 53 private: |
| 57 // Methods of PrefStore::Observer. | 54 // Methods of PrefStore::Observer. |
| 58 virtual void OnPrefValueChanged(const std::string& key); | 55 virtual void OnPrefValueChanged(const std::string& key); |
| 59 virtual void OnInitializationCompleted(bool succeeded); | 56 virtual void OnInitializationCompleted(bool succeeded); |
| 60 | 57 |
| 61 // Returns true if |key| corresponds to a preference that shall be stored in | 58 // Returns true if |key| corresponds to a preference that shall be stored in |
| 62 // an in-memory PrefStore that is not persisted to disk. All preferences | 59 // an in-memory PrefStore that is not persisted to disk. All preferences |
| 63 // that store information about the browsing history or behavior of the user | 60 // that store information about the browsing history or behavior of the user |
| 64 // should have this property. | 61 // should have this property. |
| 65 virtual bool ShallBeStoredInOverlay(const std::string& key) const; | 62 virtual bool ShallBeStoredInOverlay(const std::string& key) const; |
| 66 | 63 |
| 67 ObserverList<PrefStore::Observer, true> observers_; | 64 ObserverList<PrefStore::Observer, true> observers_; |
| 68 PrefValueMap overlay_; | 65 PrefValueMap overlay_; |
| 69 scoped_refptr<PersistentPrefStore> underlay_; | 66 scoped_refptr<PersistentPrefStore> underlay_; |
| 70 | 67 |
| 71 DISALLOW_COPY_AND_ASSIGN(IncognitoUserPrefStore); | 68 DISALLOW_COPY_AND_ASSIGN(IncognitoUserPrefStore); |
| 72 }; | 69 }; |
| 73 | 70 |
| 74 #endif // CHROME_BROWSER_PREFS_INCOGNITO_USER_PREF_STORE_H_ | 71 #endif // CHROME_BROWSER_PREFS_INCOGNITO_USER_PREF_STORE_H_ |
| OLD | NEW |