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 synchronously, on the | |
118 // next write event of |writer_|. | |
119 // |on_next_write_callback| must be thread-safe. | |
120 void RegisterOnNextWriteSynchronousCallback( | |
gab
2016/09/21 17:49:59
Just realized from https://codereview.chromium.org
| |
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_|. | |
188 // Otherwise, re-registers |on_next_successful_write_|. | |
189 void RunOrScheduleNextSuccessfulWriteCallback(bool write_success); | |
190 | |
191 // Handles the result of a write with result |write_success|. Runs | |
192 // |on_next_write| callback on the current thread and posts | |
193 // |RunOrScheduleNextSuccessfulWriteCallback| on |reply_task_runner|. | |
194 static void PostWriteCallback( | |
195 const base::Callback<void(bool success)>& on_next_write_reply, | |
196 const base::Callback<void(bool success)>& on_next_write_callback, | |
197 scoped_refptr<base::SequencedTaskRunner> reply_task_runner, | |
198 bool write_success); | |
199 | |
177 // This method is called after the JSON file has been read. It then hands | 200 // 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 | 201 // |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 | 202 // |pref_filter| if one is set. It also gives a callback pointing at |
180 // FinalizeFileRead() to that |pref_filter_| which is then responsible for | 203 // FinalizeFileRead() to that |pref_filter_| which is then responsible for |
181 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead() | 204 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead() |
182 // is invoked directly. | 205 // is invoked directly. |
183 void OnFileRead(std::unique_ptr<ReadResult> read_result); | 206 void OnFileRead(std::unique_ptr<ReadResult> read_result); |
184 | 207 |
185 // ImportantFileWriter::DataSerializer overrides: | 208 // ImportantFileWriter::DataSerializer overrides: |
186 bool SerializeData(std::string* output) override; | 209 bool SerializeData(std::string* output) override; |
(...skipping 29 matching lines...) Expand all Loading... | |
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 |
249 bool has_pending_successful_write_reply_; | |
250 bool has_pending_write_callback_; | |
251 base::Closure on_next_successful_write_reply_; | |
252 | |
226 WriteCountHistogram write_count_histogram_; | 253 WriteCountHistogram write_count_histogram_; |
227 | 254 |
228 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); | 255 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
229 }; | 256 }; |
230 | 257 |
231 #endif // COMPONENTS_PREFS_JSON_PREF_STORE_H_ | 258 #endif // COMPONENTS_PREFS_JSON_PREF_STORE_H_ |
OLD | NEW |