Chromium Code Reviews| 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" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 base::Value** result) OVERRIDE; | 33 base::Value** result) OVERRIDE; |
| 34 virtual void ReportValueChanged(const std::string& key) OVERRIDE; | 34 virtual void ReportValueChanged(const std::string& key) OVERRIDE; |
| 35 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE; | 35 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE; |
| 36 virtual void SetValueSilently(const std::string& key, | 36 virtual void SetValueSilently(const std::string& key, |
| 37 base::Value* value) OVERRIDE; | 37 base::Value* value) OVERRIDE; |
| 38 virtual void RemoveValue(const std::string& key) OVERRIDE; | 38 virtual void RemoveValue(const std::string& key) OVERRIDE; |
| 39 virtual bool ReadOnly() const OVERRIDE; | 39 virtual bool ReadOnly() const OVERRIDE; |
| 40 virtual PrefReadError GetReadError() const OVERRIDE; | 40 virtual PrefReadError GetReadError() const OVERRIDE; |
| 41 virtual PersistentPrefStore::PrefReadError ReadPrefs() OVERRIDE; | 41 virtual PersistentPrefStore::PrefReadError ReadPrefs() OVERRIDE; |
| 42 virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) OVERRIDE; | 42 virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) OVERRIDE; |
| 43 virtual void CommitPendingWrite() OVERRIDE {} | 43 virtual void CommitPendingWrite() OVERRIDE; |
| 44 | 44 |
| 45 // Marks the store as having completed initialization. | 45 // Marks the store as having completed initialization. |
| 46 void SetInitializationCompleted(); | 46 void SetInitializationCompleted(); |
| 47 | 47 |
| 48 // Used for tests to trigger notifications explicitly. | 48 // Used for tests to trigger notifications explicitly. |
| 49 void NotifyPrefValueChanged(const std::string& key); | 49 void NotifyPrefValueChanged(const std::string& key); |
| 50 void NotifyInitializationCompleted(); | 50 void NotifyInitializationCompleted(); |
| 51 | 51 |
| 52 // Some convenience getters/setters. | 52 // Some convenience getters/setters. |
| 53 void SetString(const std::string& key, const std::string& value); | 53 void SetString(const std::string& key, const std::string& value); |
| 54 void SetInteger(const std::string& key, int value); | 54 void SetInteger(const std::string& key, int value); |
| 55 void SetBoolean(const std::string& key, bool value); | 55 void SetBoolean(const std::string& key, bool value); |
| 56 | 56 |
| 57 bool GetString(const std::string& key, std::string* value) const; | 57 bool GetString(const std::string& key, std::string* value) const; |
| 58 bool GetInteger(const std::string& key, int* value) const; | 58 bool GetInteger(const std::string& key, int* value) const; |
| 59 bool GetBoolean(const std::string& key, bool* value) const; | 59 bool GetBoolean(const std::string& key, bool* value) const; |
| 60 | 60 |
| 61 // Determines whether ReadPrefsAsync completes immediately. Defaults to false | |
| 62 // (non-blocking). To block, invoke this with true (blocking) before the call | |
| 63 // to ReadPrefsAsync. To unblock, invoke again with false (non-blocking) after | |
| 64 // the call to ReadPrefsAsync. | |
| 65 void SetBlockAsyncRead(bool block_async_read); | |
| 66 | |
| 61 // Getter and Setter methods for setting and getting the state of the | 67 // Getter and Setter methods for setting and getting the state of the |
| 62 // |TestingPrefStore|. | 68 // |TestingPrefStore|. |
| 63 virtual void set_read_only(bool read_only); | 69 virtual void set_read_only(bool read_only); |
| 70 void set_read_success(bool read_success); | |
| 71 void set_read_error(PersistentPrefStore::PrefReadError read_error); | |
| 72 bool committed() { return committed_; } | |
| 64 | 73 |
| 65 protected: | 74 protected: |
| 66 virtual ~TestingPrefStore(); | 75 virtual ~TestingPrefStore(); |
| 67 | 76 |
| 68 private: | 77 private: |
| 69 // Stores the preference values. | 78 // Stores the preference values. |
| 70 PrefValueMap prefs_; | 79 PrefValueMap prefs_; |
| 71 | 80 |
| 72 // Flag that indicates if the PrefStore is read-only | 81 // Flag that indicates if the PrefStore is read-only |
| 73 bool read_only_; | 82 bool read_only_; |
| 74 | 83 |
| 84 // The result to pass to PrefStore::Observer::OnInitializationCompleted | |
| 85 bool read_success_; | |
| 86 | |
| 87 // The result to return from ReadPrefs or ReadPrefsAsync. | |
| 88 PersistentPrefStore::PrefReadError read_error_; | |
| 89 | |
| 90 // Whether a call to ReadPrefsAsync should block. | |
| 91 bool block_async_read_; | |
| 92 | |
| 93 // Whether there is a pending call to ReadPrefsAsync. | |
| 94 bool pending_async_read_; | |
| 95 | |
| 75 // Whether initialization has been completed. | 96 // Whether initialization has been completed. |
| 76 bool init_complete_; | 97 bool init_complete_; |
| 77 | 98 |
| 99 // Whether the store contents have been committed to disk since the last | |
| 100 // mutation. | |
| 101 bool committed_; | |
| 102 | |
| 103 scoped_ptr<ReadErrorDelegate> error_delegate_; | |
|
Mattias Nissler (ping if slow)
2014/03/27 20:28:05
Why is this a scoped_ptr? In production PrefStore
erikwright (departed)
2014/03/28 12:29:22
No, see JsonPrefStore. scoped_ptr, held for the li
Mattias Nissler (ping if slow)
2014/03/28 12:32:53
Ah, right, my bad.
| |
| 78 ObserverList<PrefStore::Observer, true> observers_; | 104 ObserverList<PrefStore::Observer, true> observers_; |
| 79 | 105 |
| 80 DISALLOW_COPY_AND_ASSIGN(TestingPrefStore); | 106 DISALLOW_COPY_AND_ASSIGN(TestingPrefStore); |
| 81 }; | 107 }; |
| 82 | 108 |
| 83 #endif // BASE_PREFS_TESTING_PREF_STORE_H_ | 109 #endif // BASE_PREFS_TESTING_PREF_STORE_H_ |
| OLD | NEW |