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

Side by Side Diff: chrome/browser/prefs/chrome_pref_service_factory.cc

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
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 #include "chrome/browser/prefs/chrome_pref_service_factory.h" 5 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/prefs/default_pref_store.h" 12 #include "base/prefs/default_pref_store.h"
13 #include "base/prefs/json_pref_store.h" 13 #include "base/prefs/json_pref_store.h"
14 #include "base/prefs/pref_notifier_impl.h" 14 #include "base/prefs/pref_notifier_impl.h"
15 #include "base/prefs/pref_registry.h" 15 #include "base/prefs/pref_registry.h"
16 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
17 #include "base/prefs/pref_value_store.h" 17 #include "base/prefs/pref_value_store.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/prefs/command_line_pref_store.h" 19 #include "chrome/browser/prefs/command_line_pref_store.h"
20 #include "chrome/browser/prefs/pref_model_associator.h" 20 #include "chrome/browser/prefs/pref_model_associator.h"
21 #include "chrome/browser/prefs/pref_service_syncable_builder.h" 21 #include "chrome/browser/prefs/pref_service_syncable.h"
22 #include "chrome/browser/prefs/pref_service_syncable_factory.h"
22 #include "chrome/browser/ui/profile_error_dialog.h" 23 #include "chrome/browser/ui/profile_error_dialog.h"
23 #include "components/user_prefs/pref_registry_syncable.h" 24 #include "components/user_prefs/pref_registry_syncable.h"
24 #include "content/public/browser/browser_context.h" 25 #include "content/public/browser/browser_context.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
26 #include "grit/chromium_strings.h" 27 #include "grit/chromium_strings.h"
27 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
28 29
29 #if defined(ENABLE_CONFIGURATION_POLICY) 30 #if defined(ENABLE_CONFIGURATION_POLICY)
30 #include "chrome/browser/policy/browser_policy_connector.h" 31 #include "chrome/browser/policy/browser_policy_connector.h"
31 #include "chrome/browser/policy/configuration_policy_pref_store.h" 32 #include "chrome/browser/policy/configuration_policy_pref_store.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 base::Bind(&ShowProfileErrorDialog, message_id)); 66 base::Bind(&ShowProfileErrorDialog, message_id));
66 } 67 }
67 #else 68 #else
68 // On ChromeOS error screen with message about broken local state 69 // On ChromeOS error screen with message about broken local state
69 // will be displayed. 70 // will be displayed.
70 #endif 71 #endif
71 } 72 }
72 } 73 }
73 74
74 void PrepareBuilder( 75 void PrepareBuilder(
75 PrefServiceSyncableBuilder* builder, 76 PrefServiceSyncableFactory* factory,
76 const base::FilePath& pref_filename, 77 const base::FilePath& pref_filename,
77 base::SequencedTaskRunner* pref_io_task_runner, 78 base::SequencedTaskRunner* pref_io_task_runner,
78 policy::PolicyService* policy_service, 79 policy::PolicyService* policy_service,
79 ManagedUserSettingsService* managed_user_settings, 80 ManagedUserSettingsService* managed_user_settings,
80 const scoped_refptr<PrefStore>& extension_prefs, 81 const scoped_refptr<PrefStore>& extension_prefs,
81 bool async) { 82 bool async) {
82 #if defined(OS_LINUX) 83 #if defined(OS_LINUX)
83 // We'd like to see what fraction of our users have the preferences 84 // We'd like to see what fraction of our users have the preferences
84 // stored on a network file system, as we've had no end of troubles 85 // stored on a network file system, as we've had no end of troubles
85 // with NFS/AFS. 86 // with NFS/AFS.
86 // TODO(evanm): remove this once we've collected state. 87 // TODO(evanm): remove this once we've collected state.
87 file_util::FileSystemType fstype; 88 file_util::FileSystemType fstype;
88 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) { 89 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) {
89 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType", 90 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType",
90 static_cast<int>(fstype), 91 static_cast<int>(fstype),
91 file_util::FILE_SYSTEM_TYPE_COUNT); 92 file_util::FILE_SYSTEM_TYPE_COUNT);
92 } 93 }
93 #endif 94 #endif
94 95
95 #if defined(ENABLE_CONFIGURATION_POLICY) 96 #if defined(ENABLE_CONFIGURATION_POLICY)
96 using policy::ConfigurationPolicyPrefStore; 97 using policy::ConfigurationPolicyPrefStore;
97 builder->WithManagedPrefs(new ConfigurationPolicyPrefStore( 98 factory->set_managed_prefs(
98 policy_service, 99 make_scoped_refptr(new ConfigurationPolicyPrefStore(
99 g_browser_process->browser_policy_connector()->GetHandlerList(), 100 policy_service,
100 policy::POLICY_LEVEL_MANDATORY)); 101 g_browser_process->browser_policy_connector()->GetHandlerList(),
101 builder->WithRecommendedPrefs(new ConfigurationPolicyPrefStore( 102 policy::POLICY_LEVEL_MANDATORY)));
102 policy_service, 103 factory->set_recommended_prefs(
103 g_browser_process->browser_policy_connector()->GetHandlerList(), 104 make_scoped_refptr(new ConfigurationPolicyPrefStore(
104 policy::POLICY_LEVEL_RECOMMENDED)); 105 policy_service,
106 g_browser_process->browser_policy_connector()->GetHandlerList(),
107 policy::POLICY_LEVEL_RECOMMENDED)));
105 #endif // ENABLE_CONFIGURATION_POLICY 108 #endif // ENABLE_CONFIGURATION_POLICY
106 109
107 #if defined(ENABLE_MANAGED_USERS) 110 #if defined(ENABLE_MANAGED_USERS)
108 if (managed_user_settings) { 111 if (managed_user_settings) {
109 builder->WithSupervisedUserPrefs( 112 factory->set_supervised_user_prefs(
110 new SupervisedUserPrefStore(managed_user_settings)); 113 make_scoped_refptr(new SupervisedUserPrefStore(managed_user_settings)));
111 } 114 }
112 #endif 115 #endif
113 116
114 builder->WithAsync(async); 117 factory->set_async(async);
115 builder->WithExtensionPrefs(extension_prefs.get()); 118 factory->set_extension_prefs(extension_prefs);
116 builder->WithCommandLinePrefs( 119 factory->set_command_line_prefs(
117 new CommandLinePrefStore(CommandLine::ForCurrentProcess())); 120 make_scoped_refptr(
118 builder->WithReadErrorCallback(base::Bind(&HandleReadError)); 121 new CommandLinePrefStore(CommandLine::ForCurrentProcess())));
119 builder->WithUserPrefs(new JsonPrefStore(pref_filename, pref_io_task_runner)); 122 factory->set_read_error_callback(base::Bind(&HandleReadError));
123 factory->set_user_prefs(
124 new JsonPrefStore(pref_filename, pref_io_task_runner));
120 } 125 }
121 126
122 } // namespace 127 } // namespace
123 128
124 namespace chrome_prefs { 129 namespace chrome_prefs {
125 130
126 PrefService* CreateLocalState( 131 scoped_ptr<PrefService> CreateLocalState(
127 const base::FilePath& pref_filename, 132 const base::FilePath& pref_filename,
128 base::SequencedTaskRunner* pref_io_task_runner, 133 base::SequencedTaskRunner* pref_io_task_runner,
129 policy::PolicyService* policy_service, 134 policy::PolicyService* policy_service,
130 const scoped_refptr<PrefRegistry>& pref_registry, 135 const scoped_refptr<PrefRegistry>& pref_registry,
131 bool async) { 136 bool async) {
132 PrefServiceSyncableBuilder builder; 137 PrefServiceSyncableFactory factory;
133 PrepareBuilder(&builder, 138 PrepareBuilder(&factory,
134 pref_filename, 139 pref_filename,
135 pref_io_task_runner, 140 pref_io_task_runner,
136 policy_service, 141 policy_service,
137 NULL, 142 NULL,
138 NULL, 143 NULL,
139 async); 144 async);
140 return builder.Create(pref_registry.get()); 145 return factory.Create(pref_registry.get());
141 } 146 }
142 147
143 PrefServiceSyncable* CreateProfilePrefs( 148 scoped_ptr<PrefServiceSyncable> CreateProfilePrefs(
144 const base::FilePath& pref_filename, 149 const base::FilePath& pref_filename,
145 base::SequencedTaskRunner* pref_io_task_runner, 150 base::SequencedTaskRunner* pref_io_task_runner,
146 policy::PolicyService* policy_service, 151 policy::PolicyService* policy_service,
147 ManagedUserSettingsService* managed_user_settings, 152 ManagedUserSettingsService* managed_user_settings,
148 const scoped_refptr<PrefStore>& extension_prefs, 153 const scoped_refptr<PrefStore>& extension_prefs,
149 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry, 154 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry,
150 bool async) { 155 bool async) {
151 TRACE_EVENT0("browser", "chrome_prefs::CreateProfilePrefs"); 156 TRACE_EVENT0("browser", "chrome_prefs::CreateProfilePrefs");
152 PrefServiceSyncableBuilder builder; 157 PrefServiceSyncableFactory factory;
153 PrepareBuilder(&builder, 158 PrepareBuilder(&factory,
154 pref_filename, 159 pref_filename,
155 pref_io_task_runner, 160 pref_io_task_runner,
156 policy_service, 161 policy_service,
157 managed_user_settings, 162 managed_user_settings,
158 extension_prefs, 163 extension_prefs,
159 async); 164 async);
160 return builder.CreateSyncable(pref_registry.get()); 165 return factory.CreateSyncable(pref_registry.get());
161 } 166 }
162 167
163 } // namespace chrome_prefs 168 } // namespace chrome_prefs
OLDNEW
« no previous file with comments | « chrome/browser/prefs/chrome_pref_service_factory.h ('k') | chrome/browser/prefs/chrome_pref_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698