| 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 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 <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "chrome/browser/prefs/pref_value_map.h" | 14 #include "chrome/browser/prefs/pref_value_map.h" |
| 15 #include "chrome/common/persistent_pref_store.h" | 15 #include "chrome/common/persistent_pref_store.h" |
| 16 | 16 |
| 17 // |TestingPrefStore| is a preference store implementation that allows tests to | 17 // |TestingPrefStore| is a preference store implementation that allows tests to |
| 18 // explicitly manipulate the contents of the store, triggering notifications | 18 // explicitly manipulate the contents of the store, triggering notifications |
| 19 // where appropriate. | 19 // where appropriate. |
| 20 class TestingPrefStore : public PersistentPrefStore { | 20 class TestingPrefStore : public PersistentPrefStore { |
| 21 public: | 21 public: |
| 22 TestingPrefStore(); | 22 TestingPrefStore(); |
| 23 virtual ~TestingPrefStore(); | |
| 24 | 23 |
| 25 // Overriden from PrefStore. | 24 // Overriden from PrefStore. |
| 26 virtual ReadResult GetValue(const std::string& key, | 25 virtual ReadResult GetValue(const std::string& key, |
| 27 const base::Value** result) const OVERRIDE; | 26 const base::Value** result) const OVERRIDE; |
| 28 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; | 27 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; |
| 29 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; | 28 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; |
| 30 virtual size_t NumberOfObservers() const OVERRIDE; | 29 virtual size_t NumberOfObservers() const OVERRIDE; |
| 31 virtual bool IsInitializationComplete() const OVERRIDE; | 30 virtual bool IsInitializationComplete() const OVERRIDE; |
| 32 | 31 |
| 33 // PersistentPrefStore overrides: | 32 // PersistentPrefStore overrides: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 58 void SetBoolean(const std::string& key, bool value); | 57 void SetBoolean(const std::string& key, bool value); |
| 59 | 58 |
| 60 bool GetString(const std::string& key, std::string* value) const; | 59 bool GetString(const std::string& key, std::string* value) const; |
| 61 bool GetInteger(const std::string& key, int* value) const; | 60 bool GetInteger(const std::string& key, int* value) const; |
| 62 bool GetBoolean(const std::string& key, bool* value) const; | 61 bool GetBoolean(const std::string& key, bool* value) const; |
| 63 | 62 |
| 64 // Getter and Setter methods for setting and getting the state of the | 63 // Getter and Setter methods for setting and getting the state of the |
| 65 // |TestingPrefStore|. | 64 // |TestingPrefStore|. |
| 66 virtual void set_read_only(bool read_only); | 65 virtual void set_read_only(bool read_only); |
| 67 | 66 |
| 67 protected: |
| 68 virtual ~TestingPrefStore(); |
| 69 |
| 68 private: | 70 private: |
| 69 // Stores the preference values. | 71 // Stores the preference values. |
| 70 PrefValueMap prefs_; | 72 PrefValueMap prefs_; |
| 71 | 73 |
| 72 // Flag that indicates if the PrefStore is read-only | 74 // Flag that indicates if the PrefStore is read-only |
| 73 bool read_only_; | 75 bool read_only_; |
| 74 | 76 |
| 75 // Flag that indicates if the method WritePrefs was called. | 77 // Flag that indicates if the method WritePrefs was called. |
| 76 bool prefs_written_; | 78 bool prefs_written_; |
| 77 | 79 |
| 78 // Whether initialization has been completed. | 80 // Whether initialization has been completed. |
| 79 bool init_complete_; | 81 bool init_complete_; |
| 80 | 82 |
| 81 ObserverList<PrefStore::Observer, true> observers_; | 83 ObserverList<PrefStore::Observer, true> observers_; |
| 82 | 84 |
| 83 DISALLOW_COPY_AND_ASSIGN(TestingPrefStore); | 85 DISALLOW_COPY_AND_ASSIGN(TestingPrefStore); |
| 84 }; | 86 }; |
| 85 | 87 |
| 86 #endif // CHROME_BROWSER_PREFS_TESTING_PREF_STORE_H_ | 88 #endif // CHROME_BROWSER_PREFS_TESTING_PREF_STORE_H_ |
| OLD | NEW |