1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_PREFS_PREF_SERVICE_FACTORY_H_
6 #define COMPONENTS_PREFS_PREF_SERVICE_FACTORY_H_
8 #include "base/functional/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "components/prefs/persistent_pref_store.h"
11 #include "components/prefs/pref_registry.h"
12 #include "components/prefs/pref_store.h"
13 #include "components/prefs/pref_value_store.h"
14 #include "components/prefs/prefs_export.h"
20 class SequencedTaskRunner;
23 // A class that allows convenient building of PrefService.
24 class COMPONENTS_PREFS_EXPORT PrefServiceFactory {
28 PrefServiceFactory(const PrefServiceFactory&) = delete;
29 PrefServiceFactory& operator=(const PrefServiceFactory&) = delete;
31 virtual ~PrefServiceFactory();
33 // Functions for setting the various parameters of the PrefService to build.
34 void set_managed_prefs(scoped_refptr<PrefStore> prefs) {
35 managed_prefs_.swap(prefs);
38 void set_supervised_user_prefs(scoped_refptr<PrefStore> prefs) {
39 supervised_user_prefs_.swap(prefs);
42 void set_extension_prefs(scoped_refptr<PrefStore> prefs) {
43 extension_prefs_.swap(prefs);
46 void set_standalone_browser_prefs(scoped_refptr<PersistentPrefStore> prefs) {
47 standalone_browser_prefs_.swap(prefs);
50 void set_command_line_prefs(scoped_refptr<PrefStore> prefs) {
51 command_line_prefs_.swap(prefs);
54 void set_user_prefs(scoped_refptr<PersistentPrefStore> prefs) {
55 user_prefs_.swap(prefs);
58 void set_recommended_prefs(scoped_refptr<PrefStore> prefs) {
59 recommended_prefs_.swap(prefs);
62 // Sets up error callback for the PrefService. A do-nothing default is
63 // provided if this is not called. This callback is always invoked (async or
64 // not) on the sequence on which Create is invoked.
65 void set_read_error_callback(
66 base::RepeatingCallback<void(PersistentPrefStore::PrefReadError)>
67 read_error_callback) {
68 read_error_callback_ = std::move(read_error_callback);
71 // Specifies to use an actual file-backed user pref store.
72 void SetUserPrefsFile(const base::FilePath& prefs_file,
73 base::SequencedTaskRunner* task_runner);
75 void set_async(bool async) {
79 // Creates a PrefService object initialized with the parameters from
81 std::unique_ptr<PrefService> Create(
82 scoped_refptr<PrefRegistry> pref_registry);
85 scoped_refptr<PrefStore> managed_prefs_;
86 scoped_refptr<PrefStore> supervised_user_prefs_;
87 scoped_refptr<PrefStore> extension_prefs_;
88 scoped_refptr<PersistentPrefStore> standalone_browser_prefs_;
89 scoped_refptr<PrefStore> command_line_prefs_;
90 scoped_refptr<PersistentPrefStore> user_prefs_;
91 scoped_refptr<PrefStore> recommended_prefs_;
93 base::RepeatingCallback<void(PersistentPrefStore::PrefReadError)>
100 #endif // COMPONENTS_PREFS_PREF_SERVICE_FACTORY_H_