Chromium Code Reviews| Index: chrome/browser/prefs/hashed_pref_store.h |
| diff --git a/chrome/browser/prefs/hashed_pref_store.h b/chrome/browser/prefs/hashed_pref_store.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..678470d473cc3013515fe1a684139c11c6be989f |
| --- /dev/null |
| +++ b/chrome/browser/prefs/hashed_pref_store.h |
| @@ -0,0 +1,97 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_PREFS_HASHED_PREF_STORE_H_ |
| +#define CHROME_BROWSER_PREFS_HASHED_PREF_STORE_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/observer_list.h" |
| +#include "base/prefs/persistent_pref_store.h" |
| +#include "base/prefs/pref_store.h" |
| + |
| +class PrefHashStore; |
| + |
| +namespace base { |
| +class Value; |
| +} // namespace base |
| + |
| +// This interface is complementary to the PrefStore interface, declaring |
| +// additional functionality that adds support for setting values and persisting |
| +// the data to some backing store. |
| +class HashedPrefStore : public PersistentPrefStore { |
| + public: |
| + HashedPrefStore(const scoped_refptr<PersistentPrefStore>& pref_store, |
| + scoped_ptr<PrefHashStore> pref_hash_store); |
| + |
| + virtual bool GetMutableValue(const std::string& key, |
|
gab
2013/11/29 04:05:51
Having to override all of these methods just to fo
gab
2013/11/29 04:17:10
Actually, even simpler than a delegate would be to
|
| + base::Value** result) OVERRIDE; |
| + virtual void ReportValueChanged(const std::string& key) OVERRIDE; |
| + virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE; |
| + virtual void SetValueSilently(const std::string& key, base::Value* value) |
| + OVERRIDE; |
| + virtual void RemoveValue(const std::string& key) OVERRIDE; |
| + virtual void MarkNeedsEmptyValue(const std::string& key) OVERRIDE; |
| + virtual bool ReadOnly() const OVERRIDE; |
| + virtual PrefReadError GetReadError() const OVERRIDE; |
| + virtual PrefReadError ReadPrefs() OVERRIDE; |
| + virtual void ReadPrefsAsync( |
| + PersistentPrefStore::ReadErrorDelegate* error_delegate) OVERRIDE; |
| + virtual void CommitPendingWrite() OVERRIDE; |
| + virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; |
| + virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; |
| + virtual bool HasObservers() const OVERRIDE; |
| + virtual bool IsInitializationComplete() const OVERRIDE; |
| + virtual bool GetValue(const std::string& key, |
| + const base::Value** result) const OVERRIDE; |
| + |
| + protected: |
| + virtual ~HashedPrefStore() {} |
| + |
| + private: |
| + class PrefStoreObserver : public PrefStore::Observer { |
| + public: |
| + PrefStoreObserver( |
| + const scoped_refptr<PersistentPrefStore>& wrapped_pref_store, |
| + scoped_ptr<PrefHashStore> pref_hash_store); |
| + virtual ~PrefStoreObserver(); |
| + |
| + // PrefStore::Observer implementation. |
| + virtual void OnPrefValueChanged(const std::string& key) OVERRIDE; |
| + virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; |
| + |
| + PersistentPrefStore* wrapped_pref_store() { |
| + return wrapped_pref_store_; |
| + } |
| + const PersistentPrefStore* wrapped_pref_store() const { |
| + return wrapped_pref_store_; |
| + } |
| + ObserverList<PrefStore::Observer, true>& observers() { |
|
gab
2013/11/29 04:05:51
I don't think we allow return by non-const ref in
|
| + return observers_; |
| + } |
| + const ObserverList<PrefStore::Observer, true>& observers() const { |
| + return observers_; |
| + } |
| + |
| + private: |
| + bool initialized_; |
| + |
| + scoped_refptr<PersistentPrefStore> wrapped_pref_store_; |
| + |
| + ObserverList<PrefStore::Observer, true> observers_; |
| + scoped_ptr<PrefHashStore> pref_hash_store_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PrefStoreObserver); |
| + }; |
| + |
| + PrefStoreObserver internal_observer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(HashedPrefStore); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_PREFS_HASHED_PREF_STORE_H_ |