OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_BUILDER_H_ | |
6 #define CHROME_BROWSER_PREFS_PREF_SERVICE_BUILDER_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/callback.h" | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/prefs/persistent_pref_store.h" | |
12 #include "base/prefs/pref_store.h" | |
13 #include "chrome/browser/prefs/pref_registry.h" | |
14 | |
15 class PrefService; | |
16 | |
17 namespace base { | |
18 class FilePath; | |
19 class SequencedTaskRunner; | |
20 } | |
21 | |
22 // A class that allows convenient building of PrefService. | |
23 class PrefServiceBuilder { | |
24 public: | |
25 PrefServiceBuilder(); | |
26 virtual ~PrefServiceBuilder(); | |
27 | |
28 // Functions for setting the various parameters of the PrefService to build. | |
29 // These take ownership of the |store| parameter. | |
30 PrefServiceBuilder& WithManagedPrefs(PrefStore* store); | |
31 PrefServiceBuilder& WithExtensionPrefs(PrefStore* store); | |
32 PrefServiceBuilder& WithCommandLinePrefs(PrefStore* store); | |
33 PrefServiceBuilder& WithUserPrefs(PersistentPrefStore* store); | |
34 PrefServiceBuilder& WithRecommendedPrefs(PrefStore* store); | |
35 | |
36 // Sets up error callback for the PrefService. A do-nothing default | |
37 // is provided if this is not called. | |
38 PrefServiceBuilder& WithReadErrorCallback( | |
39 const base::Callback<void(PersistentPrefStore::PrefReadError)>& | |
40 read_error_callback); | |
41 | |
42 // Specifies to use an actual file-backed user pref store. | |
43 PrefServiceBuilder& WithUserFilePrefs( | |
44 const base::FilePath& prefs_file, | |
45 base::SequencedTaskRunner* task_runner); | |
46 | |
47 PrefServiceBuilder& WithAsync(bool async); | |
48 | |
49 // Creates a PrefService object initialized with the parameters from | |
50 // this builder. | |
51 virtual PrefService* Create(PrefRegistry* registry); | |
52 | |
53 protected: | |
54 virtual void ResetDefaultState(); | |
55 | |
56 scoped_refptr<PrefStore> managed_prefs_; | |
57 scoped_refptr<PrefStore> extension_prefs_; | |
58 scoped_refptr<PrefStore> command_line_prefs_; | |
59 scoped_refptr<PersistentPrefStore> user_prefs_; | |
60 scoped_refptr<PrefStore> recommended_prefs_; | |
61 | |
62 base::Callback<void(PersistentPrefStore::PrefReadError)> read_error_callback_; | |
63 | |
64 // Defaults to false. | |
65 bool async_; | |
66 | |
67 private: | |
68 DISALLOW_COPY_AND_ASSIGN(PrefServiceBuilder); | |
69 }; | |
70 | |
71 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_BUILDER_H_ | |
OLD | NEW |