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.
5 #include "chrome/browser/ui/options/options_util.h"
7 #include "base/threading/thread_restrictions.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/download/download_manager.h"
11 #include "chrome/browser/download/download_prefs.h"
12 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
13 #include "chrome/browser/metrics/metrics_service.h"
14 #include "chrome/browser/notifications/desktop_notification_service.h"
15 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/pref_names.h"
18 #include "chrome/installer/util/google_update_settings.h"
19 #include "content/browser/host_zoom_map.h"
22 void OptionsUtil::ResetToDefaults(Profile
* profile
) {
23 // TODO(tc): It would be nice if we could generate this list automatically so
24 // changes to any of the options pages doesn't require updating this list
26 PrefService
* prefs
= profile
->GetPrefs();
27 const char* kUserPrefs
[] = {
28 prefs::kAcceptLanguages
,
29 prefs::kAlternateErrorPagesEnabled
,
30 prefs::kClearSiteDataOnExit
,
31 prefs::kCookieBehavior
,
32 prefs::kDefaultCharset
,
33 prefs::kDefaultZoomLevel
,
34 prefs::kDeleteBrowsingHistory
,
36 prefs::kDeleteCookies
,
37 prefs::kDeleteDownloadHistory
,
38 prefs::kDeleteFormData
,
39 prefs::kDeletePasswords
,
40 prefs::kNetworkPredictionEnabled
,
41 // TODO(rtenneti): Remove ssl preferences from user_prefs when we stop
42 // migrating user_prefs to local_state after 6 months (after we delete
44 prefs::kCertRevocationCheckingEnabled
,
47 #if defined(OS_CHROMEOS)
48 prefs::kTapToClickEnabled
,
49 prefs::kTouchpadSensitivity
,
51 prefs::kDownloadDefaultDirectory
,
52 prefs::kDownloadExtensionsToOpen
,
53 prefs::kSavingBrowserHistoryDisabled
,
54 prefs::kEnableSpellCheck
,
55 prefs::kEnableTranslate
,
56 prefs::kAutofillEnabled
,
57 prefs::kAutofillAuxiliaryProfilesEnabled
,
59 prefs::kHomePageIsNewTabPage
,
60 prefs::kPromptForDownload
,
61 prefs::kPasswordManagerEnabled
,
62 prefs::kRestoreOnStartup
,
63 prefs::kSafeBrowsingEnabled
,
64 prefs::kSafeBrowsingReportingEnabled
,
65 prefs::kSearchSuggestEnabled
,
66 prefs::kShowHomeButton
,
67 prefs::kSpellCheckDictionary
,
68 prefs::kURLsToRestoreOnStartup
,
69 prefs::kWebKitDefaultFixedFontSize
,
70 prefs::kWebKitDefaultFontSize
,
71 prefs::kWebKitFixedFontFamily
,
72 prefs::kWebKitJavaEnabled
,
73 prefs::kWebKitJavascriptEnabled
,
74 prefs::kWebKitLoadsImagesAutomatically
,
75 prefs::kWebKitPluginsEnabled
,
76 prefs::kWebKitSansSerifFontFamily
,
77 prefs::kWebKitSerifFontFamily
,
78 prefs::kWebKitMinimumFontSize
,
79 prefs::kWebKitMinimumLogicalFontSize
,
80 prefs::kWebkitTabsToLinks
,
82 profile
->GetDownloadManager()->download_prefs()->ResetToDefaults();
83 profile
->GetHostContentSettingsMap()->ResetToDefaults();
84 profile
->GetGeolocationContentSettingsMap()->ResetToDefault();
85 profile
->GetHostZoomMap()->ResetToDefaults();
86 profile
->GetDesktopNotificationService()->ResetToDefaultContentSetting();
87 for (size_t i
= 0; i
< arraysize(kUserPrefs
); ++i
)
88 prefs
->ClearPref(kUserPrefs
[i
]);
90 PrefService
* local_state
= g_browser_process
->local_state();
91 // Note that we don't reset the kMetricsReportingEnabled preference here
92 // because the reset will reset it to the default setting specified in Chrome
93 // source, not the default setting selected by the user on the web page where
94 // they downloaded Chrome. This means that if the user ever resets their
95 // settings they'll either inadvertedly enable this logging or disable it.
96 // One is undesirable for them, one is undesirable for us. For now, we just
98 const char* kLocalStatePrefs
[] = {
99 prefs::kApplicationLocale
,
100 prefs::kCertRevocationCheckingEnabled
,
104 for (size_t i
= 0; i
< arraysize(kLocalStatePrefs
); ++i
)
105 local_state
->ClearPref(kLocalStatePrefs
[i
]);
109 bool OptionsUtil::ResolveMetricsReportingEnabled(bool enabled
) {
110 // GoogleUpdateSettings touches the disk from the UI thread. MetricsService
111 // also calls GoogleUpdateSettings below. http://crbug/62626
112 base::ThreadRestrictions::ScopedAllowIO allow_io
;
114 GoogleUpdateSettings::SetCollectStatsConsent(enabled
);
115 bool update_pref
= GoogleUpdateSettings::GetCollectStatsConsent();
117 if (enabled
!= update_pref
) {
118 DVLOG(1) << "OptionsUtil: Unable to set crash report status to " << enabled
;
121 // Only change the pref if GoogleUpdateSettings::GetCollectStatsConsent
123 enabled
= update_pref
;
125 MetricsService
* metrics
= g_browser_process
->metrics_service();
128 metrics
->SetUserPermitsUpload(enabled
);