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