| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 BASE_PREFS_TESTING_PREF_STORE_H_ | 5 #ifndef BASE_PREFS_TESTING_PREF_STORE_H_ |
| 6 #define BASE_PREFS_TESTING_PREF_STORE_H_ | 6 #define BASE_PREFS_TESTING_PREF_STORE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "base/prefs/persistent_pref_store.h" | 13 #include "base/prefs/persistent_pref_store.h" |
| 14 #include "base/prefs/pref_value_map.h" | 14 #include "base/prefs/pref_value_map.h" |
| 15 | 15 |
| 16 // |TestingPrefStore| is a preference store implementation that allows tests to | 16 // |TestingPrefStore| is a preference store implementation that allows tests to |
| 17 // explicitly manipulate the contents of the store, triggering notifications | 17 // explicitly manipulate the contents of the store, triggering notifications |
| 18 // where appropriate. | 18 // where appropriate. |
| 19 class TestingPrefStore : public PersistentPrefStore { | 19 class TestingPrefStore : public PersistentPrefStore { |
| 20 public: | 20 public: |
| 21 TestingPrefStore(); | 21 TestingPrefStore(); |
| 22 | 22 |
| 23 // Overriden from PrefStore. | 23 // Overriden from PrefStore. |
| 24 virtual bool GetValue(const std::string& key, | 24 bool GetValue(const std::string& key, |
| 25 const base::Value** result) const override; | 25 const base::Value** result) const override; |
| 26 virtual void AddObserver(PrefStore::Observer* observer) override; | 26 void AddObserver(PrefStore::Observer* observer) override; |
| 27 virtual void RemoveObserver(PrefStore::Observer* observer) override; | 27 void RemoveObserver(PrefStore::Observer* observer) override; |
| 28 virtual bool HasObservers() const override; | 28 bool HasObservers() const override; |
| 29 virtual bool IsInitializationComplete() const override; | 29 bool IsInitializationComplete() const override; |
| 30 | 30 |
| 31 // PersistentPrefStore overrides: | 31 // PersistentPrefStore overrides: |
| 32 virtual bool GetMutableValue(const std::string& key, | 32 bool GetMutableValue(const std::string& key, base::Value** result) override; |
| 33 base::Value** result) override; | 33 void ReportValueChanged(const std::string& key) override; |
| 34 virtual void ReportValueChanged(const std::string& key) override; | 34 void SetValue(const std::string& key, base::Value* value) override; |
| 35 virtual void SetValue(const std::string& key, base::Value* value) override; | 35 void SetValueSilently(const std::string& key, base::Value* value) override; |
| 36 virtual void SetValueSilently(const std::string& key, | 36 void RemoveValue(const std::string& key) override; |
| 37 base::Value* value) override; | 37 bool ReadOnly() const override; |
| 38 virtual void RemoveValue(const std::string& key) override; | 38 PrefReadError GetReadError() const override; |
| 39 virtual bool ReadOnly() const override; | 39 PersistentPrefStore::PrefReadError ReadPrefs() override; |
| 40 virtual PrefReadError GetReadError() const override; | 40 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; |
| 41 virtual PersistentPrefStore::PrefReadError ReadPrefs() override; | 41 void CommitPendingWrite() override; |
| 42 virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; | |
| 43 virtual void CommitPendingWrite() override; | |
| 44 | 42 |
| 45 // Marks the store as having completed initialization. | 43 // Marks the store as having completed initialization. |
| 46 void SetInitializationCompleted(); | 44 void SetInitializationCompleted(); |
| 47 | 45 |
| 48 // Used for tests to trigger notifications explicitly. | 46 // Used for tests to trigger notifications explicitly. |
| 49 void NotifyPrefValueChanged(const std::string& key); | 47 void NotifyPrefValueChanged(const std::string& key); |
| 50 void NotifyInitializationCompleted(); | 48 void NotifyInitializationCompleted(); |
| 51 | 49 |
| 52 // Some convenience getters/setters. | 50 // Some convenience getters/setters. |
| 53 void SetString(const std::string& key, const std::string& value); | 51 void SetString(const std::string& key, const std::string& value); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 65 void SetBlockAsyncRead(bool block_async_read); | 63 void SetBlockAsyncRead(bool block_async_read); |
| 66 | 64 |
| 67 // Getter and Setter methods for setting and getting the state of the | 65 // Getter and Setter methods for setting and getting the state of the |
| 68 // |TestingPrefStore|. | 66 // |TestingPrefStore|. |
| 69 virtual void set_read_only(bool read_only); | 67 virtual void set_read_only(bool read_only); |
| 70 void set_read_success(bool read_success); | 68 void set_read_success(bool read_success); |
| 71 void set_read_error(PersistentPrefStore::PrefReadError read_error); | 69 void set_read_error(PersistentPrefStore::PrefReadError read_error); |
| 72 bool committed() { return committed_; } | 70 bool committed() { return committed_; } |
| 73 | 71 |
| 74 protected: | 72 protected: |
| 75 virtual ~TestingPrefStore(); | 73 ~TestingPrefStore() override; |
| 76 | 74 |
| 77 private: | 75 private: |
| 78 // Stores the preference values. | 76 // Stores the preference values. |
| 79 PrefValueMap prefs_; | 77 PrefValueMap prefs_; |
| 80 | 78 |
| 81 // Flag that indicates if the PrefStore is read-only | 79 // Flag that indicates if the PrefStore is read-only |
| 82 bool read_only_; | 80 bool read_only_; |
| 83 | 81 |
| 84 // The result to pass to PrefStore::Observer::OnInitializationCompleted | 82 // The result to pass to PrefStore::Observer::OnInitializationCompleted |
| 85 bool read_success_; | 83 bool read_success_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 100 // mutation. | 98 // mutation. |
| 101 bool committed_; | 99 bool committed_; |
| 102 | 100 |
| 103 scoped_ptr<ReadErrorDelegate> error_delegate_; | 101 scoped_ptr<ReadErrorDelegate> error_delegate_; |
| 104 ObserverList<PrefStore::Observer, true> observers_; | 102 ObserverList<PrefStore::Observer, true> observers_; |
| 105 | 103 |
| 106 DISALLOW_COPY_AND_ASSIGN(TestingPrefStore); | 104 DISALLOW_COPY_AND_ASSIGN(TestingPrefStore); |
| 107 }; | 105 }; |
| 108 | 106 |
| 109 #endif // BASE_PREFS_TESTING_PREF_STORE_H_ | 107 #endif // BASE_PREFS_TESTING_PREF_STORE_H_ |
| OLD | NEW |