| 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> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/files/important_file_writer.h" | 17 #include "base/files/important_file_writer.h" |
| 18 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "base/observer_list.h" | 21 #include "base/observer_list.h" |
| 22 #include "base/task_scheduler/post_task.h" |
| 22 #include "base/threading/non_thread_safe.h" | 23 #include "base/threading/non_thread_safe.h" |
| 23 #include "components/prefs/base_prefs_export.h" | 24 #include "components/prefs/base_prefs_export.h" |
| 24 #include "components/prefs/persistent_pref_store.h" | 25 #include "components/prefs/persistent_pref_store.h" |
| 26 #include "components/prefs/pref_filter.h" |
| 25 | 27 |
| 26 class PrefFilter; | 28 class PrefFilter; |
| 27 | 29 |
| 28 namespace base { | 30 namespace base { |
| 29 class Clock; | 31 class Clock; |
| 30 class DictionaryValue; | 32 class DictionaryValue; |
| 31 class FilePath; | 33 class FilePath; |
| 32 class HistogramBase; | 34 class HistogramBase; |
| 33 class JsonPrefStoreCallbackTest; | 35 class JsonPrefStoreCallbackTest; |
| 34 class JsonPrefStoreLossyWriteTest; | 36 class JsonPrefStoreLossyWriteTest; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 55 // to disk. | 57 // to disk. |
| 56 using OnWriteCallbackPair = | 58 using OnWriteCallbackPair = |
| 57 std::pair<base::Closure, base::Callback<void(bool success)>>; | 59 std::pair<base::Closure, base::Callback<void(bool success)>>; |
| 58 | 60 |
| 59 // Returns instance of SequencedTaskRunner which guarantees that file | 61 // Returns instance of SequencedTaskRunner which guarantees that file |
| 60 // operations on the same file will be executed in sequenced order. | 62 // operations on the same file will be executed in sequenced order. |
| 61 static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile( | 63 static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile( |
| 62 const base::FilePath& pref_filename, | 64 const base::FilePath& pref_filename, |
| 63 base::SequencedWorkerPool* worker_pool); | 65 base::SequencedWorkerPool* worker_pool); |
| 64 | 66 |
| 65 // |sequenced_task_runner| must be a shutdown-blocking task runner, ideally | 67 // |pref_filename| is the path to the file to read prefs from. It is incorrect |
| 66 // created by the GetTaskRunnerForFile() method above. | 68 // to create multiple JsonPrefStore with the same |pref_filename|. |
| 67 // |pref_filename| is the path to the file to read prefs from. | 69 // |sequenced_task_runner| is used for asynchronous reads and writes. It must |
| 68 JsonPrefStore( | 70 // have the base::TaskShutdownBehavior::BLOCK_SHUTDOWN and base::MayBlock() |
| 69 const base::FilePath& pref_filename, | 71 // traits. Unless external tasks need to run on the same sequence as |
| 70 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner, | 72 // JsonPrefStore tasks, keep the default value. |
| 71 std::unique_ptr<PrefFilter> pref_filter); | 73 JsonPrefStore(const base::FilePath& pref_filename, |
| 74 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = |
| 75 base::CreateSequencedTaskRunnerWithTraits( |
| 76 {base::MayBlock(), |
| 77 base::TaskShutdownBehavior::BLOCK_SHUTDOWN}), |
| 78 std::unique_ptr<PrefFilter> pref_filter = nullptr); |
| 72 | 79 |
| 73 // PrefStore overrides: | 80 // PrefStore overrides: |
| 74 bool GetValue(const std::string& key, | 81 bool GetValue(const std::string& key, |
| 75 const base::Value** result) const override; | 82 const base::Value** result) const override; |
| 76 std::unique_ptr<base::DictionaryValue> GetValues() const override; | 83 std::unique_ptr<base::DictionaryValue> GetValues() const override; |
| 77 void AddObserver(PrefStore::Observer* observer) override; | 84 void AddObserver(PrefStore::Observer* observer) override; |
| 78 void RemoveObserver(PrefStore::Observer* observer) override; | 85 void RemoveObserver(PrefStore::Observer* observer) override; |
| 79 bool HasObservers() const override; | 86 bool HasObservers() const override; |
| 80 bool IsInitializationComplete() const override; | 87 bool IsInitializationComplete() const override; |
| 81 | 88 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 250 |
| 244 bool has_pending_write_reply_ = true; | 251 bool has_pending_write_reply_ = true; |
| 245 base::Closure on_next_successful_write_reply_; | 252 base::Closure on_next_successful_write_reply_; |
| 246 | 253 |
| 247 WriteCountHistogram write_count_histogram_; | 254 WriteCountHistogram write_count_histogram_; |
| 248 | 255 |
| 249 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); | 256 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
| 250 }; | 257 }; |
| 251 | 258 |
| 252 #endif // COMPONENTS_PREFS_JSON_PREF_STORE_H_ | 259 #endif // COMPONENTS_PREFS_JSON_PREF_STORE_H_ |
| OLD | NEW |