Home | History | Annotate | Download | only in prefs
      1 // Copyright (c) 2011 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 "chrome/browser/about_flags.h"
      8 #include "chrome/browser/autofill/autofill_manager.h"
      9 #include "chrome/browser/background_contents_service.h"
     10 #include "chrome/browser/background_mode_manager.h"
     11 #include "chrome/browser/background_page_tracker.h"
     12 #include "chrome/browser/bookmarks/bookmark_utils.h"
     13 #include "chrome/browser/browser_shutdown.h"
     14 #include "chrome/browser/content_settings/host_content_settings_map.h"
     15 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
     16 #include "chrome/browser/debugger/devtools_manager.h"
     17 #include "chrome/browser/download/download_prefs.h"
     18 #include "chrome/browser/extensions/apps_promo.h"
     19 #include "chrome/browser/extensions/extension_prefs.h"
     20 #include "chrome/browser/extensions/extension_web_ui.h"
     21 #include "chrome/browser/extensions/extensions_ui.h"
     22 #include "chrome/browser/external_protocol_handler.h"
     23 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
     24 #include "chrome/browser/geolocation/geolocation_prefs.h"
     25 #include "chrome/browser/google/google_url_tracker.h"
     26 #include "chrome/browser/instant/instant_controller.h"
     27 #include "chrome/browser/intranet_redirect_detector.h"
     28 #include "chrome/browser/metrics/metrics_log.h"
     29 #include "chrome/browser/metrics/metrics_service.h"
     30 #include "chrome/browser/net/net_pref_observer.h"
     31 #include "chrome/browser/net/predictor_api.h"
     32 #include "chrome/browser/net/pref_proxy_config_service.h"
     33 #include "chrome/browser/notifications/desktop_notification_service.h"
     34 #include "chrome/browser/notifications/notification_ui_manager.h"
     35 #include "chrome/browser/page_info_model.h"
     36 #include "chrome/browser/password_manager/password_manager.h"
     37 #include "chrome/browser/policy/cloud_policy_subsystem.h"
     38 #include "chrome/browser/prefs/session_startup_pref.h"
     39 #include "chrome/browser/profiles/profile_impl.h"
     40 #include "chrome/browser/renderer_host/web_cache_manager.h"
     41 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
     42 #include "chrome/browser/search_engines/template_url_model.h"
     43 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
     44 #include "chrome/browser/ssl/ssl_manager.h"
     45 #include "chrome/browser/sync/signin_manager.h"
     46 #include "chrome/browser/tabs/pinned_tab_codec.h"
     47 #include "chrome/browser/task_manager/task_manager.h"
     48 #include "chrome/browser/translate/translate_prefs.h"
     49 #include "chrome/browser/ui/browser.h"
     50 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h"
     51 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
     52 #include "chrome/browser/ui/webui/flags_ui.h"
     53 #include "chrome/browser/ui/webui/new_tab_ui.h"
     54 #include "chrome/browser/ui/webui/plugins_ui.h"
     55 #include "chrome/browser/upgrade_detector.h"
     56 #include "chrome/browser/web_resource/promo_resource_service.h"
     57 #include "chrome/common/pref_names.h"
     58 #include "content/browser/host_zoom_map.h"
     59 #include "content/browser/renderer_host/browser_render_process_host.h"
     60 
     61 #if defined(TOOLKIT_VIEWS)  // TODO(port): whittle this down as we port
     62 #include "chrome/browser/ui/views/browser_actions_container.h"
     63 #include "chrome/browser/ui/views/frame/browser_view.h"
     64 #endif
     65 
     66 #if defined(TOOLKIT_GTK)
     67 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
     68 #endif
     69 
     70 #if defined(OS_CHROMEOS)
     71 #include "chrome/browser/chromeos/audio_mixer_alsa.h"
     72 #include "chrome/browser/chromeos/customization_document.h"
     73 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h"
     74 #include "chrome/browser/chromeos/login/user_manager.h"
     75 #include "chrome/browser/chromeos/login/wizard_controller.h"
     76 #include "chrome/browser/chromeos/preferences.h"
     77 #include "chrome/browser/chromeos/status/input_method_menu.h"
     78 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
     79 #endif
     80 
     81 namespace browser {
     82 
     83 void RegisterLocalState(PrefService* local_state) {
     84   // Prefs in Local State
     85   AppsPromo::RegisterPrefs(local_state);
     86   Browser::RegisterPrefs(local_state);
     87   FlagsUI::RegisterPrefs(local_state);
     88   WebCacheManager::RegisterPrefs(local_state);
     89   ExternalProtocolHandler::RegisterPrefs(local_state);
     90   GoogleURLTracker::RegisterPrefs(local_state);
     91   IntranetRedirectDetector::RegisterPrefs(local_state);
     92   KeywordEditorController::RegisterPrefs(local_state);
     93   MetricsLog::RegisterPrefs(local_state);
     94   MetricsService::RegisterPrefs(local_state);
     95   PromoResourceService::RegisterPrefs(local_state);
     96   SafeBrowsingService::RegisterPrefs(local_state);
     97   browser_shutdown::RegisterPrefs(local_state);
     98 #if defined(TOOLKIT_VIEWS)
     99   BrowserView::RegisterBrowserViewPrefs(local_state);
    100 #endif
    101   UpgradeDetector::RegisterPrefs(local_state);
    102   TaskManager::RegisterPrefs(local_state);
    103   geolocation::RegisterPrefs(local_state);
    104   AutofillManager::RegisterBrowserPrefs(local_state);
    105   BackgroundModeManager::RegisterPrefs(local_state);
    106   BackgroundPageTracker::RegisterPrefs(local_state);
    107   NotificationUIManager::RegisterPrefs(local_state);
    108   PrefProxyConfigService::RegisterPrefs(local_state);
    109   policy::CloudPolicySubsystem::RegisterPrefs(local_state);
    110 #if defined(OS_CHROMEOS)
    111   chromeos::AudioMixerAlsa::RegisterPrefs(local_state);
    112   chromeos::UserManager::RegisterPrefs(local_state);
    113   chromeos::UserCrosSettingsProvider::RegisterPrefs(local_state);
    114   WizardController::RegisterPrefs(local_state);
    115   chromeos::InputMethodMenu::RegisterPrefs(local_state);
    116   chromeos::ServicesCustomizationDocument::RegisterPrefs(local_state);
    117   chromeos::SignedSettingsTempStorage::RegisterPrefs(local_state);
    118 #endif
    119 }
    120 
    121 void RegisterUserPrefs(PrefService* user_prefs) {
    122   // User prefs
    123   AppsPromo::RegisterUserPrefs(user_prefs);
    124   AutofillManager::RegisterUserPrefs(user_prefs);
    125   SessionStartupPref::RegisterUserPrefs(user_prefs);
    126   Browser::RegisterUserPrefs(user_prefs);
    127   PasswordManager::RegisterUserPrefs(user_prefs);
    128   chrome_browser_net::RegisterUserPrefs(user_prefs);
    129   DownloadPrefs::RegisterUserPrefs(user_prefs);
    130   bookmark_utils::RegisterUserPrefs(user_prefs);
    131   TabContentsWrapper::RegisterUserPrefs(user_prefs);
    132   TemplateURLPrepopulateData::RegisterUserPrefs(user_prefs);
    133   ExtensionWebUI::RegisterUserPrefs(user_prefs);
    134   ExtensionsUI::RegisterUserPrefs(user_prefs);
    135   NewTabUI::RegisterUserPrefs(user_prefs);
    136   PluginsUI::RegisterUserPrefs(user_prefs);
    137   ProfileImpl::RegisterUserPrefs(user_prefs);
    138   PromoResourceService::RegisterUserPrefs(user_prefs);
    139   HostContentSettingsMap::RegisterUserPrefs(user_prefs);
    140   HostZoomMap::RegisterUserPrefs(user_prefs);
    141   DevToolsManager::RegisterUserPrefs(user_prefs);
    142   PinnedTabCodec::RegisterUserPrefs(user_prefs);
    143   ExtensionPrefs::RegisterUserPrefs(user_prefs);
    144   GeolocationContentSettingsMap::RegisterUserPrefs(user_prefs);
    145   TranslatePrefs::RegisterUserPrefs(user_prefs);
    146   DesktopNotificationService::RegisterUserPrefs(user_prefs);
    147   PrefProxyConfigService::RegisterPrefs(user_prefs);
    148 #if defined(TOOLKIT_VIEWS)
    149   BrowserActionsContainer::RegisterUserPrefs(user_prefs);
    150 #elif defined(TOOLKIT_GTK)
    151   BrowserWindowGtk::RegisterUserPrefs(user_prefs);
    152 #endif
    153 #if defined(OS_CHROMEOS)
    154   chromeos::Preferences::RegisterUserPrefs(user_prefs);
    155 #endif
    156   BackgroundContentsService::RegisterUserPrefs(user_prefs);
    157   SigninManager::RegisterUserPrefs(user_prefs);
    158   TemplateURLModel::RegisterUserPrefs(user_prefs);
    159   InstantController::RegisterUserPrefs(user_prefs);
    160   NetPrefObserver::RegisterPrefs(user_prefs);
    161   policy::CloudPolicySubsystem::RegisterPrefs(user_prefs);
    162   ProtocolHandlerRegistry::RegisterPrefs(user_prefs);
    163 }
    164 
    165 void MigrateBrowserPrefs(PrefService* user_prefs, PrefService* local_state) {
    166   // Copy pref values which have been migrated to user_prefs from local_state,
    167   // or remove them from local_state outright, if copying is not required.
    168   int current_version =
    169       local_state->GetInteger(prefs::kMultipleProfilePrefMigration);
    170 
    171   if ((current_version & WINDOWS_PREFS) == 0) {
    172     // Migrate the devtools split location preference.
    173     local_state->RegisterIntegerPref(prefs::kDevToolsSplitLocation, -1);
    174     DCHECK(user_prefs->FindPreference(prefs::kDevToolsSplitLocation));
    175     if (local_state->HasPrefPath(prefs::kDevToolsSplitLocation)) {
    176       user_prefs->SetInteger(prefs::kDevToolsSplitLocation,
    177           local_state->GetInteger(prefs::kDevToolsSplitLocation));
    178     }
    179     local_state->ClearPref(prefs::kDevToolsSplitLocation);
    180 
    181     // Migrate the browser window placement preference.
    182     local_state->RegisterDictionaryPref(prefs::kBrowserWindowPlacement);
    183     DCHECK(user_prefs->FindPreference(prefs::kBrowserWindowPlacement));
    184     if (local_state->HasPrefPath(prefs::kBrowserWindowPlacement)) {
    185       const PrefService::Preference* pref =
    186           local_state->FindPreference(prefs::kBrowserWindowPlacement);
    187       DCHECK(pref);
    188       user_prefs->Set(prefs::kBrowserWindowPlacement, *(pref->GetValue()));
    189     }
    190     local_state->ClearPref(prefs::kBrowserWindowPlacement);
    191 
    192     local_state->SetInteger(prefs::kMultipleProfilePrefMigration,
    193                             current_version | WINDOWS_PREFS);
    194   }
    195 }
    196 
    197 }  // namespace browser
    198