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 <stdint.h> |
| 9 |
8 #include <set> | 10 #include <set> |
9 #include <string> | 11 #include <string> |
10 | 12 |
11 #include "base/basictypes.h" | |
12 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
15 #include "base/files/important_file_writer.h" | 16 #include "base/files/important_file_writer.h" |
16 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
19 #include "base/observer_list.h" | 21 #include "base/observer_list.h" |
20 #include "base/prefs/base_prefs_export.h" | 22 #include "base/prefs/base_prefs_export.h" |
21 #include "base/prefs/persistent_pref_store.h" | 23 #include "base/prefs/persistent_pref_store.h" |
22 #include "base/threading/non_thread_safe.h" | 24 #include "base/threading/non_thread_safe.h" |
23 | 25 |
24 class PrefFilter; | 26 class PrefFilter; |
25 | 27 |
26 namespace base { | 28 namespace base { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 const base::Value** result) const override; | 79 const base::Value** result) const override; |
78 void AddObserver(PrefStore::Observer* observer) override; | 80 void AddObserver(PrefStore::Observer* observer) override; |
79 void RemoveObserver(PrefStore::Observer* observer) override; | 81 void RemoveObserver(PrefStore::Observer* observer) override; |
80 bool HasObservers() const override; | 82 bool HasObservers() const override; |
81 bool IsInitializationComplete() const override; | 83 bool IsInitializationComplete() const override; |
82 | 84 |
83 // PersistentPrefStore overrides: | 85 // PersistentPrefStore overrides: |
84 bool GetMutableValue(const std::string& key, base::Value** result) override; | 86 bool GetMutableValue(const std::string& key, base::Value** result) override; |
85 void SetValue(const std::string& key, | 87 void SetValue(const std::string& key, |
86 scoped_ptr<base::Value> value, | 88 scoped_ptr<base::Value> value, |
87 uint32 flags) override; | 89 uint32_t flags) override; |
88 void SetValueSilently(const std::string& key, | 90 void SetValueSilently(const std::string& key, |
89 scoped_ptr<base::Value> value, | 91 scoped_ptr<base::Value> value, |
90 uint32 flags) override; | 92 uint32_t flags) override; |
91 void RemoveValue(const std::string& key, uint32 flags) override; | 93 void RemoveValue(const std::string& key, uint32_t flags) override; |
92 bool ReadOnly() const override; | 94 bool ReadOnly() const override; |
93 PrefReadError GetReadError() const override; | 95 PrefReadError GetReadError() const override; |
94 // Note this method may be asynchronous if this instance has a |pref_filter_| | 96 // Note this method may be asynchronous if this instance has a |pref_filter_| |
95 // in which case it will return PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE. | 97 // in which case it will return PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE. |
96 // See details in pref_filter.h. | 98 // See details in pref_filter.h. |
97 PrefReadError ReadPrefs() override; | 99 PrefReadError ReadPrefs() override; |
98 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; | 100 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; |
99 void CommitPendingWrite() override; | 101 void CommitPendingWrite() override; |
100 void SchedulePendingLossyWrites() override; | 102 void SchedulePendingLossyWrites() override; |
101 void ReportValueChanged(const std::string& key, uint32 flags) override; | 103 void ReportValueChanged(const std::string& key, uint32_t flags) override; |
102 | 104 |
103 // Just like RemoveValue(), but doesn't notify observers. Used when doing some | 105 // Just like RemoveValue(), but doesn't notify observers. Used when doing some |
104 // cleanup that shouldn't otherwise alert observers. | 106 // cleanup that shouldn't otherwise alert observers. |
105 void RemoveValueSilently(const std::string& key, uint32 flags); | 107 void RemoveValueSilently(const std::string& key, uint32_t flags); |
106 | 108 |
107 // Registers |on_next_successful_write| to be called once, on the next | 109 // Registers |on_next_successful_write| to be called once, on the next |
108 // successful write event of |writer_|. | 110 // successful write event of |writer_|. |
109 void RegisterOnNextSuccessfulWriteCallback( | 111 void RegisterOnNextSuccessfulWriteCallback( |
110 const base::Closure& on_next_successful_write); | 112 const base::Closure& on_next_successful_write); |
111 | 113 |
112 private: | 114 private: |
113 // Represents a histogram for recording the number of writes to the pref file | 115 // Represents a histogram for recording the number of writes to the pref file |
114 // that occur every kHistogramWriteReportIntervalInMins minutes. | 116 // that occur every kHistogramWriteReportIntervalInMins minutes. |
115 class BASE_PREFS_EXPORT WriteCountHistogram { | 117 class BASE_PREFS_EXPORT WriteCountHistogram { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 // be used when reporting OnInitializationCompleted(). | 189 // be used when reporting OnInitializationCompleted(). |
188 // |schedule_write| indicates whether a write should be immediately scheduled | 190 // |schedule_write| indicates whether a write should be immediately scheduled |
189 // (typically because the |pref_filter_| has already altered the |prefs|) -- | 191 // (typically because the |pref_filter_| has already altered the |prefs|) -- |
190 // this will be ignored if this store is read-only. | 192 // this will be ignored if this store is read-only. |
191 void FinalizeFileRead(bool initialization_successful, | 193 void FinalizeFileRead(bool initialization_successful, |
192 scoped_ptr<base::DictionaryValue> prefs, | 194 scoped_ptr<base::DictionaryValue> prefs, |
193 bool schedule_write); | 195 bool schedule_write); |
194 | 196 |
195 // Schedule a write with the file writer as long as |flags| doesn't contain | 197 // Schedule a write with the file writer as long as |flags| doesn't contain |
196 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG. | 198 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG. |
197 void ScheduleWrite(uint32 flags); | 199 void ScheduleWrite(uint32_t flags); |
198 | 200 |
199 const base::FilePath path_; | 201 const base::FilePath path_; |
200 const base::FilePath alternate_path_; | 202 const base::FilePath alternate_path_; |
201 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 203 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
202 | 204 |
203 scoped_ptr<base::DictionaryValue> prefs_; | 205 scoped_ptr<base::DictionaryValue> prefs_; |
204 | 206 |
205 bool read_only_; | 207 bool read_only_; |
206 | 208 |
207 // Helper for safely writing pref data. | 209 // Helper for safely writing pref data. |
(...skipping 10 matching lines...) Expand all Loading... |
218 PrefReadError read_error_; | 220 PrefReadError read_error_; |
219 | 221 |
220 std::set<std::string> keys_need_empty_value_; | 222 std::set<std::string> keys_need_empty_value_; |
221 | 223 |
222 WriteCountHistogram write_count_histogram_; | 224 WriteCountHistogram write_count_histogram_; |
223 | 225 |
224 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); | 226 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
225 }; | 227 }; |
226 | 228 |
227 #endif // BASE_PREFS_JSON_PREF_STORE_H_ | 229 #endif // BASE_PREFS_JSON_PREF_STORE_H_ |
OLD | NEW |