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 CHROME_BROWSER_PREFS_PREF_SERVICE_BUILDER_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_BUILDER_H_ |
6 #define CHROME_BROWSER_PREFS_PREF_SERVICE_BUILDER_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_SERVICE_BUILDER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/prefs/persistent_pref_store.h" | 11 #include "base/prefs/persistent_pref_store.h" |
12 #include "base/prefs/pref_store.h" | 12 #include "base/prefs/pref_store.h" |
13 | 13 |
14 class FilePath; | 14 class FilePath; |
15 class PrefModelAssociator; | |
16 class PrefService; | 15 class PrefService; |
17 | 16 |
18 namespace base { | 17 namespace base { |
19 class SequencedTaskRunner; | 18 class SequencedTaskRunner; |
20 } | 19 } |
21 | 20 |
22 // A class that allows convenient building of custom PrefServices. | 21 // A class that allows convenient building of custom PrefServices. |
23 class PrefServiceBuilder { | 22 class PrefServiceBuilder { |
24 public: | 23 public: |
25 PrefServiceBuilder(); | 24 PrefServiceBuilder(); |
26 virtual ~PrefServiceBuilder(); | 25 virtual ~PrefServiceBuilder(); |
27 | 26 |
28 // Functions for setting the various parameters of the PrefService to build. | 27 // Functions for setting the various parameters of the PrefService to build. |
29 // These take ownership of the |store| parameter. | 28 // These take ownership of the |store| parameter. |
30 PrefServiceBuilder& WithManagedPrefs(PrefStore* store); | 29 PrefServiceBuilder& WithManagedPrefs(PrefStore* store); |
31 PrefServiceBuilder& WithExtensionPrefs(PrefStore* store); | 30 PrefServiceBuilder& WithExtensionPrefs(PrefStore* store); |
32 PrefServiceBuilder& WithCommandLinePrefs(PrefStore* store); | 31 PrefServiceBuilder& WithCommandLinePrefs(PrefStore* store); |
33 PrefServiceBuilder& WithUserPrefs(PersistentPrefStore* store); | 32 PrefServiceBuilder& WithUserPrefs(PersistentPrefStore* store); |
34 PrefServiceBuilder& WithRecommendedPrefs(PrefStore* store); | 33 PrefServiceBuilder& WithRecommendedPrefs(PrefStore* store); |
35 | 34 |
36 // Takes ownership of the associator. | |
37 PrefServiceBuilder& WithSyncAssociator(PrefModelAssociator* associator); | |
38 | |
39 // Sets up callbacks for the PrefService. Do-nothing defaults are | 35 // Sets up callbacks for the PrefService. Do-nothing defaults are |
40 // provided if these are not called. | 36 // provided if these are not called. |
41 PrefServiceBuilder& WithLocalizedStringMethod( | 37 PrefServiceBuilder& WithLocalizedStringMethod( |
42 const base::Callback<std::string(int)>& localized_string_method); | 38 const base::Callback<std::string(int)>& localized_string_method); |
43 PrefServiceBuilder& WithReadErrorCallback( | 39 PrefServiceBuilder& WithReadErrorCallback( |
44 const base::Callback<void(PersistentPrefStore::PrefReadError)>& | 40 const base::Callback<void(PersistentPrefStore::PrefReadError)>& |
45 read_error_callback); | 41 read_error_callback); |
46 | 42 |
47 // Specifies to use an actual file-backed user pref store. | 43 // Specifies to use an actual file-backed user pref store. |
48 PrefServiceBuilder& WithUserFilePrefs( | 44 PrefServiceBuilder& WithUserFilePrefs( |
49 const FilePath& prefs_file, | 45 const FilePath& prefs_file, |
50 base::SequencedTaskRunner* task_runner); | 46 base::SequencedTaskRunner* task_runner); |
51 | 47 |
52 PrefServiceBuilder& WithAsync(bool async); | 48 PrefServiceBuilder& WithAsync(bool async); |
53 | 49 |
54 // Creates the PrefService, invalidating the entire builder configuration. | 50 // Initializes the PrefService object with the builder |
55 virtual PrefService* Create(); | 51 // configuration. This resets the entire builder configuration. |
52 virtual PrefService* Build(PrefService* pref_service); | |
Mattias Nissler (ping if slow)
2012/12/14 13:50:06
Ah, now I understand the issue :) You want the bui
kaiwang
2012/12/15 00:10:07
Initializing PrefServiceSimple and PrefServiceSync
| |
56 | 53 |
57 protected: | 54 protected: |
58 scoped_refptr<PrefStore> managed_prefs_; | 55 scoped_refptr<PrefStore> managed_prefs_; |
59 scoped_refptr<PrefStore> extension_prefs_; | 56 scoped_refptr<PrefStore> extension_prefs_; |
60 scoped_refptr<PrefStore> command_line_prefs_; | 57 scoped_refptr<PrefStore> command_line_prefs_; |
61 scoped_refptr<PersistentPrefStore> user_prefs_; | 58 scoped_refptr<PersistentPrefStore> user_prefs_; |
62 scoped_refptr<PrefStore> recommended_prefs_; | 59 scoped_refptr<PrefStore> recommended_prefs_; |
63 | 60 |
64 // TODO(joi): Would be nice to switch the various places that deal | |
65 // with this pointer to using scoped_ptr::Pass semantics. | |
66 PrefModelAssociator* sync_associator_; | |
67 | |
68 base::Callback<std::string(int)> get_localized_string_method_; | 61 base::Callback<std::string(int)> get_localized_string_method_; |
69 base::Callback<void(PersistentPrefStore::PrefReadError)> read_error_callback_; | 62 base::Callback<void(PersistentPrefStore::PrefReadError)> read_error_callback_; |
70 | 63 |
71 // Defaults to false. | 64 // Defaults to false. |
72 bool async_; | 65 bool async_; |
73 | 66 |
74 private: | 67 private: |
75 void ResetDefaultState(); | 68 void ResetDefaultState(); |
76 | 69 |
77 DISALLOW_COPY_AND_ASSIGN(PrefServiceBuilder); | 70 DISALLOW_COPY_AND_ASSIGN(PrefServiceBuilder); |
78 }; | 71 }; |
79 | 72 |
80 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_BUILDER_H_ | 73 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_BUILDER_H_ |
OLD | NEW |