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 COMPONENTS_PREFS_JSON_PREF_STORE_H_ | 5 #ifndef COMPONENTS_PREFS_JSON_PREF_STORE_H_ |
6 #define COMPONENTS_PREFS_JSON_PREF_STORE_H_ | 6 #define COMPONENTS_PREFS_JSON_PREF_STORE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "components/prefs/base_prefs_export.h" | 23 #include "components/prefs/base_prefs_export.h" |
24 #include "components/prefs/persistent_pref_store.h" | 24 #include "components/prefs/persistent_pref_store.h" |
25 | 25 |
26 class PrefFilter; | 26 class PrefFilter; |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 class Clock; | 29 class Clock; |
30 class DictionaryValue; | 30 class DictionaryValue; |
31 class FilePath; | 31 class FilePath; |
32 class HistogramBase; | 32 class HistogramBase; |
33 class JsonPrefStoreCallbackTest; | |
33 class JsonPrefStoreLossyWriteTest; | 34 class JsonPrefStoreLossyWriteTest; |
34 class SequencedTaskRunner; | 35 class SequencedTaskRunner; |
35 class SequencedWorkerPool; | 36 class SequencedWorkerPool; |
36 class Value; | 37 class Value; |
37 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestBasic); | 38 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestBasic); |
38 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestSinglePeriod); | 39 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestSinglePeriod); |
39 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestMultiplePeriods); | 40 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestMultiplePeriods); |
40 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestPeriodWithGaps); | 41 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestPeriodWithGaps); |
41 } | 42 } |
42 | 43 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 PrefReadError ReadPrefs() override; | 100 PrefReadError ReadPrefs() override; |
100 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; | 101 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; |
101 void CommitPendingWrite() override; | 102 void CommitPendingWrite() override; |
102 void SchedulePendingLossyWrites() override; | 103 void SchedulePendingLossyWrites() override; |
103 void ReportValueChanged(const std::string& key, uint32_t flags) override; | 104 void ReportValueChanged(const std::string& key, uint32_t flags) override; |
104 | 105 |
105 // Just like RemoveValue(), but doesn't notify observers. Used when doing some | 106 // Just like RemoveValue(), but doesn't notify observers. Used when doing some |
106 // cleanup that shouldn't otherwise alert observers. | 107 // cleanup that shouldn't otherwise alert observers. |
107 void RemoveValueSilently(const std::string& key, uint32_t flags); | 108 void RemoveValueSilently(const std::string& key, uint32_t flags); |
108 | 109 |
109 // Registers |on_next_successful_write| to be called once, on the next | 110 // Registers |on_next_successful_write_reply| to be called once, on the next |
110 // successful write event of |writer_|. | 111 // successful write event of |writer_|. |
111 void RegisterOnNextSuccessfulWriteCallback( | 112 // |on_next_successful_write_reply| will be called on the thread from which |
112 const base::Closure& on_next_successful_write); | 113 // this method is called and does not need to be thread safe. |
114 void RegisterOnNextSuccessfulWriteReply( | |
115 const base::Closure& on_next_successful_write_reply); | |
116 | |
117 // Registers |on_next_write_callback| to be called once, on the | |
gab
2016/09/19 18:01:30
... to be called once, synchronously, on the ...
proberge
2016/09/20 15:15:52
Done.
| |
118 // next write event of |writer_|. | |
119 // |on_next_write_callback| must be thread-safe. | |
120 void RegisterOnNextWriteCallback( | |
gab
2016/09/19 18:01:30
RegisterOnNextWriteSynchronousCallback
proberge
2016/09/19 21:24:25
I don't think RegisterOnNextWriteSynchronousCallba
gab
2016/09/20 01:27:41
Well this use case is very much an edge case, I wo
proberge
2016/09/20 15:15:52
Done.
| |
121 const base::Callback<void(bool success)>& on_next_write_callback); | |
113 | 122 |
114 void ClearMutableValues() override; | 123 void ClearMutableValues() override; |
115 | 124 |
116 private: | 125 private: |
117 // Represents a histogram for recording the number of writes to the pref file | 126 // Represents a histogram for recording the number of writes to the pref file |
118 // that occur every kHistogramWriteReportIntervalInMins minutes. | 127 // that occur every kHistogramWriteReportIntervalInMins minutes. |
119 class COMPONENTS_PREFS_EXPORT WriteCountHistogram { | 128 class COMPONENTS_PREFS_EXPORT WriteCountHistogram { |
120 public: | 129 public: |
121 static const int32_t kHistogramWriteReportIntervalMins; | 130 static const int32_t kHistogramWriteReportIntervalMins; |
122 | 131 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 }; | 172 }; |
164 | 173 |
165 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, | 174 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, |
166 WriteCountHistogramTestBasic); | 175 WriteCountHistogramTestBasic); |
167 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, | 176 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, |
168 WriteCountHistogramTestSinglePeriod); | 177 WriteCountHistogramTestSinglePeriod); |
169 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, | 178 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, |
170 WriteCountHistogramTestMultiplePeriods); | 179 WriteCountHistogramTestMultiplePeriods); |
171 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, | 180 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, |
172 WriteCountHistogramTestPeriodWithGaps); | 181 WriteCountHistogramTestPeriodWithGaps); |
182 friend class base::JsonPrefStoreCallbackTest; | |
173 friend class base::JsonPrefStoreLossyWriteTest; | 183 friend class base::JsonPrefStoreLossyWriteTest; |
174 | 184 |
175 ~JsonPrefStore() override; | 185 ~JsonPrefStore() override; |
176 | 186 |
187 // If |write_success| is true, runs |on_next_successful_write| on | |
188 // |reply_task_runner|. Otherwise, re-registers |on_next_successful_write| | |
189 // on |calling_store|. | |
190 static void PostWriteCallback( | |
191 base::WeakPtr<JsonPrefStore> calling_store, | |
192 const base::Callback<void(bool success)>& on_next_successful_write, | |
193 scoped_refptr<base::SequencedTaskRunner> reply_task_runner, | |
194 bool write_success); | |
195 | |
177 // This method is called after the JSON file has been read. It then hands | 196 // This method is called after the JSON file has been read. It then hands |
178 // |value| (or an empty dictionary in some read error cases) to the | 197 // |value| (or an empty dictionary in some read error cases) to the |
179 // |pref_filter| if one is set. It also gives a callback pointing at | 198 // |pref_filter| if one is set. It also gives a callback pointing at |
180 // FinalizeFileRead() to that |pref_filter_| which is then responsible for | 199 // FinalizeFileRead() to that |pref_filter_| which is then responsible for |
181 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead() | 200 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead() |
182 // is invoked directly. | 201 // is invoked directly. |
183 void OnFileRead(std::unique_ptr<ReadResult> read_result); | 202 void OnFileRead(std::unique_ptr<ReadResult> read_result); |
184 | 203 |
185 // ImportantFileWriter::DataSerializer overrides: | 204 // ImportantFileWriter::DataSerializer overrides: |
186 bool SerializeData(std::string* output) override; | 205 bool SerializeData(std::string* output) override; |
(...skipping 12 matching lines...) Expand all Loading... | |
199 // Schedule a write with the file writer as long as |flags| doesn't contain | 218 // Schedule a write with the file writer as long as |flags| doesn't contain |
200 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG. | 219 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG. |
201 void ScheduleWrite(uint32_t flags); | 220 void ScheduleWrite(uint32_t flags); |
202 | 221 |
203 const base::FilePath path_; | 222 const base::FilePath path_; |
204 const base::FilePath alternate_path_; | 223 const base::FilePath alternate_path_; |
205 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 224 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
206 | 225 |
207 std::unique_ptr<base::DictionaryValue> prefs_; | 226 std::unique_ptr<base::DictionaryValue> prefs_; |
208 | 227 |
228 bool has_pending_successful_write_reply_; | |
229 bool has_pending_write_callback_; | |
230 base::Closure on_next_successful_write_reply_; | |
231 | |
209 bool read_only_; | 232 bool read_only_; |
210 | 233 |
211 // Helper for safely writing pref data. | 234 // Helper for safely writing pref data. |
212 base::ImportantFileWriter writer_; | 235 base::ImportantFileWriter writer_; |
213 | 236 |
214 std::unique_ptr<PrefFilter> pref_filter_; | 237 std::unique_ptr<PrefFilter> pref_filter_; |
215 base::ObserverList<PrefStore::Observer, true> observers_; | 238 base::ObserverList<PrefStore::Observer, true> observers_; |
216 | 239 |
217 std::unique_ptr<ReadErrorDelegate> error_delegate_; | 240 std::unique_ptr<ReadErrorDelegate> error_delegate_; |
218 | 241 |
219 bool initialized_; | 242 bool initialized_; |
220 bool filtering_in_progress_; | 243 bool filtering_in_progress_; |
221 bool pending_lossy_write_; | 244 bool pending_lossy_write_; |
222 PrefReadError read_error_; | 245 PrefReadError read_error_; |
223 | 246 |
224 std::set<std::string> keys_need_empty_value_; | 247 std::set<std::string> keys_need_empty_value_; |
225 | 248 |
226 WriteCountHistogram write_count_histogram_; | 249 WriteCountHistogram write_count_histogram_; |
227 | 250 |
228 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); | 251 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
229 }; | 252 }; |
230 | 253 |
231 #endif // COMPONENTS_PREFS_JSON_PREF_STORE_H_ | 254 #endif // COMPONENTS_PREFS_JSON_PREF_STORE_H_ |
OLD | NEW |