Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_TESTING_PREF_STORE_H_ | 5 #ifndef CHROME_BROWSER_PREFS_TESTING_PREF_STORE_H_ |
| 6 #define CHROME_BROWSER_PREFS_TESTING_PREF_STORE_H_ | 6 #define CHROME_BROWSER_PREFS_TESTING_PREF_STORE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/observer_list.h" | |
| 10 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 11 #include "chrome/common/pref_store_base.h" | 12 #include "chrome/common/persistent_pref_store.h" |
| 13 #include "chrome/browser/prefs/pref_value_map.h" | |
|
danno
2010/12/08 13:08:45
alphabetize
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Done.
| |
| 12 | 14 |
| 13 class DictionaryValue; | 15 class DictionaryValue; |
| 14 | 16 |
| 15 // |TestingPrefStore| is a stub implementation of the |PrefStore| interface. | 17 // |TestingPrefStore| is a stub implementation of the |PrefStore| interface. |
|
danno
2010/12/08 13:08:45
|PersistentPrefStore|, but how about just:
|Testin
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Done.
| |
| 16 // It allows to get and set the state of the |PrefStore| as well as triggering | 18 // It allows to get and set the state of the |PrefStore| as well as triggering |
| 17 // notifications. | 19 // notifications. |
| 18 class TestingPrefStore : public PrefStoreBase { | 20 class TestingPrefStore : public PersistentPrefStore { |
| 19 public: | 21 public: |
| 20 TestingPrefStore(); | 22 TestingPrefStore(); |
| 21 virtual ~TestingPrefStore() {} | 23 virtual ~TestingPrefStore() {} |
| 22 | 24 |
| 23 virtual DictionaryValue* prefs() const { return prefs_.get(); } | 25 // PersistentPrefStore overrides: |
| 24 | 26 virtual ReadResult GetValue(const std::string& key, Value** result) const; |
|
danno
2010/12/08 13:08:45
Since GetValue is inherited from PersistentPrefSto
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Done.
| |
| 25 virtual PrefStore::PrefReadError ReadPrefs(); | 27 virtual void SetValue(const std::string& key, Value* value); |
| 26 | 28 virtual void SetValueSilently(const std::string& key, Value* value); |
| 29 virtual void RemoveValue(const std::string& key); | |
| 27 virtual bool ReadOnly() const { return read_only_; } | 30 virtual bool ReadOnly() const { return read_only_; } |
| 28 | 31 virtual PersistentPrefStore::PrefReadError ReadPrefs(); |
| 29 virtual bool WritePrefs(); | 32 virtual bool WritePrefs(); |
| 33 virtual void ScheduleWritePrefs() {} | |
| 30 | 34 |
| 31 // Getter and Setter methods for setting and getting the state of the | 35 // Getter and Setter methods for setting and getting the state of the |
| 32 // |DummyPrefStore|. | 36 // |TestingPrefStore|. |
| 33 virtual void set_read_only(bool read_only) { read_only_ = read_only; } | 37 virtual void set_read_only(bool read_only) { read_only_ = read_only; } |
| 34 virtual void set_prefs(DictionaryValue* prefs) { prefs_.reset(prefs); } | |
| 35 virtual void set_prefs_written(bool status) { prefs_written_ = status; } | 38 virtual void set_prefs_written(bool status) { prefs_written_ = status; } |
| 36 virtual bool get_prefs_written() { return prefs_written_; } | 39 virtual bool get_prefs_written() { return prefs_written_; } |
| 37 | 40 |
| 38 // Publish these functions so testing code can call them. | |
| 39 virtual void NotifyPrefValueChanged(const std::string& key); | |
| 40 virtual void NotifyInitializationCompleted(); | |
| 41 | |
| 42 // Whether the store has completed all asynchronous initialization. | 41 // Whether the store has completed all asynchronous initialization. |
| 43 virtual bool IsInitializationComplete() { return init_complete_; } | 42 virtual bool IsInitializationComplete() { return init_complete_; } |
| 44 | 43 |
| 45 // Mark the store as having completed initialization. | 44 // Marks the store as having completed initialization. |
| 46 void SetInitializationCompleted(); | 45 void SetInitializationCompleted(); |
| 47 | 46 |
| 47 // Used for tests to trigger notifications explicitly. | |
| 48 void NotifyPrefValueChanged(const std::string& key); | |
| 49 void NotifyInitializationCompleted(); | |
| 50 | |
| 51 // Some convenience getters/setters. | |
| 52 void SetString(const std::string& key, const std::string& value); | |
| 53 void SetInteger(const std::string& key, int value); | |
| 54 void SetBoolean(const std::string& key, bool value); | |
| 55 | |
| 56 bool GetString(const std::string& key, std::string* value); | |
|
battre (please use the other)
2010/12/08 12:24:15
const? maybe not because it is a testing class? -
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Done.
| |
| 57 bool GetInteger(const std::string& key, int* value); | |
| 58 bool GetBoolean(const std::string& key, bool* value); | |
| 59 | |
| 48 private: | 60 private: |
| 49 scoped_ptr<DictionaryValue> prefs_; | 61 // Overriden from PrefStore. |
| 62 virtual void AddObserver(PrefStore::ObserverInterface* observer); | |
| 63 virtual void RemoveObserver(PrefStore::ObserverInterface* observer); | |
|
danno
2010/12/08 13:08:45
Why are these made private? Seems like for testing
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Done.
| |
| 64 | |
| 65 // Stores the preference values. | |
| 66 PrefValueMap prefs_; | |
| 50 | 67 |
| 51 // Flag that indicates if the PrefStore is read-only | 68 // Flag that indicates if the PrefStore is read-only |
| 52 bool read_only_; | 69 bool read_only_; |
| 53 | 70 |
| 54 // Flag that indicates if the method WritePrefs was called. | 71 // Flag that indicates if the method WritePrefs was called. |
| 55 bool prefs_written_; | 72 bool prefs_written_; |
| 56 | 73 |
| 57 // Whether initialization has been completed. | 74 // Whether initialization has been completed. |
| 58 bool init_complete_; | 75 bool init_complete_; |
| 59 | 76 |
| 77 ObserverList<PrefStore::ObserverInterface, true> observers_; | |
| 78 | |
| 60 DISALLOW_COPY_AND_ASSIGN(TestingPrefStore); | 79 DISALLOW_COPY_AND_ASSIGN(TestingPrefStore); |
| 61 }; | 80 }; |
| 62 | 81 |
| 63 #endif // CHROME_BROWSER_PREFS_TESTING_PREF_STORE_H_ | 82 #endif // CHROME_BROWSER_PREFS_TESTING_PREF_STORE_H_ |
| OLD | NEW |