| OLD | NEW |
| (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_TESTING_PREF_STORE_H_ | |
| 6 #define CHROME_BROWSER_PREFS_TESTING_PREF_STORE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/observer_list.h" | |
| 13 #include "chrome/browser/prefs/pref_value_map.h" | |
| 14 #include "chrome/common/persistent_pref_store.h" | |
| 15 | |
| 16 // |TestingPrefStore| is a preference store implementation that allows tests to | |
| 17 // explicitly manipulate the contents of the store, triggering notifications | |
| 18 // where appropriate. | |
| 19 class TestingPrefStore : public PersistentPrefStore { | |
| 20 public: | |
| 21 TestingPrefStore(); | |
| 22 | |
| 23 // Overriden from PrefStore. | |
| 24 virtual ReadResult GetValue(const std::string& key, | |
| 25 const base::Value** result) const OVERRIDE; | |
| 26 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; | |
| 27 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; | |
| 28 virtual size_t NumberOfObservers() const OVERRIDE; | |
| 29 virtual bool IsInitializationComplete() const OVERRIDE; | |
| 30 | |
| 31 // PersistentPrefStore overrides: | |
| 32 virtual ReadResult GetMutableValue(const std::string& key, | |
| 33 base::Value** result) OVERRIDE; | |
| 34 virtual void ReportValueChanged(const std::string& key) OVERRIDE; | |
| 35 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE; | |
| 36 virtual void SetValueSilently(const std::string& key, | |
| 37 base::Value* value) OVERRIDE; | |
| 38 virtual void RemoveValue(const std::string& key) OVERRIDE; | |
| 39 virtual void MarkNeedsEmptyValue(const std::string& key) OVERRIDE; | |
| 40 virtual bool ReadOnly() const OVERRIDE; | |
| 41 virtual PrefReadError GetReadError() const OVERRIDE; | |
| 42 virtual PersistentPrefStore::PrefReadError ReadPrefs() OVERRIDE; | |
| 43 virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) OVERRIDE; | |
| 44 virtual void CommitPendingWrite() OVERRIDE {} | |
| 45 | |
| 46 // Marks the store as having completed initialization. | |
| 47 void SetInitializationCompleted(); | |
| 48 | |
| 49 // Used for tests to trigger notifications explicitly. | |
| 50 void NotifyPrefValueChanged(const std::string& key); | |
| 51 void NotifyInitializationCompleted(); | |
| 52 | |
| 53 // Some convenience getters/setters. | |
| 54 void SetString(const std::string& key, const std::string& value); | |
| 55 void SetInteger(const std::string& key, int value); | |
| 56 void SetBoolean(const std::string& key, bool value); | |
| 57 | |
| 58 bool GetString(const std::string& key, std::string* value) const; | |
| 59 bool GetInteger(const std::string& key, int* value) const; | |
| 60 bool GetBoolean(const std::string& key, bool* value) const; | |
| 61 | |
| 62 // Getter and Setter methods for setting and getting the state of the | |
| 63 // |TestingPrefStore|. | |
| 64 virtual void set_read_only(bool read_only); | |
| 65 | |
| 66 protected: | |
| 67 virtual ~TestingPrefStore(); | |
| 68 | |
| 69 private: | |
| 70 // Stores the preference values. | |
| 71 PrefValueMap prefs_; | |
| 72 | |
| 73 // Flag that indicates if the PrefStore is read-only | |
| 74 bool read_only_; | |
| 75 | |
| 76 // Whether initialization has been completed. | |
| 77 bool init_complete_; | |
| 78 | |
| 79 ObserverList<PrefStore::Observer, true> observers_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(TestingPrefStore); | |
| 82 }; | |
| 83 | |
| 84 #endif // CHROME_BROWSER_PREFS_TESTING_PREF_STORE_H_ | |
| OLD | NEW |