Home | History | Annotate | Download | only in options
      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/ui/options/options_util.h"
      6 
      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/notifications/desktop_notification_service_factory.h"
     16 #include "chrome/browser/prefs/pref_service.h"
     17 #include "chrome/browser/profiles/profile.h"
     18 #include "chrome/common/pref_names.h"
     19 #include "chrome/installer/util/google_update_settings.h"
     20 #include "content/browser/host_zoom_map.h"
     21 
     22 // static
     23 void OptionsUtil::ResetToDefaults(Profile* profile) {
     24   // TODO(tc): It would be nice if we could generate this list automatically so
     25   // changes to any of the options pages doesn't require updating this list
     26   // manually.
     27   PrefService* prefs = profile->GetPrefs();
     28   const char* kUserPrefs[] = {
     29     prefs::kAcceptLanguages,
     30     prefs::kAlternateErrorPagesEnabled,
     31     prefs::kClearSiteDataOnExit,
     32     prefs::kCookieBehavior,
     33     prefs::kDefaultCharset,
     34     prefs::kDefaultZoomLevel,
     35     prefs::kDeleteBrowsingHistory,
     36     prefs::kDeleteCache,
     37     prefs::kDeleteCookies,
     38     prefs::kDeleteDownloadHistory,
     39     prefs::kDeleteFormData,
     40     prefs::kDeletePasswords,
     41     prefs::kNetworkPredictionEnabled,
     42     // TODO(rtenneti): Remove ssl preferences from user_prefs when we stop
     43     // migrating user_prefs to local_state after 6 months (after we delete
     44     // migration code).
     45     prefs::kCertRevocationCheckingEnabled,
     46     prefs::kSSL3Enabled,
     47     prefs::kTLS1Enabled,
     48 #if defined(OS_CHROMEOS)
     49     prefs::kTapToClickEnabled,
     50     prefs::kTouchpadSensitivity,
     51 #endif
     52     prefs::kDownloadDefaultDirectory,
     53     prefs::kDownloadExtensionsToOpen,
     54     prefs::kSavingBrowserHistoryDisabled,
     55     prefs::kEnableSpellCheck,
     56     prefs::kEnableTranslate,
     57     prefs::kAutofillEnabled,
     58     prefs::kAutofillAuxiliaryProfilesEnabled,
     59     prefs::kHomePage,
     60     prefs::kHomePageIsNewTabPage,
     61     prefs::kPromptForDownload,
     62     prefs::kPasswordManagerEnabled,
     63     prefs::kRestoreOnStartup,
     64     prefs::kSafeBrowsingEnabled,
     65     prefs::kSafeBrowsingReportingEnabled,
     66     prefs::kSearchSuggestEnabled,
     67     prefs::kShowHomeButton,
     68     prefs::kSpellCheckDictionary,
     69     prefs::kURLsToRestoreOnStartup,
     70     prefs::kWebKitDefaultFixedFontSize,
     71     prefs::kWebKitDefaultFontSize,
     72     prefs::kWebKitFixedFontFamily,
     73     prefs::kWebKitJavaEnabled,
     74     prefs::kWebKitJavascriptEnabled,
     75     prefs::kWebKitLoadsImagesAutomatically,
     76     prefs::kWebKitPluginsEnabled,
     77     prefs::kWebKitSansSerifFontFamily,
     78     prefs::kWebKitSerifFontFamily,
     79     prefs::kWebKitMinimumFontSize,
     80     prefs::kWebKitMinimumLogicalFontSize,
     81     prefs::kWebkitTabsToLinks,
     82   };
     83   profile->GetDownloadManager()->download_prefs()->ResetToDefaults();
     84   profile->GetHostContentSettingsMap()->ResetToDefaults();
     85   profile->GetGeolocationContentSettingsMap()->ResetToDefault();
     86   profile->GetHostZoomMap()->ResetToDefaults();
     87   DesktopNotificationServiceFactory::GetForProfile(profile)->
     88       ResetToDefaultContentSetting();
     89   for (size_t i = 0; i < arraysize(kUserPrefs); ++i)
     90     prefs->ClearPref(kUserPrefs[i]);
     91 
     92   PrefService* local_state = g_browser_process->local_state();
     93   // Note that we don't reset the kMetricsReportingEnabled preference here
     94   // because the reset will reset it to the default setting specified in Chrome
     95   // source, not the default setting selected by the user on the web page where
     96   // they downloaded Chrome. This means that if the user ever resets their
     97   // settings they'll either inadvertedly enable this logging or disable it.
     98   // One is undesirable for them, one is undesirable for us. For now, we just
     99   // don't reset it.
    100   const char* kLocalStatePrefs[] = {
    101     prefs::kApplicationLocale,
    102     prefs::kCertRevocationCheckingEnabled,
    103     prefs::kSSL3Enabled,
    104     prefs::kTLS1Enabled,
    105   };
    106   for (size_t i = 0; i < arraysize(kLocalStatePrefs); ++i)
    107     local_state->ClearPref(kLocalStatePrefs[i]);
    108 }
    109 
    110 // static
    111 bool OptionsUtil::ResolveMetricsReportingEnabled(bool enabled) {
    112   // GoogleUpdateSettings touches the disk from the UI thread. MetricsService
    113   // also calls GoogleUpdateSettings below. http://crbug/62626
    114   base::ThreadRestrictions::ScopedAllowIO allow_io;
    115 
    116   GoogleUpdateSettings::SetCollectStatsConsent(enabled);
    117   bool update_pref = GoogleUpdateSettings::GetCollectStatsConsent();
    118 
    119   if (enabled != update_pref) {
    120     DVLOG(1) << "OptionsUtil: Unable to set crash report status to " << enabled;
    121   }
    122 
    123   // Only change the pref if GoogleUpdateSettings::GetCollectStatsConsent
    124   // succeeds.
    125   enabled = update_pref;
    126 
    127   MetricsService* metrics = g_browser_process->metrics_service();
    128   DCHECK(metrics);
    129   if (metrics) {
    130     if (enabled)
    131       metrics->Start();
    132     else
    133       metrics->Stop();
    134   }
    135 
    136   return enabled;
    137 }
    138