• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/prefs/browser_prefs.h"
6 
7 #include <string>
8 
9 #include "base/debug/trace_event.h"
10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h"
12 #include "chrome/browser/about_flags.h"
13 #include "chrome/browser/accessibility/invert_bubble_prefs.h"
14 #include "chrome/browser/apps/drive/drive_app_mapping.h"
15 #include "chrome/browser/apps/shortcut_manager.h"
16 #include "chrome/browser/autocomplete/zero_suggest_provider.h"
17 #include "chrome/browser/background/background_mode_manager.h"
18 #include "chrome/browser/browser_process_impl.h"
19 #include "chrome/browser/browser_shutdown.h"
20 #include "chrome/browser/chrome_content_browser_client.h"
21 #include "chrome/browser/component_updater/recovery_component_installer.h"
22 #include "chrome/browser/content_settings/host_content_settings_map.h"
23 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
24 #include "chrome/browser/devtools/devtools_window.h"
25 #include "chrome/browser/download/download_prefs.h"
26 #include "chrome/browser/external_protocol/external_protocol_handler.h"
27 #include "chrome/browser/first_run/first_run.h"
28 #include "chrome/browser/geolocation/geolocation_prefs.h"
29 #include "chrome/browser/google/google_url_tracker_factory.h"
30 #include "chrome/browser/gpu/gl_string_manager.h"
31 #include "chrome/browser/gpu/gpu_mode_manager.h"
32 #include "chrome/browser/intranet_redirect_detector.h"
33 #include "chrome/browser/io_thread.h"
34 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
35 #include "chrome/browser/media/media_device_id_salt.h"
36 #include "chrome/browser/media/media_stream_devices_controller.h"
37 #include "chrome/browser/metrics/chrome_metrics_service_client.h"
38 #include "chrome/browser/metrics/variations/variations_service.h"
39 #include "chrome/browser/net/http_server_properties_manager_factory.h"
40 #include "chrome/browser/net/net_pref_observer.h"
41 #include "chrome/browser/net/prediction_options.h"
42 #include "chrome/browser/net/predictor.h"
43 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h"
44 #include "chrome/browser/net/ssl_config_service_manager.h"
45 #include "chrome/browser/notifications/desktop_notification_service.h"
46 #include "chrome/browser/notifications/extension_welcome_notification.h"
47 #include "chrome/browser/notifications/message_center_notification_manager.h"
48 #include "chrome/browser/pepper_flash_settings_manager.h"
49 #include "chrome/browser/plugins/plugin_finder.h"
50 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
51 #include "chrome/browser/prefs/incognito_mode_prefs.h"
52 #include "chrome/browser/prefs/pref_service_syncable.h"
53 #include "chrome/browser/prefs/session_startup_pref.h"
54 #include "chrome/browser/printing/print_dialog_cloud.h"
55 #include "chrome/browser/profiles/chrome_version_service.h"
56 #include "chrome/browser/profiles/profile.h"
57 #include "chrome/browser/profiles/profile_impl.h"
58 #include "chrome/browser/profiles/profile_info_cache.h"
59 #include "chrome/browser/profiles/profiles_state.h"
60 #include "chrome/browser/renderer_host/pepper/device_id_fetcher.h"
61 #include "chrome/browser/search/search.h"
62 #include "chrome/browser/services/gcm/gcm_profile_service.h"
63 #include "chrome/browser/signin/signin_manager_factory.h"
64 #include "chrome/browser/signin/signin_promo.h"
65 #include "chrome/browser/task_manager/task_manager.h"
66 #include "chrome/browser/ui/app_list/app_list_service.h"
67 #include "chrome/browser/ui/browser_ui_prefs.h"
68 #include "chrome/browser/ui/navigation_correction_tab_observer.h"
69 #include "chrome/browser/ui/network_profile_bubble.h"
70 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
71 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h"
72 #include "chrome/browser/ui/startup/autolaunch_prompt.h"
73 #include "chrome/browser/ui/startup/default_browser_prompt.h"
74 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
75 #include "chrome/browser/ui/webui/flags_ui.h"
76 #include "chrome/browser/ui/webui/instant_ui.h"
77 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
78 #include "chrome/browser/ui/webui/plugins_ui.h"
79 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h"
80 #include "chrome/browser/upgrade_detector.h"
81 #include "chrome/browser/web_resource/promo_resource_service.h"
82 #include "chrome/common/pref_names.h"
83 #include "components/autofill/core/browser/autofill_manager.h"
84 #include "components/bookmarks/browser/bookmark_utils.h"
85 #include "components/dom_distiller/core/distilled_page_prefs.h"
86 #include "components/gcm_driver/gcm_channel_status_syncer.h"
87 #include "components/google/core/browser/google_pref_names.h"
88 #include "components/google/core/browser/google_url_tracker.h"
89 #include "components/network_time/network_time_tracker.h"
90 #include "components/password_manager/core/browser/password_manager.h"
91 #include "components/pref_registry/pref_registry_syncable.h"
92 #include "components/rappor/rappor_service.h"
93 #include "components/search_engines/template_url_prepopulate_data.h"
94 #include "components/sync_driver/sync_prefs.h"
95 #include "components/translate/core/browser/translate_prefs.h"
96 #include "content/public/browser/render_process_host.h"
97 #include "net/http/http_server_properties_manager.h"
98 
99 #if defined(ENABLE_AUTOFILL_DIALOG)
100 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
101 #endif
102 
103 #if defined(ENABLE_CONFIGURATION_POLICY)
104 #include "components/policy/core/browser/browser_policy_connector.h"
105 #include "components/policy/core/browser/url_blacklist_manager.h"
106 #include "components/policy/core/common/policy_statistics_collector.h"
107 #endif
108 
109 #if defined(ENABLE_EXTENSIONS)
110 #include "chrome/browser/extensions/activity_log/activity_log.h"
111 #include "chrome/browser/extensions/api/commands/command_service.h"
112 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
113 #include "chrome/browser/extensions/extension_web_ui.h"
114 #include "chrome/browser/extensions/launch_util.h"
115 #include "chrome/browser/signin/easy_unlock_service.h"
116 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h"
117 #include "extensions/browser/extension_prefs.h"
118 #endif
119 
120 #if defined(ENABLE_MANAGED_USERS)
121 #include "chrome/browser/supervised_user/supervised_user_service.h"
122 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service.h"
123 #include "chrome/browser/supervised_user/supervised_user_sync_service.h"
124 #endif
125 
126 #if defined(ENABLE_SERVICE_DISCOVERY)
127 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui.h"
128 #endif
129 
130 #if defined(ENABLE_PLUGIN_INSTALLATION)
131 #include "chrome/browser/plugins/plugins_resource_service.h"
132 #endif
133 
134 #if defined(OS_ANDROID)
135 #include "chrome/browser/android/bookmarks/partner_bookmarks_shim.h"
136 #include "chrome/browser/android/new_tab_page_prefs.h"
137 #else
138 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
139 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
140 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h"
141 #endif
142 
143 #if defined(OS_CHROMEOS)
144 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
145 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h"
146 #include "chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h"
147 #include "chrome/browser/chromeos/customization_document.h"
148 #include "chrome/browser/chromeos/display/display_preferences.h"
149 #include "chrome/browser/chromeos/extensions/echo_private_api.h"
150 #include "chrome/browser/chromeos/file_system_provider/service.h"
151 #include "chrome/browser/chromeos/first_run/first_run.h"
152 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h"
153 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h"
154 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
155 #include "chrome/browser/chromeos/login/startup_utils.h"
156 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h"
157 #include "chrome/browser/chromeos/login/users/avatar/user_image_sync_observer.h"
158 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h"
159 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
160 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
161 #include "chrome/browser/chromeos/net/proxy_config_handler.h"
162 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h"
163 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
164 #include "chrome/browser/chromeos/policy/consumer_management_service.h"
165 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
166 #include "chrome/browser/chromeos/policy/device_status_collector.h"
167 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
168 #include "chrome/browser/chromeos/power/power_prefs.h"
169 #include "chrome/browser/chromeos/preferences.h"
170 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
171 #include "chrome/browser/chromeos/settings/device_settings_cache.h"
172 #include "chrome/browser/chromeos/status/data_promo_notification.h"
173 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
174 #include "chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.h"
175 #include "chrome/browser/extensions/extension_assets_manager_chromeos.h"
176 #include "chrome/browser/metrics/chromeos_metrics_provider.h"
177 #include "chrome/browser/ui/webui/chromeos/charger_replacement_handler.h"
178 #include "chrome/browser/ui/webui/chromeos/login/demo_mode_detector.h"
179 #include "chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h"
180 #include "chrome/browser/ui/webui/chromeos/login/reset_screen_handler.h"
181 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
182 #include "components/invalidation/invalidator_storage.h"
183 #else
184 #include "chrome/browser/extensions/default_apps.h"
185 #endif
186 
187 #if defined(OS_MACOSX)
188 #include "chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h"
189 #include "chrome/browser/ui/cocoa/confirm_quit.h"
190 #endif
191 
192 #if defined(OS_WIN)
193 #include "chrome/browser/apps/app_launch_for_metro_restart_win.h"
194 #include "chrome/browser/component_updater/sw_reporter_installer_win.h"
195 #endif
196 
197 #if defined(TOOLKIT_VIEWS)
198 #include "chrome/browser/ui/browser_view_prefs.h"
199 #endif
200 
201 #if defined(USE_ASH)
202 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
203 #endif
204 
205 namespace {
206 
207 enum MigratedPreferences {
208   NO_PREFS = 0,
209   DNS_PREFS = 1 << 0,
210   WINDOWS_PREFS = 1 << 1,
211   GOOGLE_URL_TRACKER_PREFS = 1 << 2,
212 };
213 
214 // A previous feature (see
215 // chrome/browser/protector/protected_prefs_watcher.cc in source
216 // control history) used this string as a prefix for various prefs it
217 // registered. We keep it here for now to clear out those old prefs in
218 // MigrateUserPrefs.
219 const char kBackupPref[] = "backup";
220 
221 #if !defined(OS_ANDROID)
222 // The sync promo error message preference has been removed; this pref will
223 // be cleared from user data.
224 const char kSyncPromoErrorMessage[] = "sync_promo.error_message";
225 
226 // The AutomaticProfileResetter service used this preference to save that the
227 // profile reset prompt had already been shown, however, the preference has been
228 // renamed in Local State. We keep the name here for now so that we can clear
229 // out legacy values.
230 // TODO(engedy): Remove this and usages in M42 or later. See crbug.com/398813.
231 const char kLegacyProfileResetPromptMemento[] = "profile.reset_prompt_memento";
232 #endif
233 
234 }  // namespace
235 
236 namespace chrome {
237 
RegisterLocalState(PrefRegistrySimple * registry)238 void RegisterLocalState(PrefRegistrySimple* registry) {
239   // Prefs in Local State.
240   registry->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0);
241 
242   // Please keep this list alphabetized.
243   AppListService::RegisterPrefs(registry);
244   browser_shutdown::RegisterPrefs(registry);
245   BrowserProcessImpl::RegisterPrefs(registry);
246   ChromeMetricsServiceClient::RegisterPrefs(registry);
247   chrome_prefs::RegisterPrefs(registry);
248   chrome_variations::VariationsService::RegisterPrefs(registry);
249   component_updater::RegisterPrefsForRecoveryComponent(registry);
250   ExternalProtocolHandler::RegisterPrefs(registry);
251   FlagsUI::RegisterPrefs(registry);
252   geolocation::RegisterPrefs(registry);
253   GLStringManager::RegisterPrefs(registry);
254   GpuModeManager::RegisterPrefs(registry);
255   IntranetRedirectDetector::RegisterPrefs(registry);
256   IOThread::RegisterPrefs(registry);
257   network_time::NetworkTimeTracker::RegisterPrefs(registry);
258   PrefProxyConfigTrackerImpl::RegisterPrefs(registry);
259   ProfileInfoCache::RegisterPrefs(registry);
260   profiles::RegisterPrefs(registry);
261   PromoResourceService::RegisterPrefs(registry);
262   rappor::RapporService::RegisterPrefs(registry);
263   RegisterScreenshotPrefs(registry);
264   SigninManagerFactory::RegisterPrefs(registry);
265   SSLConfigServiceManager::RegisterPrefs(registry);
266   UpgradeDetector::RegisterPrefs(registry);
267 
268 #if defined(ENABLE_AUTOFILL_DIALOG)
269   autofill::AutofillDialogController::RegisterPrefs(registry);
270 #endif
271 
272 #if defined(ENABLE_CONFIGURATION_POLICY)
273   policy::BrowserPolicyConnector::RegisterPrefs(registry);
274   policy::PolicyStatisticsCollector::RegisterPrefs(registry);
275 #endif
276 
277 #if defined(ENABLE_EXTENSIONS)
278   EasyUnlockService::RegisterPrefs(registry);
279 #endif
280 
281 #if defined(ENABLE_NOTIFICATIONS) && !defined(OS_ANDROID)
282   // Android does not use the message center for notifications.
283   MessageCenterNotificationManager::RegisterPrefs(registry);
284 #endif
285 
286 #if defined(ENABLE_PLUGINS)
287   PluginFinder::RegisterPrefs(registry);
288 #endif
289 
290 #if defined(ENABLE_PLUGIN_INSTALLATION)
291   PluginsResourceService::RegisterPrefs(registry);
292 #endif
293 
294 #if defined(ENABLE_TASK_MANAGER)
295   TaskManager::RegisterPrefs(registry);
296 #endif  // defined(ENABLE_TASK_MANAGER)
297 
298 #if !defined(OS_ANDROID)
299   AutomaticProfileResetterFactory::RegisterPrefs(registry);
300   BackgroundModeManager::RegisterPrefs(registry);
301   RegisterBrowserPrefs(registry);
302   // The native GCM is used on Android instead.
303   gcm::GCMChannelStatusSyncer::RegisterPrefs(registry);
304 #if !defined(OS_CHROMEOS)
305   RegisterDefaultBrowserPromptPrefs(registry);
306 #endif  // !defined(OS_CHROMEOS)
307 #endif  // !defined(OS_ANDROID)
308 
309 #if defined(OS_CHROMEOS)
310   ChromeOSMetricsProvider::RegisterPrefs(registry);
311   chromeos::AudioDevicesPrefHandlerImpl::RegisterPrefs(registry);
312   chromeos::ChargerReplacementHandler::RegisterPrefs(registry);
313   chromeos::ChromeUserManagerImpl::RegisterPrefs(registry);
314   chromeos::DataPromoNotification::RegisterPrefs(registry);
315   chromeos::DeviceOAuth2TokenService::RegisterPrefs(registry);
316   chromeos::device_settings_cache::RegisterPrefs(registry);
317   chromeos::default_pinned_apps_field_trial::RegisterPrefs(registry);
318   chromeos::language_prefs::RegisterPrefs(registry);
319   chromeos::KioskAppManager::RegisterPrefs(registry);
320   chromeos::MultiProfileUserController::RegisterPrefs(registry);
321   chromeos::HIDDetectionScreenHandler::RegisterPrefs(registry);
322   chromeos::DemoModeDetector::RegisterPrefs(registry);
323   chromeos::Preferences::RegisterPrefs(registry);
324   chromeos::proxy_config::RegisterPrefs(registry);
325   chromeos::RegisterDisplayLocalStatePrefs(registry);
326   chromeos::ResetScreenHandler::RegisterPrefs(registry);
327   chromeos::ServicesCustomizationDocument::RegisterPrefs(registry);
328   chromeos::SigninScreenHandler::RegisterPrefs(registry);
329   chromeos::StartupUtils::RegisterPrefs(registry);
330   chromeos::system::AutomaticRebootManager::RegisterPrefs(registry);
331   chromeos::UserImageManager::RegisterPrefs(registry);
332   chromeos::UserSessionManager::RegisterPrefs(registry);
333   chromeos::WallpaperManager::RegisterPrefs(registry);
334   chromeos::echo_offer::RegisterPrefs(registry);
335   extensions::ExtensionAssetsManagerChromeOS::RegisterPrefs(registry);
336   invalidation::InvalidatorStorage::RegisterPrefs(registry);
337   policy::AutoEnrollmentClient::RegisterPrefs(registry);
338   policy::BrowserPolicyConnectorChromeOS::RegisterPrefs(registry);
339   policy::ConsumerManagementService::RegisterPrefs(registry);
340   policy::DeviceCloudPolicyManagerChromeOS::RegisterPrefs(registry);
341   policy::DeviceStatusCollector::RegisterPrefs(registry);
342   policy::PolicyCertServiceFactory::RegisterPrefs(registry);
343 #endif
344 
345 #if defined(OS_MACOSX)
346   confirm_quit::RegisterLocalState(registry);
347   QuitWithAppsController::RegisterPrefs(registry);
348 #endif
349 
350 #if defined(OS_WIN)
351   app_metro_launch::RegisterPrefs(registry);
352   component_updater::RegisterPrefsForSwReporter(registry);
353   password_manager::PasswordManager::RegisterLocalPrefs(registry);
354 #endif
355 
356 #if defined(TOOLKIT_VIEWS)
357   RegisterBrowserViewLocalPrefs(registry);
358 #endif
359 
360   // Preferences registered only for migration (clearing or moving to a new key)
361   // go here.
362 #if !defined(OS_ANDROID)
363   registry->RegisterDictionaryPref(kLegacyProfileResetPromptMemento);
364 #endif  // !defined(OS_ANDROID)
365 }
366 
367 // Register prefs applicable to all profiles.
RegisterProfilePrefs(user_prefs::PrefRegistrySyncable * registry)368 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
369   TRACE_EVENT0("browser", "chrome::RegisterUserPrefs");
370   // User prefs. Please keep this list alphabetized.
371   autofill::AutofillManager::RegisterProfilePrefs(registry);
372   bookmarks::RegisterProfilePrefs(registry);
373   sync_driver::SyncPrefs::RegisterProfilePrefs(registry);
374   ChromeContentBrowserClient::RegisterProfilePrefs(registry);
375   ChromeVersionService::RegisterProfilePrefs(registry);
376   chrome_browser_net::HttpServerPropertiesManagerFactory::RegisterProfilePrefs(
377       registry);
378   chrome_browser_net::Predictor::RegisterProfilePrefs(registry);
379   chrome_browser_net::RegisterPredictionOptionsProfilePrefs(registry);
380   chrome_prefs::RegisterProfilePrefs(registry);
381   dom_distiller::DistilledPagePrefs::RegisterProfilePrefs(registry);
382   DownloadPrefs::RegisterProfilePrefs(registry);
383   gcm::GCMProfileService::RegisterProfilePrefs(registry);
384   HostContentSettingsMap::RegisterProfilePrefs(registry);
385   IncognitoModePrefs::RegisterProfilePrefs(registry);
386   InstantUI::RegisterProfilePrefs(registry);
387   NavigationCorrectionTabObserver::RegisterProfilePrefs(registry);
388   MediaCaptureDevicesDispatcher::RegisterProfilePrefs(registry);
389   MediaDeviceIDSalt::RegisterProfilePrefs(registry);
390   MediaStreamDevicesController::RegisterProfilePrefs(registry);
391   NetPrefObserver::RegisterProfilePrefs(registry);
392   password_manager::PasswordManager::RegisterProfilePrefs(registry);
393   PrefProxyConfigTrackerImpl::RegisterProfilePrefs(registry);
394   PrefsTabHelper::RegisterProfilePrefs(registry);
395   Profile::RegisterProfilePrefs(registry);
396   ProfileImpl::RegisterProfilePrefs(registry);
397   PromoResourceService::RegisterProfilePrefs(registry);
398   ProtocolHandlerRegistry::RegisterProfilePrefs(registry);
399   RegisterBrowserUserPrefs(registry);
400   SessionStartupPref::RegisterProfilePrefs(registry);
401   TemplateURLPrepopulateData::RegisterProfilePrefs(registry);
402   translate::TranslatePrefs::RegisterProfilePrefs(registry);
403   ZeroSuggestProvider::RegisterProfilePrefs(registry);
404 
405 #if defined(ENABLE_AUTOFILL_DIALOG)
406   autofill::AutofillDialogController::RegisterProfilePrefs(registry);
407 #endif
408 
409 #if defined(ENABLE_CONFIGURATION_POLICY)
410   policy::URLBlacklistManager::RegisterProfilePrefs(registry);
411 #endif
412 
413 #if defined(ENABLE_EXTENSIONS)
414   EasyUnlockService::RegisterProfilePrefs(registry);
415   extensions::ActivityLog::RegisterProfilePrefs(registry);
416   extensions::launch_util::RegisterProfilePrefs(registry);
417   ExtensionWebUI::RegisterProfilePrefs(registry);
418   extensions::ExtensionPrefs::RegisterProfilePrefs(registry);
419 #endif
420 
421 #if defined(ENABLE_FULL_PRINTING)
422   print_dialog_cloud::RegisterProfilePrefs(registry);
423   printing::StickySettings::RegisterProfilePrefs(registry);
424 #endif
425 
426 #if defined(ENABLE_MANAGED_USERS)
427   SupervisedUserService::RegisterProfilePrefs(registry);
428   SupervisedUserSharedSettingsService::RegisterProfilePrefs(registry);
429   SupervisedUserSyncService::RegisterProfilePrefs(registry);
430 #endif
431 
432 #if defined(ENABLE_NOTIFICATIONS)
433   DesktopNotificationService::RegisterProfilePrefs(registry);
434 #endif
435 
436 #if defined(ENABLE_NOTIFICATIONS) && defined(ENABLE_EXTENSIONS) && \
437     !defined(OS_ANDROID)
438   // The extension welcome notification requires a build that enables extensions
439   // and notifications, and uses the UI message center.
440   ExtensionWelcomeNotification::RegisterProfilePrefs(registry);
441 #endif
442 
443 #if defined(ENABLE_SERVICE_DISCOVERY)
444   LocalDiscoveryUI::RegisterProfilePrefs(registry);
445 #endif
446 
447 #if defined(OS_ANDROID)
448   chrome_variations::VariationsService::RegisterProfilePrefs(registry);
449   NewTabPagePrefs::RegisterProfilePrefs(registry);
450   PartnerBookmarksShim::RegisterProfilePrefs(registry);
451 #else
452   AppShortcutManager::RegisterProfilePrefs(registry);
453   autofill::GeneratedCreditCardBubbleController::RegisterUserPrefs(registry);
454   DeviceIDFetcher::RegisterProfilePrefs(registry);
455   DevToolsWindow::RegisterProfilePrefs(registry);
456   DriveAppMapping::RegisterProfilePrefs(registry);
457   extensions::CommandService::RegisterProfilePrefs(registry);
458   extensions::ExtensionSettingsHandler::RegisterProfilePrefs(registry);
459 #if !defined(USE_ATHENA)
460   extensions::TabsCaptureVisibleTabFunction::RegisterProfilePrefs(registry);
461 #endif
462   first_run::RegisterProfilePrefs(registry);
463   gcm::GCMChannelStatusSyncer::RegisterProfilePrefs(registry);
464   NewTabUI::RegisterProfilePrefs(registry);
465   PepperFlashSettingsManager::RegisterProfilePrefs(registry);
466   PinnedTabCodec::RegisterProfilePrefs(registry);
467   PluginsUI::RegisterProfilePrefs(registry);
468   RegisterAutolaunchUserPrefs(registry);
469   signin::RegisterProfilePrefs(registry);
470 #endif
471 
472 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
473   default_apps::RegisterProfilePrefs(registry);
474 #endif
475 
476 #if defined(OS_CHROMEOS)
477   chromeos::attestation::PlatformVerificationFlow::RegisterProfilePrefs(
478       registry);
479   chromeos::first_run::RegisterProfilePrefs(registry);
480   chromeos::file_system_provider::RegisterProfilePrefs(registry);
481   chromeos::MultiProfileUserController::RegisterProfilePrefs(registry);
482   chromeos::Preferences::RegisterProfilePrefs(registry);
483   chromeos::proxy_config::RegisterProfilePrefs(registry);
484   chromeos::SAMLOfflineSigninLimiter::RegisterProfilePrefs(registry);
485   chromeos::ServicesCustomizationDocument::RegisterProfilePrefs(registry);
486   chromeos::UserImageSyncObserver::RegisterProfilePrefs(registry);
487   extensions::EnterprisePlatformKeysPrivateChallengeUserKeyFunction::
488       RegisterProfilePrefs(registry);
489   FlagsUI::RegisterProfilePrefs(registry);
490 #endif
491 
492 #if defined(OS_WIN)
493   component_updater::RegisterProfilePrefsForSwReporter(registry);
494   NetworkProfileBubble::RegisterProfilePrefs(registry);
495 #endif
496 
497 #if defined(TOOLKIT_VIEWS)
498   RegisterBrowserViewProfilePrefs(registry);
499   RegisterInvertBubbleUserPrefs(registry);
500 #endif
501 
502 #if defined(USE_ASH)
503   ash::RegisterChromeLauncherUserPrefs(registry);
504 #endif
505 
506   // Preferences registered only for migration (clearing or moving to a new key)
507   // go here.
508   registry->RegisterDictionaryPref(
509       kBackupPref,
510       new base::DictionaryValue(),
511       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
512 #if !defined(OS_ANDROID)
513   registry->RegisterStringPref(
514       kSyncPromoErrorMessage,
515       std::string(),
516       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
517 #endif
518 }
519 
RegisterUserProfilePrefs(user_prefs::PrefRegistrySyncable * registry)520 void RegisterUserProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
521   RegisterProfilePrefs(registry);
522 
523 #if defined(OS_CHROMEOS)
524   chromeos::PowerPrefs::RegisterUserProfilePrefs(registry);
525 #endif
526 }
527 
RegisterScreenshotPrefs(PrefRegistrySimple * registry)528 void RegisterScreenshotPrefs(PrefRegistrySimple* registry) {
529   registry->RegisterBooleanPref(prefs::kDisableScreenshots, false);
530 }
531 
532 #if defined(OS_CHROMEOS)
RegisterLoginProfilePrefs(user_prefs::PrefRegistrySyncable * registry)533 void RegisterLoginProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
534   RegisterProfilePrefs(registry);
535 
536   chromeos::PowerPrefs::RegisterLoginProfilePrefs(registry);
537 }
538 #endif
539 
MigrateUserPrefs(Profile * profile)540 void MigrateUserPrefs(Profile* profile) {
541   PrefService* prefs = profile->GetPrefs();
542 
543   // Cleanup prefs from now-removed protector feature.
544   prefs->ClearPref(kBackupPref);
545 
546 #if !defined(OS_ANDROID)
547   // Cleanup now-removed sync promo error message preference.
548   // TODO(fdoray): Remove this when it's safe to do so (crbug.com/268442).
549   prefs->ClearPref(kSyncPromoErrorMessage);
550   // Migrate kNetworkPredictionEnabled to kNetworkPredictionOptions when not on
551   // Android.  On Android, platform-specific code performs preference migration.
552   // TODO(bnc): https://crbug.com/401970  Remove migration code one year after
553   // M38.
554   chrome_browser_net::MigrateNetworkPredictionUserPrefs(prefs);
555 #endif
556 
557   PromoResourceService::MigrateUserPrefs(prefs);
558   translate::TranslatePrefs::MigrateUserPrefs(prefs, prefs::kAcceptLanguages);
559 
560 #if defined(OS_MACOSX) && !defined(OS_IOS)
561   autofill::AutofillManager::MigrateUserPrefs(prefs);
562 #endif  // defined(OS_MACOSX) && !defined(OS_IOS)
563 }
564 
MigrateBrowserPrefs(Profile * profile,PrefService * local_state)565 void MigrateBrowserPrefs(Profile* profile, PrefService* local_state) {
566   // Copy pref values which have been migrated to user_prefs from local_state,
567   // or remove them from local_state outright, if copying is not required.
568   int current_version =
569       local_state->GetInteger(prefs::kMultipleProfilePrefMigration);
570   PrefRegistrySimple* registry = static_cast<PrefRegistrySimple*>(
571       local_state->DeprecatedGetPrefRegistry());
572 
573   if (!(current_version & DNS_PREFS)) {
574     registry->RegisterListPref(prefs::kDnsStartupPrefetchList);
575     local_state->ClearPref(prefs::kDnsStartupPrefetchList);
576 
577     registry->RegisterListPref(prefs::kDnsHostReferralList);
578     local_state->ClearPref(prefs::kDnsHostReferralList);
579 
580     current_version |= DNS_PREFS;
581     local_state->SetInteger(prefs::kMultipleProfilePrefMigration,
582                             current_version);
583   }
584 
585   PrefService* user_prefs = profile->GetPrefs();
586   if (!(current_version & WINDOWS_PREFS)) {
587     registry->RegisterDictionaryPref(prefs::kBrowserWindowPlacement);
588     if (local_state->HasPrefPath(prefs::kBrowserWindowPlacement)) {
589       const PrefService::Preference* pref =
590           local_state->FindPreference(prefs::kBrowserWindowPlacement);
591       DCHECK(pref);
592       user_prefs->Set(prefs::kBrowserWindowPlacement,
593                       *(pref->GetValue()));
594     }
595     local_state->ClearPref(prefs::kBrowserWindowPlacement);
596 
597     current_version |= WINDOWS_PREFS;
598     local_state->SetInteger(prefs::kMultipleProfilePrefMigration,
599                             current_version);
600   }
601 
602   if (!(current_version & GOOGLE_URL_TRACKER_PREFS)) {
603     registry->RegisterStringPref(prefs::kLastKnownGoogleURL,
604                                  GoogleURLTracker::kDefaultGoogleHomepage);
605     if (local_state->HasPrefPath(prefs::kLastKnownGoogleURL)) {
606       user_prefs->SetString(prefs::kLastKnownGoogleURL,
607                             local_state->GetString(prefs::kLastKnownGoogleURL));
608     }
609     local_state->ClearPref(prefs::kLastKnownGoogleURL);
610 
611     registry->RegisterStringPref(prefs::kLastPromptedGoogleURL,
612                                  std::string());
613     if (local_state->HasPrefPath(prefs::kLastPromptedGoogleURL)) {
614       user_prefs->SetString(
615           prefs::kLastPromptedGoogleURL,
616           local_state->GetString(prefs::kLastPromptedGoogleURL));
617     }
618     local_state->ClearPref(prefs::kLastPromptedGoogleURL);
619 
620     current_version |= GOOGLE_URL_TRACKER_PREFS;
621     local_state->SetInteger(prefs::kMultipleProfilePrefMigration,
622                             current_version);
623   }
624 
625 #if !defined(OS_ANDROID)
626   local_state->ClearPref(kLegacyProfileResetPromptMemento);
627 #endif
628 
629 #if defined(OS_CHROMEOS)
630   chromeos::default_pinned_apps_field_trial::MigratePrefs(local_state);
631 #endif
632 
633 #if defined(TOOLKIT_VIEWS)
634   MigrateBrowserTabStripPrefs(local_state);
635 #endif
636 }
637 
638 }  // namespace chrome
639