| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // to disk. | 55 // to disk. |
| 56 using OnWriteCallbackPair = | 56 using OnWriteCallbackPair = |
| 57 std::pair<base::Closure, base::Callback<void(bool success)>>; | 57 std::pair<base::Closure, base::Callback<void(bool success)>>; |
| 58 | 58 |
| 59 // Returns instance of SequencedTaskRunner which guarantees that file | 59 // Returns instance of SequencedTaskRunner which guarantees that file |
| 60 // operations on the same file will be executed in sequenced order. | 60 // operations on the same file will be executed in sequenced order. |
| 61 static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile( | 61 static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile( |
| 62 const base::FilePath& pref_filename, | 62 const base::FilePath& pref_filename, |
| 63 base::SequencedWorkerPool* worker_pool); | 63 base::SequencedWorkerPool* worker_pool); |
| 64 | 64 |
| 65 // Same as the constructor below with no alternate filename. | 65 // |sequenced_task_runner| must be a shutdown-blocking task runner, ideally |
| 66 // created by the GetTaskRunnerForFile() method above. |
| 67 // |pref_filename| is the path to the file to read prefs from. |
| 66 JsonPrefStore( | 68 JsonPrefStore( |
| 67 const base::FilePath& pref_filename, | 69 const base::FilePath& pref_filename, |
| 68 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner, | 70 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner, |
| 69 std::unique_ptr<PrefFilter> pref_filter); | 71 std::unique_ptr<PrefFilter> pref_filter); |
| 70 | 72 |
| 71 // |sequenced_task_runner| must be a shutdown-blocking task runner, ideally | |
| 72 // created by the GetTaskRunnerForFile() method above. | |
| 73 // |pref_filename| is the path to the file to read prefs from. | |
| 74 // |pref_alternate_filename| is the path to an alternate file which the | |
| 75 // desired prefs may have previously been written to. If |pref_filename| | |
| 76 // doesn't exist and |pref_alternate_filename| does, |pref_alternate_filename| | |
| 77 // will be moved to |pref_filename| before the read occurs. | |
| 78 JsonPrefStore( | |
| 79 const base::FilePath& pref_filename, | |
| 80 const base::FilePath& pref_alternate_filename, | |
| 81 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner, | |
| 82 std::unique_ptr<PrefFilter> pref_filter); | |
| 83 | |
| 84 // PrefStore overrides: | 73 // PrefStore overrides: |
| 85 bool GetValue(const std::string& key, | 74 bool GetValue(const std::string& key, |
| 86 const base::Value** result) const override; | 75 const base::Value** result) const override; |
| 87 std::unique_ptr<base::DictionaryValue> GetValues() const override; | 76 std::unique_ptr<base::DictionaryValue> GetValues() const override; |
| 88 void AddObserver(PrefStore::Observer* observer) override; | 77 void AddObserver(PrefStore::Observer* observer) override; |
| 89 void RemoveObserver(PrefStore::Observer* observer) override; | 78 void RemoveObserver(PrefStore::Observer* observer) override; |
| 90 bool HasObservers() const override; | 79 bool HasObservers() const override; |
| 91 bool IsInitializationComplete() const override; | 80 bool IsInitializationComplete() const override; |
| 92 | 81 |
| 93 // PersistentPrefStore overrides: | 82 // PersistentPrefStore overrides: |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 // this will be ignored if this store is read-only. | 213 // this will be ignored if this store is read-only. |
| 225 void FinalizeFileRead(bool initialization_successful, | 214 void FinalizeFileRead(bool initialization_successful, |
| 226 std::unique_ptr<base::DictionaryValue> prefs, | 215 std::unique_ptr<base::DictionaryValue> prefs, |
| 227 bool schedule_write); | 216 bool schedule_write); |
| 228 | 217 |
| 229 // 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 |
| 230 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG. | 219 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG. |
| 231 void ScheduleWrite(uint32_t flags); | 220 void ScheduleWrite(uint32_t flags); |
| 232 | 221 |
| 233 const base::FilePath path_; | 222 const base::FilePath path_; |
| 234 const base::FilePath alternate_path_; | |
| 235 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 223 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
| 236 | 224 |
| 237 std::unique_ptr<base::DictionaryValue> prefs_; | 225 std::unique_ptr<base::DictionaryValue> prefs_; |
| 238 | 226 |
| 239 bool read_only_; | 227 bool read_only_; |
| 240 | 228 |
| 241 // Helper for safely writing pref data. | 229 // Helper for safely writing pref data. |
| 242 base::ImportantFileWriter writer_; | 230 base::ImportantFileWriter writer_; |
| 243 | 231 |
| 244 std::unique_ptr<PrefFilter> pref_filter_; | 232 std::unique_ptr<PrefFilter> pref_filter_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 255 | 243 |
| 256 bool has_pending_write_reply_ = true; | 244 bool has_pending_write_reply_ = true; |
| 257 base::Closure on_next_successful_write_reply_; | 245 base::Closure on_next_successful_write_reply_; |
| 258 | 246 |
| 259 WriteCountHistogram write_count_histogram_; | 247 WriteCountHistogram write_count_histogram_; |
| 260 | 248 |
| 261 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); | 249 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
| 262 }; | 250 }; |
| 263 | 251 |
| 264 #endif // COMPONENTS_PREFS_JSON_PREF_STORE_H_ | 252 #endif // COMPONENTS_PREFS_JSON_PREF_STORE_H_ |
| OLD | NEW |