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

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
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // |pref_alternate_filename| is the path to an alternate file which the 65 // |pref_alternate_filename| is the path to an alternate file which the
66 // desired prefs may have previously been written to. If |pref_filename| 66 // desired prefs may have previously been written to. If |pref_filename|
67 // doesn't exist and |pref_alternate_filename| does, |pref_alternate_filename| 67 // doesn't exist and |pref_alternate_filename| does, |pref_alternate_filename|
68 // will be moved to |pref_filename| before the read occurs. 68 // will be moved to |pref_filename| before the read occurs.
69 JsonPrefStore( 69 JsonPrefStore(
70 const base::FilePath& pref_filename, 70 const base::FilePath& pref_filename,
71 const base::FilePath& pref_alternate_filename, 71 const base::FilePath& pref_alternate_filename,
72 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner, 72 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner,
73 scoped_ptr<PrefFilter> pref_filter); 73 scoped_ptr<PrefFilter> pref_filter);
74 74
75 // Constructor for testing which allows an ImportantFileWriter to be
76 // specified.
77 JsonPrefStore(
78 const base::FilePath& pref_filename,
79 const base::FilePath& pref_alternate_filename,
80 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner,
81 scoped_ptr<base::ImportantFileWriter> file_writer,
82 scoped_ptr<PrefFilter> pref_filter);
83
75 // PrefStore overrides: 84 // PrefStore overrides:
76 bool GetValue(const std::string& key, 85 bool GetValue(const std::string& key,
77 const base::Value** result) const override; 86 const base::Value** result) const override;
78 void AddObserver(PrefStore::Observer* observer) override; 87 void AddObserver(PrefStore::Observer* observer) override;
79 void RemoveObserver(PrefStore::Observer* observer) override; 88 void RemoveObserver(PrefStore::Observer* observer) override;
80 bool HasObservers() const override; 89 bool HasObservers() const override;
81 bool IsInitializationComplete() const override; 90 bool IsInitializationComplete() const override;
82 91
83 // PersistentPrefStore overrides: 92 // PersistentPrefStore overrides:
84 bool GetMutableValue(const std::string& key, base::Value** result) override; 93 bool GetMutableValue(const std::string& key, base::Value** result) override;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // potentially been intercepted and modified by |pref_filter_|. 192 // potentially been intercepted and modified by |pref_filter_|.
184 // |initialization_successful| is pre-determined by OnFileRead() and should 193 // |initialization_successful| is pre-determined by OnFileRead() and should
185 // be used when reporting OnInitializationCompleted(). 194 // be used when reporting OnInitializationCompleted().
186 // |schedule_write| indicates whether a write should be immediately scheduled 195 // |schedule_write| indicates whether a write should be immediately scheduled
187 // (typically because the |pref_filter_| has already altered the |prefs|) -- 196 // (typically because the |pref_filter_| has already altered the |prefs|) --
188 // this will be ignored if this store is read-only. 197 // this will be ignored if this store is read-only.
189 void FinalizeFileRead(bool initialization_successful, 198 void FinalizeFileRead(bool initialization_successful,
190 scoped_ptr<base::DictionaryValue> prefs, 199 scoped_ptr<base::DictionaryValue> prefs,
191 bool schedule_write); 200 bool schedule_write);
192 201
202 // Schedule a write with the file writer as long as |flags| doesn't contain
203 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG.
204 void ScheduleWrite(uint32 flags);
205
193 const base::FilePath path_; 206 const base::FilePath path_;
194 const base::FilePath alternate_path_; 207 const base::FilePath alternate_path_;
195 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; 208 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_;
196 209
197 scoped_ptr<base::DictionaryValue> prefs_; 210 scoped_ptr<base::DictionaryValue> prefs_;
198 211
199 bool read_only_; 212 bool read_only_;
200 213
201 // Helper for safely writing pref data. 214 // Helper for safely writing pref data.
202 base::ImportantFileWriter writer_; 215 scoped_ptr<base::ImportantFileWriter> writer_;
203 216
204 scoped_ptr<PrefFilter> pref_filter_; 217 scoped_ptr<PrefFilter> pref_filter_;
205 ObserverList<PrefStore::Observer, true> observers_; 218 ObserverList<PrefStore::Observer, true> observers_;
206 219
207 scoped_ptr<ReadErrorDelegate> error_delegate_; 220 scoped_ptr<ReadErrorDelegate> error_delegate_;
208 221
209 bool initialized_; 222 bool initialized_;
210 bool filtering_in_progress_; 223 bool filtering_in_progress_;
224 bool pending_lossy_write_;
211 PrefReadError read_error_; 225 PrefReadError read_error_;
212 226
213 std::set<std::string> keys_need_empty_value_; 227 std::set<std::string> keys_need_empty_value_;
214 228
215 WriteCountHistogram write_count_histogram_; 229 WriteCountHistogram write_count_histogram_;
216 230
217 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); 231 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore);
218 }; 232 };
219 233
220 #endif // BASE_PREFS_JSON_PREF_STORE_H_ 234 #endif // BASE_PREFS_JSON_PREF_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698