1 // Copyright 2015 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 "ios/chrome/browser/prefs/browser_prefs.h"
7 #include "base/prefs/pref_service.h"
8 #include "components/autofill/core/browser/autofill_manager.h"
9 #include "components/content_settings/core/browser/host_content_settings_map.h"
10 #include "components/dom_distiller/core/distilled_page_prefs.h"
11 #include "components/enhanced_bookmarks/bookmark_server_cluster_service.h"
12 #include "components/gcm_driver/gcm_channel_status_syncer.h"
13 #include "components/network_time/network_time_tracker.h"
14 #include "components/omnibox/browser/zero_suggest_provider.h"
15 #include "components/password_manager/core/browser/password_manager.h"
16 #include "components/pref_registry/pref_registry_syncable.h"
17 #include "components/proxy_config/pref_proxy_config_tracker_impl.h"
18 #include "components/rappor/rappor_service.h"
19 #include "components/search_engines/template_url_prepopulate_data.h"
20 #include "components/sync_driver/sync_prefs.h"
21 #include "components/translate/core/browser/translate_prefs.h"
22 #include "components/translate/core/common/translate_pref_names.h"
23 #include "components/variations/service/variations_service.h"
24 #include "components/web_resource/promo_resource_service.h"
25 #include "ios/chrome/browser/first_run/first_run.h"
26 #include "ios/chrome/browser/net/http_server_properties_manager_factory.h"
27 #include "ios/chrome/browser/pref_names.h"
28 #include "ios/chrome/browser/signin/signin_manager_factory.h"
29 #include "ios/chrome/grit/ios_locale_settings.h"
30 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
31 #include "ui/base/l10n/l10n_util.h"
33 #if defined(ENABLE_CONFIGURATION_POLICY)
34 #include "components/policy/core/browser/browser_policy_connector.h"
35 #include "components/policy/core/browser/url_blacklist_manager.h"
36 #include "components/policy/core/common/policy_statistics_collector.h"
37 #endif // defined(ENABLE_CONFIGURATION_POLICY)
41 // TODO(sdefresne): those preferences are not used on iOS but are required to
42 // be able to run unit_tests until componentization of chrome/browser/prefs is
43 // complete. Remove once http://crbug.com/525079 is fixed.
44 const char kURLsToRestoreOnStartup
[] = "session.startup_urls";
45 const char kURLsToRestoreOnStartupOld
[] = "session.urls_to_restore_on_startup";
49 void RegisterLocalStatePrefs(PrefRegistrySimple
* registry
) {
50 gcm::GCMChannelStatusSyncer::RegisterPrefs(registry
);
51 ios::SigninManagerFactory::RegisterPrefs(registry
);
52 network_time::NetworkTimeTracker::RegisterPrefs(registry
);
53 PrefProxyConfigTrackerImpl::RegisterPrefs(registry
);
54 rappor::RapporService::RegisterPrefs(registry
);
55 variations::VariationsService::RegisterPrefs(registry
);
56 web_resource::PromoResourceService::RegisterPrefs(registry
);
58 #if defined(ENABLE_CONFIGURATION_POLICY)
59 policy::BrowserPolicyConnector::RegisterPrefs(registry
);
60 policy::PolicyStatisticsCollector::RegisterPrefs(registry
);
63 // Preferences related to the browser state manager.
64 registry
->RegisterStringPref(ios::prefs::kBrowserStateLastUsed
,
66 registry
->RegisterIntegerPref(ios::prefs::kBrowserStatesNumCreated
, 1);
67 registry
->RegisterListPref(ios::prefs::kBrowserStatesLastActive
);
69 ios::GetChromeBrowserProvider()->RegisterLocalState(registry
);
72 void RegisterBrowserStatePrefs(user_prefs::PrefRegistrySyncable
* registry
) {
73 autofill::AutofillManager::RegisterProfilePrefs(registry
);
74 dom_distiller::DistilledPagePrefs::RegisterProfilePrefs(registry
);
75 enhanced_bookmarks::BookmarkServerClusterService::RegisterPrefs(registry
);
76 FirstRun::RegisterProfilePrefs(registry
);
77 gcm::GCMChannelStatusSyncer::RegisterProfilePrefs(registry
);
78 HostContentSettingsMap::RegisterProfilePrefs(registry
);
79 HttpServerPropertiesManagerFactory::RegisterProfilePrefs(registry
);
80 password_manager::PasswordManager::RegisterProfilePrefs(registry
);
81 PrefProxyConfigTrackerImpl::RegisterProfilePrefs(registry
);
82 sync_driver::SyncPrefs::RegisterProfilePrefs(registry
);
83 TemplateURLPrepopulateData::RegisterProfilePrefs(registry
);
84 translate::TranslatePrefs::RegisterProfilePrefs(registry
);
85 variations::VariationsService::RegisterProfilePrefs(registry
);
86 web_resource::PromoResourceService::RegisterProfilePrefs(registry
);
87 ZeroSuggestProvider::RegisterProfilePrefs(registry
);
89 #if defined(ENABLE_CONFIGURATION_POLICY)
90 policy::URLBlacklistManager::RegisterProfilePrefs(registry
);
93 registry
->RegisterBooleanPref(
94 ios::prefs::kEnableDoNotTrack
, false,
95 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
96 registry
->RegisterBooleanPref(
97 prefs::kEnableTranslate
, true,
98 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
99 registry
->RegisterStringPref(
100 ios::prefs::kAcceptLanguages
,
101 l10n_util::GetStringUTF8(IDS_IOS_ACCEPT_LANGUAGES
));
102 registry
->RegisterStringPref(
103 ios::prefs::kDefaultCharset
,
104 l10n_util::GetStringUTF8(IDS_IOS_DEFAULT_ENCODING
),
105 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
107 // TODO(sdefresne): those preferences are not used on iOS but are required to
108 // be able to run unit_tests until componentization of chrome/browser/prefs
109 // is complete. Remove once http://crbug.com/525079 is fixed.
110 registry
->RegisterListPref(kURLsToRestoreOnStartup
,
111 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
112 registry
->RegisterListPref(kURLsToRestoreOnStartupOld
);
114 ios::GetChromeBrowserProvider()->RegisterProfilePrefs(registry
);
117 // This method should be periodically pruned of year+ old migrations.
118 void MigrateObsoleteLocalStatePrefs(PrefService
* prefs
) {}
120 // This method should be periodically pruned of year+ old migrations.
121 void MigrateObsoleteBrowserStatePrefs(PrefService
* prefs
) {
123 translate::TranslatePrefs::MigrateUserPrefs(prefs
,
124 ios::prefs::kAcceptLanguages
);
127 prefs
->ClearPref(::prefs::kSigninSharedAuthenticationUserId
);