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_JSON_PREF_STORE_H_ | 5 #ifndef BASE_PREFS_JSON_PREF_STORE_H_ |
6 #define BASE_PREFS_JSON_PREF_STORE_H_ | 6 #define BASE_PREFS_JSON_PREF_STORE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // desired prefs may have previously been written to. If |pref_filename| | 59 // desired prefs may have previously been written to. If |pref_filename| |
60 // doesn't exist and |pref_alternate_filename| does, |pref_alternate_filename| | 60 // doesn't exist and |pref_alternate_filename| does, |pref_alternate_filename| |
61 // will be moved to |pref_filename| before the read occurs. | 61 // will be moved to |pref_filename| before the read occurs. |
62 JsonPrefStore( | 62 JsonPrefStore( |
63 const base::FilePath& pref_filename, | 63 const base::FilePath& pref_filename, |
64 const base::FilePath& pref_alternate_filename, | 64 const base::FilePath& pref_alternate_filename, |
65 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner, | 65 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner, |
66 scoped_ptr<PrefFilter> pref_filter); | 66 scoped_ptr<PrefFilter> pref_filter); |
67 | 67 |
68 // PrefStore overrides: | 68 // PrefStore overrides: |
69 virtual bool GetValue(const std::string& key, | 69 bool GetValue(const std::string& key, |
70 const base::Value** result) const OVERRIDE; | 70 const base::Value** result) const override; |
71 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; | 71 void AddObserver(PrefStore::Observer* observer) override; |
72 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; | 72 void RemoveObserver(PrefStore::Observer* observer) override; |
73 virtual bool HasObservers() const OVERRIDE; | 73 bool HasObservers() const override; |
74 virtual bool IsInitializationComplete() const OVERRIDE; | 74 bool IsInitializationComplete() const override; |
75 | 75 |
76 // PersistentPrefStore overrides: | 76 // PersistentPrefStore overrides: |
77 virtual bool GetMutableValue(const std::string& key, | 77 bool GetMutableValue(const std::string& key, base::Value** result) override; |
78 base::Value** result) OVERRIDE; | 78 void SetValue(const std::string& key, base::Value* value) override; |
79 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE; | 79 void SetValueSilently(const std::string& key, base::Value* value) override; |
80 virtual void SetValueSilently(const std::string& key, | 80 void RemoveValue(const std::string& key) override; |
81 base::Value* value) OVERRIDE; | 81 bool ReadOnly() const override; |
82 virtual void RemoveValue(const std::string& key) OVERRIDE; | 82 PrefReadError GetReadError() const override; |
83 virtual bool ReadOnly() const OVERRIDE; | |
84 virtual PrefReadError GetReadError() const OVERRIDE; | |
85 // Note this method may be asynchronous if this instance has a |pref_filter_| | 83 // Note this method may be asynchronous if this instance has a |pref_filter_| |
86 // in which case it will return PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE. | 84 // in which case it will return PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE. |
87 // See details in pref_filter.h. | 85 // See details in pref_filter.h. |
88 virtual PrefReadError ReadPrefs() OVERRIDE; | 86 PrefReadError ReadPrefs() override; |
89 virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) OVERRIDE; | 87 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; |
90 virtual void CommitPendingWrite() OVERRIDE; | 88 void CommitPendingWrite() override; |
91 virtual void ReportValueChanged(const std::string& key) OVERRIDE; | 89 void ReportValueChanged(const std::string& key) override; |
92 | 90 |
93 // Just like RemoveValue(), but doesn't notify observers. Used when doing some | 91 // Just like RemoveValue(), but doesn't notify observers. Used when doing some |
94 // cleanup that shouldn't otherwise alert observers. | 92 // cleanup that shouldn't otherwise alert observers. |
95 void RemoveValueSilently(const std::string& key); | 93 void RemoveValueSilently(const std::string& key); |
96 | 94 |
97 // Registers |on_next_successful_write| to be called once, on the next | 95 // Registers |on_next_successful_write| to be called once, on the next |
98 // successful write event of |writer_|. | 96 // successful write event of |writer_|. |
99 void RegisterOnNextSuccessfulWriteCallback( | 97 void RegisterOnNextSuccessfulWriteCallback( |
100 const base::Closure& on_next_successful_write); | 98 const base::Closure& on_next_successful_write); |
101 | 99 |
102 private: | 100 private: |
103 virtual ~JsonPrefStore(); | 101 virtual ~JsonPrefStore(); |
104 | 102 |
105 // This method is called after the JSON file has been read. It then hands | 103 // This method is called after the JSON file has been read. It then hands |
106 // |value| (or an empty dictionary in some read error cases) to the | 104 // |value| (or an empty dictionary in some read error cases) to the |
107 // |pref_filter| if one is set. It also gives a callback pointing at | 105 // |pref_filter| if one is set. It also gives a callback pointing at |
108 // FinalizeFileRead() to that |pref_filter_| which is then responsible for | 106 // FinalizeFileRead() to that |pref_filter_| which is then responsible for |
109 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead() | 107 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead() |
110 // is invoked directly. | 108 // is invoked directly. |
111 void OnFileRead(scoped_ptr<ReadResult> read_result); | 109 void OnFileRead(scoped_ptr<ReadResult> read_result); |
112 | 110 |
113 // ImportantFileWriter::DataSerializer overrides: | 111 // ImportantFileWriter::DataSerializer overrides: |
114 virtual bool SerializeData(std::string* output) OVERRIDE; | 112 bool SerializeData(std::string* output) override; |
115 | 113 |
116 // This method is called after the JSON file has been read and the result has | 114 // This method is called after the JSON file has been read and the result has |
117 // potentially been intercepted and modified by |pref_filter_|. | 115 // potentially been intercepted and modified by |pref_filter_|. |
118 // |initialization_successful| is pre-determined by OnFileRead() and should | 116 // |initialization_successful| is pre-determined by OnFileRead() and should |
119 // be used when reporting OnInitializationCompleted(). | 117 // be used when reporting OnInitializationCompleted(). |
120 // |schedule_write| indicates whether a write should be immediately scheduled | 118 // |schedule_write| indicates whether a write should be immediately scheduled |
121 // (typically because the |pref_filter_| has already altered the |prefs|) -- | 119 // (typically because the |pref_filter_| has already altered the |prefs|) -- |
122 // this will be ignored if this store is read-only. | 120 // this will be ignored if this store is read-only. |
123 void FinalizeFileRead(bool initialization_successful, | 121 void FinalizeFileRead(bool initialization_successful, |
124 scoped_ptr<base::DictionaryValue> prefs, | 122 scoped_ptr<base::DictionaryValue> prefs, |
(...skipping 18 matching lines...) Expand all Loading... |
143 bool initialized_; | 141 bool initialized_; |
144 bool filtering_in_progress_; | 142 bool filtering_in_progress_; |
145 PrefReadError read_error_; | 143 PrefReadError read_error_; |
146 | 144 |
147 std::set<std::string> keys_need_empty_value_; | 145 std::set<std::string> keys_need_empty_value_; |
148 | 146 |
149 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); | 147 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
150 }; | 148 }; |
151 | 149 |
152 #endif // BASE_PREFS_JSON_PREF_STORE_H_ | 150 #endif // BASE_PREFS_JSON_PREF_STORE_H_ |
OLD | NEW |