Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: base/prefs/pref_service_factory.h

Issue 64193003: Clean up PrefServiceBuilder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory ownership bug in ProxyPolicyTest Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/prefs/pref_service_builder.cc ('k') | base/prefs/pref_service_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 BASE_PREFS_PREF_SERVICE_BUILDER_H_ 5 #ifndef BASE_PREFS_PREF_SERVICE_FACTORY_H_
6 #define BASE_PREFS_PREF_SERVICE_BUILDER_H_ 6 #define BASE_PREFS_PREF_SERVICE_FACTORY_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/base_prefs_export.h" 11 #include "base/prefs/base_prefs_export.h"
12 #include "base/prefs/persistent_pref_store.h" 12 #include "base/prefs/persistent_pref_store.h"
13 #include "base/prefs/pref_registry.h" 13 #include "base/prefs/pref_registry.h"
14 #include "base/prefs/pref_store.h" 14 #include "base/prefs/pref_store.h"
15 15
16 class PrefService; 16 class PrefService;
17 17
18 namespace base { 18 namespace base {
19
19 class FilePath; 20 class FilePath;
20 class SequencedTaskRunner; 21 class SequencedTaskRunner;
21 }
22 22
23 // A class that allows convenient building of PrefService. 23 // A class that allows convenient building of PrefService.
24 class BASE_PREFS_EXPORT PrefServiceBuilder { 24 class BASE_PREFS_EXPORT PrefServiceFactory {
25 public: 25 public:
26 PrefServiceBuilder(); 26 PrefServiceFactory();
27 virtual ~PrefServiceBuilder(); 27 virtual ~PrefServiceFactory();
28 28
29 // Functions for setting the various parameters of the PrefService to build. 29 // Functions for setting the various parameters of the PrefService to build.
30 // These take ownership of the |store| parameter. 30 void set_managed_prefs(const scoped_refptr<PrefStore>& managed_prefs) {
31 PrefServiceBuilder& WithManagedPrefs(PrefStore* store); 31 managed_prefs_ = managed_prefs;
32 PrefServiceBuilder& WithSupervisedUserPrefs(PrefStore* store); 32 }
33 PrefServiceBuilder& WithExtensionPrefs(PrefStore* store); 33 void set_supervised_user_prefs(
34 PrefServiceBuilder& WithCommandLinePrefs(PrefStore* store); 34 const scoped_refptr<PrefStore>& supervised_user_prefs) {
35 PrefServiceBuilder& WithUserPrefs(PersistentPrefStore* store); 35 supervised_user_prefs_ = supervised_user_prefs;
36 PrefServiceBuilder& WithRecommendedPrefs(PrefStore* store); 36 }
37 void set_extension_prefs(const scoped_refptr<PrefStore>& extension_prefs) {
38 extension_prefs_ = extension_prefs;
39 }
40 void set_command_line_prefs(
41 const scoped_refptr<PrefStore>& command_line_prefs) {
42 command_line_prefs_ = command_line_prefs;
43 }
44 void set_user_prefs(const scoped_refptr<PersistentPrefStore>& user_prefs) {
45 user_prefs_ = user_prefs;
46 }
47 void set_recommended_prefs(
48 const scoped_refptr<PrefStore>& recommended_prefs) {
49 recommended_prefs_ = recommended_prefs;
50 }
37 51
38 // Sets up error callback for the PrefService. A do-nothing default 52 // Sets up error callback for the PrefService. A do-nothing default
39 // is provided if this is not called. 53 // is provided if this is not called.
40 PrefServiceBuilder& WithReadErrorCallback( 54 void set_read_error_callback(
41 const base::Callback<void(PersistentPrefStore::PrefReadError)>& 55 const base::Callback<void(PersistentPrefStore::PrefReadError)>&
42 read_error_callback); 56 read_error_callback) {
57 read_error_callback_ = read_error_callback;
58 }
43 59
44 // Specifies to use an actual file-backed user pref store. 60 // Specifies to use an actual file-backed user pref store.
45 PrefServiceBuilder& WithUserFilePrefs( 61 void SetUserPrefsFile(const base::FilePath& prefs_file,
46 const base::FilePath& prefs_file, 62 base::SequencedTaskRunner* task_runner);
47 base::SequencedTaskRunner* task_runner);
48 63
49 PrefServiceBuilder& WithAsync(bool async); 64 void set_async(bool async) {
65 async_ = async;
66 }
50 67
51 // Creates a PrefService object initialized with the parameters from 68 // Creates a PrefService object initialized with the parameters from
52 // this builder. 69 // this factory.
53 virtual PrefService* Create(PrefRegistry* registry); 70 scoped_ptr<PrefService> Create(PrefRegistry* registry);
54 71
55 protected: 72 protected:
56 virtual void ResetDefaultState();
57
58 scoped_refptr<PrefStore> managed_prefs_; 73 scoped_refptr<PrefStore> managed_prefs_;
59 scoped_refptr<PrefStore> supervised_user_prefs_; 74 scoped_refptr<PrefStore> supervised_user_prefs_;
60 scoped_refptr<PrefStore> extension_prefs_; 75 scoped_refptr<PrefStore> extension_prefs_;
61 scoped_refptr<PrefStore> command_line_prefs_; 76 scoped_refptr<PrefStore> command_line_prefs_;
62 scoped_refptr<PersistentPrefStore> user_prefs_; 77 scoped_refptr<PersistentPrefStore> user_prefs_;
63 scoped_refptr<PrefStore> recommended_prefs_; 78 scoped_refptr<PrefStore> recommended_prefs_;
64 79
65 base::Callback<void(PersistentPrefStore::PrefReadError)> read_error_callback_; 80 base::Callback<void(PersistentPrefStore::PrefReadError)> read_error_callback_;
66 81
67 // Defaults to false. 82 // Defaults to false.
68 bool async_; 83 bool async_;
69 84
70 private: 85 private:
71 DISALLOW_COPY_AND_ASSIGN(PrefServiceBuilder); 86 DISALLOW_COPY_AND_ASSIGN(PrefServiceFactory);
72 }; 87 };
73 88
74 #endif // BASE_PREFS_PREF_SERVICE_BUILDER_H_ 89 } // namespace base
90
91 #endif // BASE_PREFS_PREF_SERVICE_FACTORY_H_
OLDNEW
« no previous file with comments | « base/prefs/pref_service_builder.cc ('k') | base/prefs/pref_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698