1 // Copyright 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.
5 #include "chrome/browser/prefs/browser_prefs.h"
7 #include "apps/prefs.h"
8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/about_flags.h"
11 #include "chrome/browser/accessibility/invert_bubble_prefs.h"
12 #include "chrome/browser/background/background_mode_manager.h"
13 #include "chrome/browser/bookmarks/bookmark_prompt_prefs.h"
14 #include "chrome/browser/bookmarks/bookmark_utils.h"
15 #include "chrome/browser/browser_process_impl.h"
16 #include "chrome/browser/browser_shutdown.h"
17 #include "chrome/browser/chrome_content_browser_client.h"
18 #include "chrome/browser/component_updater/recovery_component_installer.h"
19 #include "chrome/browser/content_settings/host_content_settings_map.h"
20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
21 #include "chrome/browser/devtools/devtools_window.h"
22 #include "chrome/browser/download/chrome_download_manager_delegate.h"
23 #include "chrome/browser/download/download_prefs.h"
24 #include "chrome/browser/extensions/api/commands/command_service.h"
25 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
26 #include "chrome/browser/extensions/component_loader.h"
27 #include "chrome/browser/extensions/extension_prefs.h"
28 #include "chrome/browser/extensions/extension_web_ui.h"
29 #include "chrome/browser/external_protocol/external_protocol_handler.h"
30 #include "chrome/browser/first_run/first_run.h"
31 #include "chrome/browser/geolocation/geolocation_prefs.h"
32 #include "chrome/browser/google/google_url_tracker.h"
33 #include "chrome/browser/google/google_url_tracker_factory.h"
34 #include "chrome/browser/gpu/gl_string_manager.h"
35 #include "chrome/browser/gpu/gpu_mode_manager.h"
36 #include "chrome/browser/intranet_redirect_detector.h"
37 #include "chrome/browser/io_thread.h"
38 #include "chrome/browser/managed_mode/managed_mode.h"
39 #include "chrome/browser/managed_mode/managed_user_service.h"
40 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
41 #include "chrome/browser/media/media_stream_devices_controller.h"
42 #include "chrome/browser/metrics/metrics_log.h"
43 #include "chrome/browser/metrics/metrics_service.h"
44 #include "chrome/browser/metrics/variations/variations_service.h"
45 #include "chrome/browser/net/http_server_properties_manager.h"
46 #include "chrome/browser/net/net_pref_observer.h"
47 #include "chrome/browser/net/predictor.h"
48 #include "chrome/browser/net/ssl_config_service_manager.h"
49 #include "chrome/browser/notifications/desktop_notification_service.h"
50 #include "chrome/browser/notifications/notification_prefs_manager.h"
51 #include "chrome/browser/password_manager/password_manager.h"
52 #include "chrome/browser/pepper_flash_settings_manager.h"
53 #include "chrome/browser/plugins/plugin_finder.h"
54 #include "chrome/browser/prefs/incognito_mode_prefs.h"
55 #include "chrome/browser/prefs/pref_service_syncable.h"
56 #include "chrome/browser/prefs/session_startup_pref.h"
57 #include "chrome/browser/printing/cloud_print/cloud_print_url.h"
58 #include "chrome/browser/printing/print_dialog_cloud.h"
59 #include "chrome/browser/profiles/chrome_version_service.h"
60 #include "chrome/browser/profiles/profile.h"
61 #include "chrome/browser/profiles/profile_impl.h"
62 #include "chrome/browser/profiles/profile_info_cache.h"
63 #include "chrome/browser/profiles/profile_manager.h"
64 #include "chrome/browser/renderer_host/web_cache_manager.h"
65 #include "chrome/browser/search/search.h"
66 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
67 #include "chrome/browser/signin/signin_manager_factory.h"
68 #include "chrome/browser/sync/invalidations/invalidator_storage.h"
69 #include "chrome/browser/sync/sync_prefs.h"
70 #include "chrome/browser/task_manager/task_manager.h"
71 #include "chrome/browser/translate/translate_prefs.h"
72 #include "chrome/browser/ui/alternate_error_tab_observer.h"
73 #include "chrome/browser/ui/app_list/app_list_service.h"
74 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
75 #include "chrome/browser/ui/browser_ui_prefs.h"
76 #include "chrome/browser/ui/network_profile_bubble.h"
77 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
78 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h"
79 #include "chrome/browser/ui/startup/autolaunch_prompt.h"
80 #include "chrome/browser/ui/startup/default_browser_prompt.h"
81 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
82 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h"
83 #include "chrome/browser/ui/webui/flags_ui.h"
84 #include "chrome/browser/ui/webui/instant_ui.h"
85 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
86 #include "chrome/browser/ui/webui/plugins_ui.h"
87 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h"
88 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
89 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
90 #include "chrome/browser/upgrade_detector.h"
91 #include "chrome/browser/web_resource/promo_resource_service.h"
92 #include "chrome/common/pref_names.h"
93 #include "components/autofill/browser/autofill_manager.h"
94 #include "components/user_prefs/pref_registry_syncable.h"
95 #include "content/public/browser/render_process_host.h"
97 #if defined(ENABLE_CONFIGURATION_POLICY)
98 #include "chrome/browser/policy/browser_policy_connector.h"
99 #include "chrome/browser/policy/policy_statistics_collector.h"
100 #include "chrome/browser/policy/url_blacklist_manager.h"
103 #if defined(OS_MACOSX)
104 #include "chrome/browser/ui/cocoa/confirm_quit.h"
107 #if defined(TOOLKIT_VIEWS)
108 #include "chrome/browser/ui/browser_view_prefs.h"
109 #include "chrome/browser/ui/tabs/tab_strip_layout_type_prefs.h"
112 #if defined(TOOLKIT_GTK)
113 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
116 #if defined(OS_CHROMEOS)
117 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
118 #include "chrome/browser/chromeos/audio/audio_handler.h"
119 #include "chrome/browser/chromeos/customization_document.h"
120 #include "chrome/browser/chromeos/display/display_preferences.h"
121 #include "chrome/browser/chromeos/login/login_utils.h"
122 #include "chrome/browser/chromeos/login/oauth2_login_manager.h"
123 #include "chrome/browser/chromeos/login/user_image_manager.h"
124 #include "chrome/browser/chromeos/login/user_manager.h"
125 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
126 #include "chrome/browser/chromeos/login/wizard_controller.h"
127 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h"
128 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
129 #include "chrome/browser/chromeos/policy/device_status_collector.h"
130 #include "chrome/browser/chromeos/preferences.h"
131 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
132 #include "chrome/browser/chromeos/settings/device_settings_cache.h"
133 #include "chrome/browser/chromeos/status/data_promo_notification.h"
134 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
136 #include "chrome/browser/extensions/default_apps.h"
140 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
143 #if !defined(OS_ANDROID)
144 #include "chrome/browser/chrome_to_mobile_service.h"
147 #if defined(OS_ANDROID)
148 #include "chrome/browser/ui/webui/ntp/android/promo_handler.h"
151 #if defined(ENABLE_PLUGIN_INSTALLATION)
152 #include "chrome/browser/plugins/plugins_resource_service.h"
157 enum MigratedPreferences
{
160 WINDOWS_PREFS
= 1 << 1,
161 GOOGLE_URL_TRACKER_PREFS
= 1 << 2,
164 // A previous feature (see
165 // chrome/browser/protector/protected_prefs_watcher.cc in source
166 // control history) used this string as a prefix for various prefs it
167 // registered. We keep it here for now to clear out those old prefs in
169 const char kBackupPref
[] = "backup";
175 void RegisterLocalState(PrefRegistrySimple
* registry
) {
176 // Prefs in Local State.
177 registry
->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration
, 0);
179 // Please keep this list alphabetized.
180 AppListService::RegisterPrefs(registry
);
181 apps::RegisterPrefs(registry
);
182 browser_shutdown::RegisterPrefs(registry
);
183 BrowserProcessImpl::RegisterPrefs(registry
);
184 RegisterScreenshotPrefs(registry
);
185 ExternalProtocolHandler::RegisterPrefs(registry
);
186 FlagsUI::RegisterPrefs(registry
);
187 geolocation::RegisterPrefs(registry
);
188 GLStringManager::RegisterPrefs(registry
);
189 GpuModeManager::RegisterPrefs(registry
);
190 IntranetRedirectDetector::RegisterPrefs(registry
);
191 IOThread::RegisterPrefs(registry
);
192 KeywordEditorController::RegisterPrefs(registry
);
193 MetricsLog::RegisterPrefs(registry
);
194 MetricsService::RegisterPrefs(registry
);
195 PrefProxyConfigTrackerImpl::RegisterPrefs(registry
);
196 ProfileInfoCache::RegisterPrefs(registry
);
197 ProfileManager::RegisterPrefs(registry
);
198 PromoResourceService::RegisterPrefs(registry
);
199 RegisterPrefsForRecoveryComponent(registry
);
200 SigninManagerFactory::RegisterPrefs(registry
);
201 SSLConfigServiceManager::RegisterPrefs(registry
);
202 UpgradeDetector::RegisterPrefs(registry
);
203 WebCacheManager::RegisterPrefs(registry
);
205 #if defined(ENABLE_PLUGINS)
206 PluginFinder::RegisterPrefs(registry
);
209 #if defined(ENABLE_PLUGIN_INSTALLATION)
210 PluginsResourceService::RegisterPrefs(registry
);
213 #if defined(ENABLE_CONFIGURATION_POLICY)
214 policy::BrowserPolicyConnector::RegisterPrefs(registry
);
215 policy::PolicyStatisticsCollector::RegisterPrefs(registry
);
218 #if defined(ENABLE_NOTIFICATIONS)
219 NotificationPrefsManager::RegisterPrefs(registry
);
222 #if defined(ENABLE_TASK_MANAGER)
223 TaskManager::RegisterPrefs(registry
);
224 #endif // defined(ENABLE_TASK_MANAGER)
226 #if defined(TOOLKIT_VIEWS)
227 RegisterBrowserViewPrefs(registry
);
228 RegisterTabStripLayoutTypePrefs(registry
);
231 #if !defined(OS_ANDROID)
232 BackgroundModeManager::RegisterPrefs(registry
);
233 chrome_variations::VariationsService::RegisterPrefs(registry
);
234 RegisterBrowserPrefs(registry
);
235 RegisterDefaultBrowserPromptPrefs(registry
);
236 ManagedMode::RegisterPrefs(registry
);
239 #if defined(OS_CHROMEOS)
240 chromeos::AudioHandler::RegisterPrefs(registry
);
241 chromeos::DataPromoNotification::RegisterPrefs(registry
);
242 chromeos::device_settings_cache::RegisterPrefs(registry
);
243 chromeos::language_prefs::RegisterPrefs(registry
);
244 chromeos::KioskAppManager::RegisterPrefs(registry
);
245 chromeos::LoginUtils::RegisterPrefs(registry
);
246 chromeos::Preferences::RegisterPrefs(registry
);
247 chromeos::ProxyConfigServiceImpl::RegisterPrefs(registry
);
248 chromeos::RegisterDisplayLocalStatePrefs(registry
);
249 chromeos::ServicesCustomizationDocument::RegisterPrefs(registry
);
250 chromeos::system::AutomaticRebootManager::RegisterPrefs(registry
);
251 chromeos::UserImageManager::RegisterPrefs(registry
);
252 chromeos::UserManager::RegisterPrefs(registry
);
253 chromeos::WallpaperManager::RegisterPrefs(registry
);
254 chromeos::WizardController::RegisterPrefs(registry
);
255 policy::AutoEnrollmentClient::RegisterPrefs(registry
);
256 policy::DeviceStatusCollector::RegisterPrefs(registry
);
259 #if defined(OS_MACOSX)
260 confirm_quit::RegisterLocalState(registry
);
264 void RegisterUserPrefs(PrefRegistrySyncable
* registry
) {
265 // User prefs. Please keep this list alphabetized.
266 AlternateErrorPageTabObserver::RegisterUserPrefs(registry
);
267 autofill::AutofillDialogControllerImpl::RegisterUserPrefs(registry
);
268 autofill::AutofillManager::RegisterUserPrefs(registry
);
269 BookmarkPromptPrefs::RegisterUserPrefs(registry
);
270 bookmark_utils::RegisterUserPrefs(registry
);
271 browser_sync::SyncPrefs::RegisterUserPrefs(registry
);
272 chrome::RegisterInstantUserPrefs(registry
);
273 ChromeContentBrowserClient::RegisterUserPrefs(registry
);
274 ChromeDownloadManagerDelegate::RegisterUserPrefs(registry
);
275 ChromeVersionService::RegisterUserPrefs(registry
);
276 chrome_browser_net::HttpServerPropertiesManager::RegisterUserPrefs(
278 chrome_browser_net::Predictor::RegisterUserPrefs(registry
);
279 DownloadPrefs::RegisterUserPrefs(registry
);
280 extensions::ComponentLoader::RegisterUserPrefs(registry
);
281 extensions::ExtensionPrefs::RegisterUserPrefs(registry
);
282 ExtensionWebUI::RegisterUserPrefs(registry
);
283 first_run::RegisterUserPrefs(registry
);
284 HostContentSettingsMap::RegisterUserPrefs(registry
);
285 IncognitoModePrefs::RegisterUserPrefs(registry
);
286 InstantUI::RegisterUserPrefs(registry
);
287 browser_sync::InvalidatorStorage::RegisterUserPrefs(registry
);
288 MediaCaptureDevicesDispatcher::RegisterUserPrefs(registry
);
289 MediaStreamDevicesController::RegisterUserPrefs(registry
);
290 NetPrefObserver::RegisterUserPrefs(registry
);
291 NewTabUI::RegisterUserPrefs(registry
);
292 PasswordManager::RegisterUserPrefs(registry
);
293 PrefProxyConfigTrackerImpl::RegisterUserPrefs(registry
);
294 PrefsTabHelper::RegisterUserPrefs(registry
);
295 Profile::RegisterUserPrefs(registry
);
296 ProfileImpl::RegisterUserPrefs(registry
);
297 PromoResourceService::RegisterUserPrefs(registry
);
298 ProtocolHandlerRegistry::RegisterUserPrefs(registry
);
299 RegisterBrowserUserPrefs(registry
);
300 SessionStartupPref::RegisterUserPrefs(registry
);
301 TemplateURLPrepopulateData::RegisterUserPrefs(registry
);
302 TranslatePrefs::RegisterUserPrefs(registry
);
304 #if defined(ENABLE_CONFIGURATION_POLICY)
305 policy::BrowserPolicyConnector::RegisterUserPrefs(registry
);
306 policy::URLBlacklistManager::RegisterUserPrefs(registry
);
309 #if defined(ENABLE_MANAGED_USERS)
310 ManagedUserService::RegisterUserPrefs(registry
);
313 #if defined(ENABLE_NOTIFICATIONS)
314 DesktopNotificationService::RegisterUserPrefs(registry
);
317 #if defined(TOOLKIT_VIEWS)
318 RegisterInvertBubbleUserPrefs(registry
);
319 #elif defined(TOOLKIT_GTK)
320 BrowserWindowGtk::RegisterUserPrefs(registry
);
323 #if defined(OS_ANDROID)
324 PromoHandler::RegisterUserPrefs(registry
);
328 ash::RegisterChromeLauncherUserPrefs(registry
);
331 #if !defined(OS_ANDROID)
332 TabsCaptureVisibleTabFunction::RegisterUserPrefs(registry
);
333 ChromeToMobileService::RegisterUserPrefs(registry
);
334 DevToolsWindow::RegisterUserPrefs(registry
);
335 extensions::CommandService::RegisterUserPrefs(registry
);
336 ExtensionSettingsHandler::RegisterUserPrefs(registry
);
337 PepperFlashSettingsManager::RegisterUserPrefs(registry
);
338 PinnedTabCodec::RegisterUserPrefs(registry
);
339 PluginsUI::RegisterUserPrefs(registry
);
340 CloudPrintURL::RegisterUserPrefs(registry
);
341 print_dialog_cloud::RegisterUserPrefs(registry
);
342 printing::StickySettings::RegisterUserPrefs(registry
);
343 RegisterAutolaunchUserPrefs(registry
);
344 SyncPromoUI::RegisterUserPrefs(registry
);
347 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
348 default_apps::RegisterUserPrefs(registry
);
351 #if defined(OS_CHROMEOS)
352 chromeos::OAuth2LoginManager::RegisterUserPrefs(registry
);
353 chromeos::Preferences::RegisterUserPrefs(registry
);
354 chromeos::ProxyConfigServiceImpl::RegisterUserPrefs(registry
);
355 FlagsUI::RegisterUserPrefs(registry
);
359 NetworkProfileBubble::RegisterUserPrefs(registry
);
362 // Prefs registered only for migration (clearing or moving to a new
364 registry
->RegisterDictionaryPref(kBackupPref
, new DictionaryValue(),
365 PrefRegistrySyncable::UNSYNCABLE_PREF
);
368 void MigrateUserPrefs(Profile
* profile
) {
369 PrefService
* prefs
= profile
->GetPrefs();
371 // Cleanup prefs from now-removed protector feature.
372 prefs
->ClearPref(kBackupPref
);
374 PrefsTabHelper::MigrateUserPrefs(prefs
);
375 PromoResourceService::MigrateUserPrefs(prefs
);
376 TranslatePrefs::MigrateUserPrefs(prefs
);
379 void MigrateBrowserPrefs(Profile
* profile
, PrefService
* local_state
) {
380 // Copy pref values which have been migrated to user_prefs from local_state,
381 // or remove them from local_state outright, if copying is not required.
382 int current_version
=
383 local_state
->GetInteger(prefs::kMultipleProfilePrefMigration
);
384 PrefRegistrySimple
* registry
= static_cast<PrefRegistrySimple
*>(
385 local_state
->DeprecatedGetPrefRegistry());
387 if (!(current_version
& DNS_PREFS
)) {
388 registry
->RegisterListPref(prefs::kDnsStartupPrefetchList
);
389 local_state
->ClearPref(prefs::kDnsStartupPrefetchList
);
391 registry
->RegisterListPref(prefs::kDnsHostReferralList
);
392 local_state
->ClearPref(prefs::kDnsHostReferralList
);
394 current_version
|= DNS_PREFS
;
395 local_state
->SetInteger(prefs::kMultipleProfilePrefMigration
,
399 PrefService
* user_prefs
= profile
->GetPrefs();
400 if (!(current_version
& WINDOWS_PREFS
)) {
401 registry
->RegisterIntegerPref(prefs::kDevToolsHSplitLocation
, -1);
402 if (local_state
->HasPrefPath(prefs::kDevToolsHSplitLocation
)) {
403 user_prefs
->SetInteger(
404 prefs::kDevToolsHSplitLocation
,
405 local_state
->GetInteger(prefs::kDevToolsHSplitLocation
));
407 local_state
->ClearPref(prefs::kDevToolsHSplitLocation
);
409 registry
->RegisterDictionaryPref(prefs::kBrowserWindowPlacement
);
410 if (local_state
->HasPrefPath(prefs::kBrowserWindowPlacement
)) {
411 const PrefService::Preference
* pref
=
412 local_state
->FindPreference(prefs::kBrowserWindowPlacement
);
414 user_prefs
->Set(prefs::kBrowserWindowPlacement
,
415 *(pref
->GetValue()));
417 local_state
->ClearPref(prefs::kBrowserWindowPlacement
);
419 current_version
|= WINDOWS_PREFS
;
420 local_state
->SetInteger(prefs::kMultipleProfilePrefMigration
,
424 if (!(current_version
& GOOGLE_URL_TRACKER_PREFS
)) {
425 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(profile
);
426 registry
->RegisterStringPref(prefs::kLastKnownGoogleURL
,
427 GoogleURLTracker::kDefaultGoogleHomepage
);
428 if (local_state
->HasPrefPath(prefs::kLastKnownGoogleURL
)) {
429 user_prefs
->SetString(prefs::kLastKnownGoogleURL
,
430 local_state
->GetString(prefs::kLastKnownGoogleURL
));
432 local_state
->ClearPref(prefs::kLastKnownGoogleURL
);
434 registry
->RegisterStringPref(prefs::kLastPromptedGoogleURL
,
436 if (local_state
->HasPrefPath(prefs::kLastPromptedGoogleURL
)) {
437 user_prefs
->SetString(
438 prefs::kLastPromptedGoogleURL
,
439 local_state
->GetString(prefs::kLastPromptedGoogleURL
));
441 local_state
->ClearPref(prefs::kLastPromptedGoogleURL
);
443 current_version
|= GOOGLE_URL_TRACKER_PREFS
;
444 local_state
->SetInteger(prefs::kMultipleProfilePrefMigration
,
449 } // namespace chrome