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 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 25 matching lines...) Expand all Loading... |
36 : public PersistentPrefStore, | 36 : public PersistentPrefStore, |
37 public base::ImportantFileWriter::DataSerializer, | 37 public base::ImportantFileWriter::DataSerializer, |
38 public base::SupportsWeakPtr<JsonPrefStore> { | 38 public base::SupportsWeakPtr<JsonPrefStore> { |
39 public: | 39 public: |
40 // Returns instance of SequencedTaskRunner which guarantees that file | 40 // Returns instance of SequencedTaskRunner which guarantees that file |
41 // operations on the same file will be executed in sequenced order. | 41 // operations on the same file will be executed in sequenced order. |
42 static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile( | 42 static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile( |
43 const base::FilePath& pref_filename, | 43 const base::FilePath& pref_filename, |
44 base::SequencedWorkerPool* worker_pool); | 44 base::SequencedWorkerPool* worker_pool); |
45 | 45 |
46 // |sequenced_task_runner| is must be a shutdown-blocking task runner, ideally | 46 // Same as the constructor below with no alternate filename. |
47 // created by GetTaskRunnerForFile() method above. | |
48 JsonPrefStore(const base::FilePath& pref_filename, | 47 JsonPrefStore(const base::FilePath& pref_filename, |
49 base::SequencedTaskRunner* sequenced_task_runner, | 48 base::SequencedTaskRunner* sequenced_task_runner, |
50 scoped_ptr<PrefFilter> pref_filter); | 49 scoped_ptr<PrefFilter> pref_filter); |
51 | 50 |
| 51 // |sequenced_task_runner| must be a shutdown-blocking task runner, ideally |
| 52 // created by the GetTaskRunnerForFile() method above. |
| 53 // |pref_filename| is the path to the file to read prefs from. |
| 54 // |pref_alternate_filename| is the path to an alternate file which the |
| 55 // desired prefs may have previously been written to. If |pref_filename| |
| 56 // doesn't exist and |pref_alternate_filename| does, |pref_alternate_filename| |
| 57 // will be moved to |pref_filename| before the read occurs. |
| 58 JsonPrefStore(const base::FilePath& pref_filename, |
| 59 const base::FilePath& pref_alternate_filename, |
| 60 base::SequencedTaskRunner* sequenced_task_runner, |
| 61 scoped_ptr<PrefFilter> pref_filter); |
| 62 |
52 // PrefStore overrides: | 63 // PrefStore overrides: |
53 virtual bool GetValue(const std::string& key, | 64 virtual bool GetValue(const std::string& key, |
54 const base::Value** result) const OVERRIDE; | 65 const base::Value** result) const OVERRIDE; |
55 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; | 66 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; |
56 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; | 67 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; |
57 virtual bool HasObservers() const OVERRIDE; | 68 virtual bool HasObservers() const OVERRIDE; |
58 virtual bool IsInitializationComplete() const OVERRIDE; | 69 virtual bool IsInitializationComplete() const OVERRIDE; |
59 | 70 |
60 // PersistentPrefStore overrides: | 71 // PersistentPrefStore overrides: |
61 virtual bool GetMutableValue(const std::string& key, | 72 virtual bool GetMutableValue(const std::string& key, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // potentially been intercepted and modified by |pref_filter_|. | 119 // potentially been intercepted and modified by |pref_filter_|. |
109 // |initialization_successful| is pre-determined by OnFileRead() and should | 120 // |initialization_successful| is pre-determined by OnFileRead() and should |
110 // be used when reporting OnInitializationCompleted(). | 121 // be used when reporting OnInitializationCompleted(). |
111 // |schedule_write| indicates whether a write should be immediately scheduled | 122 // |schedule_write| indicates whether a write should be immediately scheduled |
112 // (typically because the |pref_filter_| has already altered the |prefs|) -- | 123 // (typically because the |pref_filter_| has already altered the |prefs|) -- |
113 // this will be ignored if this store is read-only. | 124 // this will be ignored if this store is read-only. |
114 void FinalizeFileRead(bool initialization_successful, | 125 void FinalizeFileRead(bool initialization_successful, |
115 scoped_ptr<base::DictionaryValue> prefs, | 126 scoped_ptr<base::DictionaryValue> prefs, |
116 bool schedule_write); | 127 bool schedule_write); |
117 | 128 |
118 base::FilePath path_; | 129 const base::FilePath path_; |
| 130 const base::FilePath alternate_path_; |
119 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 131 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
120 | 132 |
121 scoped_ptr<base::DictionaryValue> prefs_; | 133 scoped_ptr<base::DictionaryValue> prefs_; |
122 | 134 |
123 bool read_only_; | 135 bool read_only_; |
124 | 136 |
125 // Helper for safely writing pref data. | 137 // Helper for safely writing pref data. |
126 base::ImportantFileWriter writer_; | 138 base::ImportantFileWriter writer_; |
127 | 139 |
128 scoped_ptr<PrefFilter> pref_filter_; | 140 scoped_ptr<PrefFilter> pref_filter_; |
129 ObserverList<PrefStore::Observer, true> observers_; | 141 ObserverList<PrefStore::Observer, true> observers_; |
130 | 142 |
131 scoped_ptr<ReadErrorDelegate> error_delegate_; | 143 scoped_ptr<ReadErrorDelegate> error_delegate_; |
132 | 144 |
133 bool initialized_; | 145 bool initialized_; |
134 bool filtering_in_progress_; | 146 bool filtering_in_progress_; |
135 PrefReadError read_error_; | 147 PrefReadError read_error_; |
136 | 148 |
137 std::set<std::string> keys_need_empty_value_; | 149 std::set<std::string> keys_need_empty_value_; |
138 | 150 |
139 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); | 151 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
140 }; | 152 }; |
141 | 153 |
142 #endif // BASE_PREFS_JSON_PREF_STORE_H_ | 154 #endif // BASE_PREFS_JSON_PREF_STORE_H_ |
OLD | NEW |