Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 #include "components/prefs/base_prefs_export.h" | 23 #include "components/prefs/base_prefs_export.h" |
| 24 #include "components/prefs/persistent_pref_store.h" | 24 #include "components/prefs/persistent_pref_store.h" |
| 25 | 25 |
| 26 class PrefFilter; | 26 class PrefFilter; |
| 27 | 27 |
| 28 namespace base { | 28 namespace base { |
| 29 class Clock; | 29 class Clock; |
| 30 class DictionaryValue; | 30 class DictionaryValue; |
| 31 class FilePath; | 31 class FilePath; |
| 32 class HistogramBase; | 32 class HistogramBase; |
| 33 class JsonPrefStoreCallbackTest; | |
| 33 class JsonPrefStoreLossyWriteTest; | 34 class JsonPrefStoreLossyWriteTest; |
| 34 class SequencedTaskRunner; | 35 class SequencedTaskRunner; |
| 35 class SequencedWorkerPool; | 36 class SequencedWorkerPool; |
| 36 class Value; | 37 class Value; |
| 37 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestBasic); | 38 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestBasic); |
| 38 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestSinglePeriod); | 39 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestSinglePeriod); |
| 39 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestMultiplePeriods); | 40 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestMultiplePeriods); |
| 40 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestPeriodWithGaps); | 41 FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestPeriodWithGaps); |
| 41 } | 42 } |
| 42 | 43 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 PrefReadError ReadPrefs() override; | 100 PrefReadError ReadPrefs() override; |
| 100 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; | 101 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; |
| 101 void CommitPendingWrite() override; | 102 void CommitPendingWrite() override; |
| 102 void SchedulePendingLossyWrites() override; | 103 void SchedulePendingLossyWrites() override; |
| 103 void ReportValueChanged(const std::string& key, uint32_t flags) override; | 104 void ReportValueChanged(const std::string& key, uint32_t flags) override; |
| 104 | 105 |
| 105 // Just like RemoveValue(), but doesn't notify observers. Used when doing some | 106 // Just like RemoveValue(), but doesn't notify observers. Used when doing some |
| 106 // cleanup that shouldn't otherwise alert observers. | 107 // cleanup that shouldn't otherwise alert observers. |
| 107 void RemoveValueSilently(const std::string& key, uint32_t flags); | 108 void RemoveValueSilently(const std::string& key, uint32_t flags); |
| 108 | 109 |
| 109 // Registers |on_next_successful_write| to be called once, on the next | 110 // Registers |on_next_successful_write_reply| to be called once, on the next |
| 110 // successful write event of |writer_|. | 111 // successful write event of |writer_|. |
| 111 void RegisterOnNextSuccessfulWriteCallback( | 112 // |on_next_successful_write_reply| will be called on the thread from which |
| 112 const base::Closure& on_next_successful_write); | 113 // this method is called and does not need to be thread safe. |
| 114 void RegisterOnNextSuccessfulWriteReply( | |
| 115 const base::Closure& on_next_successful_write_reply); | |
| 116 | |
| 117 // Registers |on_next_write_callback| to be called once, on the | |
| 118 // next write event of |writer_|. | |
| 119 // |on_next_write_callback| must be thread-safe. | |
| 120 void RegisterOnNextWriteCallback( | |
| 121 const base::Callback<void(bool success)>& on_next_write_callback); | |
| 113 | 122 |
| 114 void ClearMutableValues() override; | 123 void ClearMutableValues() override; |
| 115 | 124 |
| 116 private: | 125 private: |
| 117 // Represents a histogram for recording the number of writes to the pref file | 126 // Represents a histogram for recording the number of writes to the pref file |
| 118 // that occur every kHistogramWriteReportIntervalInMins minutes. | 127 // that occur every kHistogramWriteReportIntervalInMins minutes. |
| 119 class COMPONENTS_PREFS_EXPORT WriteCountHistogram { | 128 class COMPONENTS_PREFS_EXPORT WriteCountHistogram { |
| 120 public: | 129 public: |
| 121 static const int32_t kHistogramWriteReportIntervalMins; | 130 static const int32_t kHistogramWriteReportIntervalMins; |
| 122 | 131 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 }; | 172 }; |
| 164 | 173 |
| 165 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, | 174 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, |
| 166 WriteCountHistogramTestBasic); | 175 WriteCountHistogramTestBasic); |
| 167 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, | 176 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, |
| 168 WriteCountHistogramTestSinglePeriod); | 177 WriteCountHistogramTestSinglePeriod); |
| 169 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, | 178 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, |
| 170 WriteCountHistogramTestMultiplePeriods); | 179 WriteCountHistogramTestMultiplePeriods); |
| 171 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, | 180 FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest, |
| 172 WriteCountHistogramTestPeriodWithGaps); | 181 WriteCountHistogramTestPeriodWithGaps); |
| 182 friend class base::JsonPrefStoreCallbackTest; | |
| 173 friend class base::JsonPrefStoreLossyWriteTest; | 183 friend class base::JsonPrefStoreLossyWriteTest; |
| 174 | 184 |
| 175 ~JsonPrefStore() override; | 185 ~JsonPrefStore() override; |
| 176 | 186 |
| 187 // If |write_success| is true, runs |on_next_successful_write_| on the thread | |
|
gab
2016/09/20 01:27:42
s/thread/sequence/
proberge
2016/09/20 15:15:53
Done.
| |
| 188 // owning |calling_store|. Otherwise, re-registers |on_next_successful_write| | |
| 189 // on |calling_store|. | |
| 190 static void RunOrScheduleNextSuccessfulWriteCallback( | |
| 191 base::WeakPtr<JsonPrefStore> calling_store, | |
|
gab
2016/09/20 01:27:42
Make this a member method, essentially what you ar
proberge
2016/09/20 15:15:53
Done.
| |
| 192 bool write_success); | |
| 193 | |
| 194 // Handles the result of a write with result |write_success|. Runs the | |
| 195 // |on_next_write| callback on the current thread and calls |PostWriteReply| | |
|
gab
2016/09/20 01:27:42
s/calls/posts/
Also, what's |PostWriteReply|?
proberge
2016/09/20 15:15:53
My bad, had renamed PostWriteReply -> RunOrSchedul
| |
| 196 // on |reply_task_runner|. | |
| 197 static void PostWriteCallback( | |
| 198 base::WeakPtr<JsonPrefStore> calling_store, | |
| 199 const base::Callback<void(bool success)>& on_next_write, | |
| 200 scoped_refptr<base::SequencedTaskRunner> reply_task_runner, | |
| 201 bool write_success); | |
| 202 | |
| 177 // This method is called after the JSON file has been read. It then hands | 203 // This method is called after the JSON file has been read. It then hands |
| 178 // |value| (or an empty dictionary in some read error cases) to the | 204 // |value| (or an empty dictionary in some read error cases) to the |
| 179 // |pref_filter| if one is set. It also gives a callback pointing at | 205 // |pref_filter| if one is set. It also gives a callback pointing at |
| 180 // FinalizeFileRead() to that |pref_filter_| which is then responsible for | 206 // FinalizeFileRead() to that |pref_filter_| which is then responsible for |
| 181 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead() | 207 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead() |
| 182 // is invoked directly. | 208 // is invoked directly. |
| 183 void OnFileRead(std::unique_ptr<ReadResult> read_result); | 209 void OnFileRead(std::unique_ptr<ReadResult> read_result); |
| 184 | 210 |
| 185 // ImportantFileWriter::DataSerializer overrides: | 211 // ImportantFileWriter::DataSerializer overrides: |
| 186 bool SerializeData(std::string* output) override; | 212 bool SerializeData(std::string* output) override; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 199 // Schedule a write with the file writer as long as |flags| doesn't contain | 225 // Schedule a write with the file writer as long as |flags| doesn't contain |
| 200 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG. | 226 // WriteablePrefStore::LOSSY_PREF_WRITE_FLAG. |
| 201 void ScheduleWrite(uint32_t flags); | 227 void ScheduleWrite(uint32_t flags); |
| 202 | 228 |
| 203 const base::FilePath path_; | 229 const base::FilePath path_; |
| 204 const base::FilePath alternate_path_; | 230 const base::FilePath alternate_path_; |
| 205 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 231 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
| 206 | 232 |
| 207 std::unique_ptr<base::DictionaryValue> prefs_; | 233 std::unique_ptr<base::DictionaryValue> prefs_; |
| 208 | 234 |
| 235 bool has_pending_successful_write_reply_; | |
| 236 bool has_pending_write_callback_; | |
| 237 base::Closure on_next_successful_write_reply_; | |
| 238 | |
| 209 bool read_only_; | 239 bool read_only_; |
| 210 | 240 |
| 211 // Helper for safely writing pref data. | 241 // Helper for safely writing pref data. |
| 212 base::ImportantFileWriter writer_; | 242 base::ImportantFileWriter writer_; |
| 213 | 243 |
| 214 std::unique_ptr<PrefFilter> pref_filter_; | 244 std::unique_ptr<PrefFilter> pref_filter_; |
| 215 base::ObserverList<PrefStore::Observer, true> observers_; | 245 base::ObserverList<PrefStore::Observer, true> observers_; |
| 216 | 246 |
| 217 std::unique_ptr<ReadErrorDelegate> error_delegate_; | 247 std::unique_ptr<ReadErrorDelegate> error_delegate_; |
| 218 | 248 |
| 219 bool initialized_; | 249 bool initialized_; |
| 220 bool filtering_in_progress_; | 250 bool filtering_in_progress_; |
| 221 bool pending_lossy_write_; | 251 bool pending_lossy_write_; |
| 222 PrefReadError read_error_; | 252 PrefReadError read_error_; |
| 223 | 253 |
| 224 std::set<std::string> keys_need_empty_value_; | 254 std::set<std::string> keys_need_empty_value_; |
| 225 | 255 |
| 226 WriteCountHistogram write_count_histogram_; | 256 WriteCountHistogram write_count_histogram_; |
| 227 | 257 |
| 228 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); | 258 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
| 229 }; | 259 }; |
| 230 | 260 |
| 231 #endif // COMPONENTS_PREFS_JSON_PREF_STORE_H_ | 261 #endif // COMPONENTS_PREFS_JSON_PREF_STORE_H_ |
| OLD | NEW |