Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: base/prefs/json_pref_store.h

Issue 1127963002: Implement lossy pref behavior for JsonPrefStore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prefs-fix-flags
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/prefs/json_pref_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
22 #include "base/prefs/persistent_pref_store.h" 22 #include "base/prefs/persistent_pref_store.h"
23 #include "base/threading/non_thread_safe.h" 23 #include "base/threading/non_thread_safe.h"
24 24
25 class PrefFilter; 25 class PrefFilter;
26 26
27 namespace base { 27 namespace base {
28 class Clock; 28 class Clock;
29 class DictionaryValue; 29 class DictionaryValue;
30 class FilePath; 30 class FilePath;
31 class HistogramBase; 31 class HistogramBase;
32 class JsonPrefStoreLossyWriteTest;
32 class SequencedTaskRunner; 33 class SequencedTaskRunner;
33 class SequencedWorkerPool; 34 class SequencedWorkerPool;
34 class Value; 35 class Value;
35 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestBasic); 36 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestBasic);
36 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestSinglePeriod); 37 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestSinglePeriod);
37 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestMultiplePeriods); 38 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestMultiplePeriods);
38 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestPeriodWithGaps); 39 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestPeriodWithGaps);
39 } 40 }
40 41
41 // A writable PrefStore implementation that is used for user preferences. 42 // A writable PrefStore implementation that is used for user preferences.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 }; 159 };
159 160
160 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, 161 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest,
161 WriteCountHistogramTestBasic); 162 WriteCountHistogramTestBasic);
162 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, 163 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest,
163 WriteCountHistogramTestSinglePeriod); 164 WriteCountHistogramTestSinglePeriod);
164 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, 165 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest,
165 WriteCountHistogramTestMultiplePeriods); 166 WriteCountHistogramTestMultiplePeriods);
166 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, 167 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest,
167 WriteCountHistogramTestPeriodWithGaps); 168 WriteCountHistogramTestPeriodWithGaps);
169 friend class base::JsonPrefStoreLossyWriteTest;
168 170
169 ~JsonPrefStore() override; 171 ~JsonPrefStore() override;
170 172
171 // This method is called after the JSON file has been read. It then hands 173 // This method is called after the JSON file has been read. It then hands
172 // |value| (or an empty dictionary in some read error cases) to the 174 // |value| (or an empty dictionary in some read error cases) to the
173 // |pref_filter| if one is set. It also gives a callback pointing at 175 // |pref_filter| if one is set. It also gives a callback pointing at
174 // FinalizeFileRead() to that |pref_filter_| which is then responsible for 176 // FinalizeFileRead() to that |pref_filter_| which is then responsible for
175 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead() 177 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead()
176 // is invoked directly. 178 // is invoked directly.
177 void OnFileRead(scoped_ptr<ReadResult> read_result); 179 void OnFileRead(scoped_ptr<ReadResult> read_result);
178 180
179 // ImportantFileWriter::DataSerializer overrides: 181 // ImportantFileWriter::DataSerializer overrides:
180 bool SerializeData(std::string* output) override; 182 bool SerializeData(std::string* output) override;
181 183
182 // This method is called after the JSON file has been read and the result has 184 // This method is called after the JSON file has been read and the result has
183 // potentially been intercepted and modified by |pref_filter_|. 185 // potentially been intercepted and modified by |pref_filter_|.
184 // |initialization_successful| is pre-determined by OnFileRead() and should 186 // |initialization_successful| is pre-determined by OnFileRead() and should
185 // be used when reporting OnInitializationCompleted(). 187 // be used when reporting OnInitializationCompleted().
186 // |schedule_write| indicates whether a write should be immediately scheduled 188 // |schedule_write| indicates whether a write should be immediately scheduled
187 // (typically because the |pref_filter_| has already altered the |prefs|) -- 189 // (typically because the |pref_filter_| has already altered the |prefs|) --
188 // this will be ignored if this store is read-only. 190 // this will be ignored if this store is read-only.
189 void FinalizeFileRead(bool initialization_successful, 191 void FinalizeFileRead(bool initialization_successful,
190 scoped_ptr<base::DictionaryValue> prefs, 192 scoped_ptr<base::DictionaryValue> prefs,
191 bool schedule_write); 193 bool schedule_write);
192 194
195 // Schedule a write with the file writer as long as |flags| doesn't contain
196 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG.
197 void ScheduleWrite(uint32 flags);
198
193 const base::FilePath path_; 199 const base::FilePath path_;
194 const base::FilePath alternate_path_; 200 const base::FilePath alternate_path_;
195 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; 201 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_;
196 202
197 scoped_ptr<base::DictionaryValue> prefs_; 203 scoped_ptr<base::DictionaryValue> prefs_;
198 204
199 bool read_only_; 205 bool read_only_;
200 206
201 // Helper for safely writing pref data. 207 // Helper for safely writing pref data.
202 base::ImportantFileWriter writer_; 208 base::ImportantFileWriter writer_;
203 209
204 scoped_ptr<PrefFilter> pref_filter_; 210 scoped_ptr<PrefFilter> pref_filter_;
205 ObserverList<PrefStore::Observer, true> observers_; 211 ObserverList<PrefStore::Observer, true> observers_;
206 212
207 scoped_ptr<ReadErrorDelegate> error_delegate_; 213 scoped_ptr<ReadErrorDelegate> error_delegate_;
208 214
209 bool initialized_; 215 bool initialized_;
210 bool filtering_in_progress_; 216 bool filtering_in_progress_;
217 bool pending_lossy_write_;
211 PrefReadError read_error_; 218 PrefReadError read_error_;
212 219
213 std::set<std::string> keys_need_empty_value_; 220 std::set<std::string> keys_need_empty_value_;
214 221
215 WriteCountHistogram write_count_histogram_; 222 WriteCountHistogram write_count_histogram_;
216 223
217 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); 224 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore);
218 }; 225 };
219 226
220 #endif // BASE_PREFS_JSON_PREF_STORE_H_ 227 #endif // BASE_PREFS_JSON_PREF_STORE_H_
OLDNEW
« no previous file with comments | « no previous file | base/prefs/json_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698