blob: 6ef97ebf3ba6c77b8e5594446ab69d025217cfcf [file] [log] [blame]
[email protected]487ba1462012-01-05 03:13:091// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]fecc1522009-10-15 21:08:292// 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/chromeos/preferences.h"
6
[email protected]20d2a79d2012-03-16 23:01:027#include "base/chromeos/chromeos_version.h"
[email protected]775caec2011-09-01 17:14:328#include "base/command_line.h"
[email protected]530cd622011-04-14 15:45:009#include "base/i18n/time_formatting.h"
[email protected]d7ca1ba2011-05-09 20:09:0810#include "base/metrics/histogram.h"
[email protected]0abb67122012-12-12 11:36:0511#include "base/prefs/public/pref_member.h"
[email protected]4e5ae20f2010-09-24 04:52:1112#include "base/string_split.h"
[email protected]de1528d1a2012-05-14 10:36:1513#include "base/string_util.h"
[email protected]50951432010-03-31 12:12:4214#include "base/utf_string_conversions.h"
[email protected]c0a2128d92011-07-20 15:04:4615#include "chrome/browser/browser_process.h"
[email protected]15de8142012-10-11 06:00:5416#include "chrome/browser/chromeos/drive/drive_file_system_util.h"
[email protected]c02a4242012-12-11 18:36:3217#include "chrome/browser/chromeos/input_method/input_method_configuration.h"
[email protected]c8d4e9462011-06-29 23:18:5718#include "chrome/browser/chromeos/input_method/input_method_manager.h"
[email protected]9199bd52010-07-01 05:04:4119#include "chrome/browser/chromeos/input_method/input_method_util.h"
[email protected]c010f632011-04-01 06:44:3920#include "chrome/browser/chromeos/input_method/xkeyboard.h"
[email protected]26012e22010-12-01 06:44:2721#include "chrome/browser/chromeos/login/login_utils.h"
[email protected]022c3b92012-09-13 19:45:5922#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]595a5ed2012-05-04 00:39:1623#include "chrome/browser/chromeos/system/drm_settings.h"
[email protected]82eb8ec2011-12-20 22:24:3324#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]58a46772012-07-11 02:16:0825#include "chrome/browser/chromeos/system/power_manager_settings.h"
[email protected]de1528d1a2012-05-14 10:36:1526#include "chrome/browser/chromeos/system/statistics_provider.h"
[email protected]155e1b42012-07-14 03:06:0127#include "chrome/browser/download/download_util.h"
[email protected]37858e52010-08-26 00:22:0228#include "chrome/browser/prefs/pref_service.h"
[email protected]b3362572011-08-17 09:28:5029#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]432115822011-07-10 15:52:2730#include "chrome/common/chrome_notification_types.h"
[email protected]775caec2011-09-01 17:14:3231#include "chrome/common/chrome_switches.h"
[email protected]fecc1522009-10-15 21:08:2932#include "chrome/common/pref_names.h"
[email protected]6f96cbcb2011-11-04 02:26:0733#include "googleurl/src/gurl.h"
[email protected]153472d72012-09-04 21:33:0234#include "ui/base/events/event_constants.h"
[email protected]e4cc4832012-11-05 17:33:1435#include "ui/base/events/event_utils.h"
[email protected]fecc1522009-10-15 21:08:2936#include "unicode/timezone.h"
37
[email protected]de1528d1a2012-05-14 10:36:1538namespace chromeos {
[email protected]fecc1522009-10-15 21:08:2939
[email protected]9199bd52010-07-01 05:04:4140static const char kFallbackInputMethodLocale[] = "en-US";
[email protected]4793c942010-09-21 23:17:1741
[email protected]2c62b3f2012-04-12 12:07:5042Preferences::Preferences()
[email protected]155e1b42012-07-14 03:06:0143 : prefs_(NULL),
[email protected]c02a4242012-12-11 18:36:3244 input_method_manager_(input_method::GetInputMethodManager()) {
[email protected]2c62b3f2012-04-12 12:07:5045}
46
47Preferences::Preferences(input_method::InputMethodManager* input_method_manager)
48 : input_method_manager_(input_method_manager) {
49}
[email protected]d743a5982010-11-08 17:54:0950
[email protected]7f914fd2012-12-20 23:55:2551Preferences::~Preferences() {
52 prefs_->RemoveObserver(this);
53}
[email protected]9199bd52010-07-01 05:04:4154
[email protected]fecc1522009-10-15 21:08:2955// static
[email protected]5b199522012-12-22 17:24:4456void Preferences::RegisterUserPrefs(PrefServiceSyncable* prefs) {
[email protected]2c62b3f2012-04-12 12:07:5057 std::string hardware_keyboard_id;
58 // TODO(yusukes): Remove the runtime hack.
59 if (base::chromeos::IsRunningOnChromeOS()) {
60 input_method::InputMethodManager* manager =
[email protected]c02a4242012-12-11 18:36:3261 input_method::GetInputMethodManager();
[email protected]1e019ea2012-08-09 00:54:0462 if (manager) {
63 hardware_keyboard_id =
64 manager->GetInputMethodUtil()->GetHardwareInputMethodId();
65 }
[email protected]2c62b3f2012-04-12 12:07:5066 } else {
67 hardware_keyboard_id = "xkb:us::eng"; // only for testing.
68 }
[email protected]a9a81812011-09-16 11:01:1769
[email protected]d36f941b2011-05-09 06:19:1670 prefs->RegisterBooleanPref(prefs::kTapToClickEnabled,
[email protected]392abf52012-09-25 00:21:5871 true,
[email protected]5b199522012-12-22 17:24:4472 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]1b46af02012-10-31 05:23:5473 prefs->RegisterBooleanPref(prefs::kTapDraggingEnabled,
74 false,
[email protected]5b199522012-12-22 17:24:4475 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]190349fd2012-05-02 00:10:4776 prefs->RegisterBooleanPref(prefs::kEnableTouchpadThreeFingerClick,
77 false,
[email protected]5b199522012-12-22 17:24:4478 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]fbc176b62012-10-27 02:19:5879 prefs->RegisterBooleanPref(prefs::kEnableTouchpadThreeFingerSwipe,
80 false,
[email protected]5b199522012-12-22 17:24:4481 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]61008732012-11-27 10:36:0582 prefs->RegisterBooleanPref(
83 prefs::kNaturalScroll,
84 CommandLine::ForCurrentProcess()->HasSwitch(
85 switches::kNaturalScrollDefault),
[email protected]5b199522012-12-22 17:24:4486 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]0027fde12011-12-15 05:09:3887 prefs->RegisterBooleanPref(prefs::kPrimaryMouseButtonRight,
88 false,
[email protected]5b199522012-12-22 17:24:4489 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]d36f941b2011-05-09 06:19:1690 prefs->RegisterBooleanPref(prefs::kLabsMediaplayerEnabled,
91 false,
[email protected]5b199522012-12-22 17:24:4492 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]d36f941b2011-05-09 06:19:1693 prefs->RegisterBooleanPref(prefs::kLabsAdvancedFilesystemEnabled,
94 false,
[email protected]5b199522012-12-22 17:24:4495 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]27f20d52010-09-18 00:59:3196 // Check if the accessibility pref is already registered, which can happen
97 // in WizardController::RegisterPrefs. We still want to try to register
98 // the pref here in case of Chrome/Linux with ChromeOS=1.
[email protected]7ef254b2011-12-08 03:24:4599 if (prefs->FindPreference(prefs::kSpokenFeedbackEnabled) == NULL) {
100 prefs->RegisterBooleanPref(prefs::kSpokenFeedbackEnabled,
[email protected]d36f941b2011-05-09 06:19:16101 false,
[email protected]5b199522012-12-22 17:24:44102 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]27f20d52010-09-18 00:59:31103 }
[email protected]487ba1462012-01-05 03:13:09104 if (prefs->FindPreference(prefs::kHighContrastEnabled) == NULL) {
105 prefs->RegisterBooleanPref(prefs::kHighContrastEnabled,
106 false,
[email protected]5b199522012-12-22 17:24:44107 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]487ba1462012-01-05 03:13:09108 }
[email protected]a53804ba2012-12-17 12:07:42109 if (prefs->FindPreference(prefs::kScreenMagnifierEnabled) == NULL) {
110 prefs->RegisterBooleanPref(prefs::kScreenMagnifierEnabled,
111 false,
[email protected]5b199522012-12-22 17:24:44112 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]a53804ba2012-12-17 12:07:42113 }
[email protected]dddc4a072012-10-16 19:30:03114 if (prefs->FindPreference(prefs::kScreenMagnifierScale) == NULL) {
115 prefs->RegisterDoublePref(prefs::kScreenMagnifierScale,
116 std::numeric_limits<double>::min(),
[email protected]5b199522012-12-22 17:24:44117 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]dddc4a072012-10-16 19:30:03118 }
[email protected]5c85d5d2012-12-03 14:22:56119 if (prefs->FindPreference(prefs::kShouldAlwaysShowAccessibilityMenu) ==
120 NULL) {
121 prefs->RegisterBooleanPref(prefs::kShouldAlwaysShowAccessibilityMenu,
[email protected]51009902012-12-03 18:37:31122 false,
[email protected]5b199522012-12-22 17:24:44123 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]77f7c132012-11-15 06:52:54124 }
[email protected]487ba1462012-01-05 03:13:09125 if (prefs->FindPreference(prefs::kVirtualKeyboardEnabled) == NULL) {
126 prefs->RegisterBooleanPref(prefs::kVirtualKeyboardEnabled,
127 false,
[email protected]5b199522012-12-22 17:24:44128 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]487ba1462012-01-05 03:13:09129 }
[email protected]563fb5f2012-03-31 00:39:28130 prefs->RegisterIntegerPref(prefs::kMouseSensitivity,
131 3,
[email protected]5b199522012-12-22 17:24:44132 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]d36f941b2011-05-09 06:19:16133 prefs->RegisterIntegerPref(prefs::kTouchpadSensitivity,
134 3,
[email protected]5b199522012-12-22 17:24:44135 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]530cd622011-04-14 15:45:00136 prefs->RegisterBooleanPref(prefs::kUse24HourClock,
[email protected]d36f941b2011-05-09 06:19:16137 base::GetHourClockType() == base::k24HourClock,
[email protected]5b199522012-12-22 17:24:44138 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]e1619ee02012-10-22 08:14:49139 prefs->RegisterBooleanPref(prefs::kDisableDrive,
[email protected]3cbae79b02012-03-21 19:21:49140 false,
[email protected]5b199522012-12-22 17:24:44141 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]e1619ee02012-10-22 08:14:49142 prefs->RegisterBooleanPref(prefs::kDisableDriveOverCellular,
[email protected]3cbae79b02012-03-21 19:21:49143 true,
[email protected]5b199522012-12-22 17:24:44144 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]e1619ee02012-10-22 08:14:49145 prefs->RegisterBooleanPref(prefs::kDisableDriveHostedFiles,
[email protected]3cbae79b02012-03-21 19:21:49146 false,
[email protected]5b199522012-12-22 17:24:44147 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:10148 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod
149 // because they're just used to track the logout state of the device.
[email protected]d36f941b2011-05-09 06:19:16150 prefs->RegisterStringPref(prefs::kLanguageCurrentInputMethod,
151 "",
[email protected]5b199522012-12-22 17:24:44152 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]d36f941b2011-05-09 06:19:16153 prefs->RegisterStringPref(prefs::kLanguagePreviousInputMethod,
154 "",
[email protected]5b199522012-12-22 17:24:44155 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:10156 // We don't sync the list of input methods and preferred languages since a
157 // user might use two or more devices with different hardware keyboards.
158 // crosbug.com/15181
[email protected]c5d45432010-09-07 08:25:35159 prefs->RegisterStringPref(prefs::kLanguagePreferredLanguages,
[email protected]d36f941b2011-05-09 06:19:16160 kFallbackInputMethodLocale,
[email protected]5b199522012-12-22 17:24:44161 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]2c62b3f2012-04-12 12:07:50162 prefs->RegisterStringPref(prefs::kLanguagePreloadEngines,
163 hardware_keyboard_id,
[email protected]5b199522012-12-22 17:24:44164 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]797c6802012-09-20 10:36:13165 prefs->RegisterStringPref(prefs::kLanguageFilteredExtensionImes,
166 "",
[email protected]5b199522012-12-22 17:24:44167 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]b65c5d22010-08-20 02:50:23168 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
169 prefs->RegisterBooleanPref(
170 language_prefs::kChewingBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16171 language_prefs::kChewingBooleanPrefs[i].default_pref_value,
[email protected]da9858f2012-04-09 14:50:03172 language_prefs::kChewingBooleanPrefs[i].sync_status);
[email protected]525dbe22010-06-01 07:05:43173 }
[email protected]b65c5d22010-08-20 02:50:23174 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:43175 prefs->RegisterStringPref(
[email protected]b65c5d22010-08-20 02:50:23176 language_prefs::kChewingMultipleChoicePrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16177 language_prefs::kChewingMultipleChoicePrefs[i].default_pref_value,
[email protected]da9858f2012-04-09 14:50:03178 language_prefs::kChewingMultipleChoicePrefs[i].sync_status);
[email protected]525dbe22010-06-01 07:05:43179 }
[email protected]b65c5d22010-08-20 02:50:23180 prefs->RegisterIntegerPref(
181 language_prefs::kChewingHsuSelKeyType.pref_name,
[email protected]d36f941b2011-05-09 06:19:16182 language_prefs::kChewingHsuSelKeyType.default_pref_value,
[email protected]da9858f2012-04-09 14:50:03183 language_prefs::kChewingHsuSelKeyType.sync_status);
[email protected]7ac5af92010-06-07 01:25:44184
[email protected]b65c5d22010-08-20 02:50:23185 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
186 prefs->RegisterIntegerPref(
187 language_prefs::kChewingIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16188 language_prefs::kChewingIntegerPrefs[i].default_pref_value,
[email protected]da9858f2012-04-09 14:50:03189 language_prefs::kChewingIntegerPrefs[i].sync_status);
[email protected]15c53082010-06-03 03:28:21190 }
[email protected]20ce516d2010-06-18 02:20:04191 prefs->RegisterStringPref(
192 prefs::kLanguageHangulKeyboard,
[email protected]d36f941b2011-05-09 06:19:16193 language_prefs::kHangulKeyboardNameIDPairs[0].keyboard_id,
[email protected]5b199522012-12-22 17:24:44194 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]33444cf2011-08-04 06:33:55195 prefs->RegisterStringPref(prefs::kLanguageHangulHanjaBindingKeys,
[email protected]7f132d02013-01-03 00:32:26196 language_prefs::kHangulHanjaBindingKeys,
[email protected]33444cf2011-08-04 06:33:55197 // Don't sync the pref as it's not user-configurable
[email protected]5b199522012-12-22 17:24:44198 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]b65c5d22010-08-20 02:50:23199 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
200 prefs->RegisterBooleanPref(
201 language_prefs::kPinyinBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16202 language_prefs::kPinyinBooleanPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51203 language_prefs::kPinyinBooleanPrefs[i].sync_status);
[email protected]9040ad22010-04-22 04:29:28204 }
[email protected]b65c5d22010-08-20 02:50:23205 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
206 prefs->RegisterIntegerPref(
207 language_prefs::kPinyinIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16208 language_prefs::kPinyinIntegerPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51209 language_prefs::kPinyinIntegerPrefs[i].sync_status);
[email protected]6e5c4b82010-05-24 08:18:44210 }
[email protected]b65c5d22010-08-20 02:50:23211 prefs->RegisterIntegerPref(
212 language_prefs::kPinyinDoublePinyinSchema.pref_name,
[email protected]d36f941b2011-05-09 06:19:16213 language_prefs::kPinyinDoublePinyinSchema.default_pref_value,
[email protected]5b199522012-12-22 17:24:44214 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]7ac5af92010-06-07 01:25:44215
[email protected]b65c5d22010-08-20 02:50:23216 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
217 prefs->RegisterBooleanPref(
218 language_prefs::kMozcBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16219 language_prefs::kMozcBooleanPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51220 language_prefs::kMozcBooleanPrefs[i].sync_status);
[email protected]8a1ace22010-06-10 05:38:25221 }
[email protected]b65c5d22010-08-20 02:50:23222 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
[email protected]7ac5af92010-06-07 01:25:44223 prefs->RegisterStringPref(
[email protected]b65c5d22010-08-20 02:50:23224 language_prefs::kMozcMultipleChoicePrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16225 language_prefs::kMozcMultipleChoicePrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51226 language_prefs::kMozcMultipleChoicePrefs[i].sync_status);
[email protected]9040ad22010-04-22 04:29:28227 }
[email protected]b65c5d22010-08-20 02:50:23228 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
229 prefs->RegisterIntegerPref(
230 language_prefs::kMozcIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16231 language_prefs::kMozcIntegerPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51232 language_prefs::kMozcIntegerPrefs[i].sync_status);
[email protected]54037462010-06-22 02:06:23233 }
[email protected]a25f48c2012-10-30 00:32:13234 prefs->RegisterIntegerPref(prefs::kLanguageRemapSearchKeyTo,
[email protected]d36f941b2011-05-09 06:19:16235 input_method::kSearchKey,
[email protected]5b199522012-12-22 17:24:44236 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]a25f48c2012-10-30 00:32:13237 prefs->RegisterIntegerPref(prefs::kLanguageRemapControlKeyTo,
[email protected]99c6cbe2012-05-23 08:34:04238 input_method::kControlKey,
[email protected]5b199522012-12-22 17:24:44239 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]a25f48c2012-10-30 00:32:13240 prefs->RegisterIntegerPref(prefs::kLanguageRemapAltKeyTo,
[email protected]99c6cbe2012-05-23 08:34:04241 input_method::kAltKey,
[email protected]5b199522012-12-22 17:24:44242 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]872ead342012-10-31 17:50:01243 prefs->RegisterIntegerPref(prefs::kLanguageRemapCapsLockKeyTo,
244 input_method::kCapsLockKey,
[email protected]5b199522012-12-22 17:24:44245 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:10246 // We don't sync the following keyboard prefs since they are not user-
247 // configurable.
[email protected]d36f941b2011-05-09 06:19:16248 prefs->RegisterBooleanPref(prefs::kLanguageXkbAutoRepeatEnabled,
249 true,
[email protected]5b199522012-12-22 17:24:44250 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]4743dad2010-08-30 01:41:07251 prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatDelay,
[email protected]d36f941b2011-05-09 06:19:16252 language_prefs::kXkbAutoRepeatDelayInMs,
[email protected]5b199522012-12-22 17:24:44253 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]4743dad2010-08-30 01:41:07254 prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatInterval,
[email protected]d36f941b2011-05-09 06:19:16255 language_prefs::kXkbAutoRepeatIntervalInMs,
[email protected]5b199522012-12-22 17:24:44256 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]4ccc05e2010-10-06 19:32:15257
258 // Screen lock default to off.
[email protected]d36f941b2011-05-09 06:19:16259 prefs->RegisterBooleanPref(prefs::kEnableScreenLock,
260 false,
[email protected]5b199522012-12-22 17:24:44261 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]ea1eba52010-11-23 18:05:38262
263 // Mobile plan notifications default to on.
[email protected]d36f941b2011-05-09 06:19:16264 prefs->RegisterBooleanPref(prefs::kShowPlanNotifications,
265 true,
[email protected]5b199522012-12-22 17:24:44266 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]c74fffa2011-04-27 13:32:24267
268 // 3G first-time usage promo will be shown at least once.
[email protected]d36f941b2011-05-09 06:19:16269 prefs->RegisterBooleanPref(prefs::kShow3gPromoNotification,
270 true,
[email protected]5b199522012-12-22 17:24:44271 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]d6ae9502011-05-05 18:23:09272
[email protected]efb770c2012-05-04 22:31:48273 // Initially all existing users would see "What's new"
274 // for current version after update.
275 prefs->RegisterStringPref(prefs::kChromeOSReleaseNotesVersion,
276 "0.0.0.0",
[email protected]5b199522012-12-22 17:24:44277 PrefServiceSyncable::SYNCABLE_PREF);
[email protected]efb770c2012-05-04 22:31:48278
[email protected]cc8f2472011-08-01 07:14:46279 // OAuth1 all access token and secret pair.
280 prefs->RegisterStringPref(prefs::kOAuth1Token,
281 "",
[email protected]5b199522012-12-22 17:24:44282 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]cc8f2472011-08-01 07:14:46283 prefs->RegisterStringPref(prefs::kOAuth1Secret,
284 "",
[email protected]5b199522012-12-22 17:24:44285 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]595a5ed2012-05-04 00:39:16286
287 // TODO(wad): Once UI is connected, a final default can be set. At that point
288 // change this pref from UNSYNCABLE to SYNCABLE.
289 prefs->RegisterBooleanPref(prefs::kEnableCrosDRM,
290 true,
[email protected]5b199522012-12-22 17:24:44291 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]52584062012-07-24 08:46:13292
293 prefs->RegisterBooleanPref(prefs::kExternalStorageDisabled,
294 false,
[email protected]5b199522012-12-22 17:24:44295 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]fecc1522009-10-15 21:08:29296}
297
[email protected]5b199522012-12-22 17:24:44298void Preferences::InitUserPrefs(PrefServiceSyncable* prefs) {
[email protected]155e1b42012-07-14 03:06:01299 prefs_ = prefs;
300
[email protected]e7bff3e2012-11-14 15:34:44301 BooleanPrefMember::NamedChangeCallback callback =
302 base::Bind(&Preferences::OnPreferenceChanged, base::Unretained(this));
303
304 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, callback);
305 tap_dragging_enabled_.Init(prefs::kTapDraggingEnabled, prefs, callback);
[email protected]190349fd2012-05-02 00:10:47306 three_finger_click_enabled_.Init(prefs::kEnableTouchpadThreeFingerClick,
[email protected]e7bff3e2012-11-14 15:34:44307 prefs, callback);
[email protected]fbc176b62012-10-27 02:19:58308 three_finger_swipe_enabled_.Init(prefs::kEnableTouchpadThreeFingerSwipe,
[email protected]e7bff3e2012-11-14 15:34:44309 prefs, callback);
310 natural_scroll_.Init(prefs::kNaturalScroll, prefs, callback);
311 accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, prefs, callback);
[email protected]a53804ba2012-12-17 12:07:42312 screen_magnifier_enabled_.Init(prefs::kScreenMagnifierEnabled,
313 prefs, callback);
[email protected]ea2110d2012-11-26 19:20:24314 screen_magnifier_scale_.Init(prefs::kScreenMagnifierScale, prefs, callback);
[email protected]e7bff3e2012-11-14 15:34:44315 mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, callback);
316 touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, callback);
317 use_24hour_clock_.Init(prefs::kUse24HourClock, prefs, callback);
318 disable_drive_.Init(prefs::kDisableDrive, prefs, callback);
[email protected]e1619ee02012-10-22 08:14:49319 disable_drive_over_cellular_.Init(prefs::kDisableDriveOverCellular,
[email protected]e7bff3e2012-11-14 15:34:44320 prefs, callback);
[email protected]e1619ee02012-10-22 08:14:49321 disable_drive_hosted_files_.Init(prefs::kDisableDriveHostedFiles,
[email protected]e7bff3e2012-11-14 15:34:44322 prefs, callback);
[email protected]78a6b642012-09-12 02:07:03323 download_default_directory_.Init(prefs::kDownloadDefaultDirectory,
[email protected]e7bff3e2012-11-14 15:34:44324 prefs, callback);
[email protected]0027fde12011-12-15 05:09:38325 primary_mouse_button_right_.Init(prefs::kPrimaryMouseButtonRight,
[email protected]e7bff3e2012-11-14 15:34:44326 prefs, callback);
[email protected]c67a30932012-03-14 05:23:00327 preferred_languages_.Init(prefs::kLanguagePreferredLanguages,
[email protected]e7bff3e2012-11-14 15:34:44328 prefs, callback);
329 preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, callback);
[email protected]797c6802012-09-20 10:36:13330 filtered_extension_imes_.Init(prefs::kLanguageFilteredExtensionImes,
[email protected]e7bff3e2012-11-14 15:34:44331 prefs, callback);
332 current_input_method_.Init(prefs::kLanguageCurrentInputMethod,
333 prefs, callback);
334 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod,
335 prefs, callback);
[email protected]22bec1a2012-03-27 06:33:48336
[email protected]b65c5d22010-08-20 02:50:23337 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
[email protected]c67a30932012-03-14 05:23:00338 chewing_boolean_prefs_[i].Init(
[email protected]e7bff3e2012-11-14 15:34:44339 language_prefs::kChewingBooleanPrefs[i].pref_name, prefs, callback);
[email protected]525dbe22010-06-01 07:05:43340 }
[email protected]b65c5d22010-08-20 02:50:23341 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
[email protected]c67a30932012-03-14 05:23:00342 chewing_multiple_choice_prefs_[i].Init(
[email protected]e7bff3e2012-11-14 15:34:44343 language_prefs::kChewingMultipleChoicePrefs[i].pref_name,
344 prefs, callback);
[email protected]525dbe22010-06-01 07:05:43345 }
[email protected]c67a30932012-03-14 05:23:00346 chewing_hsu_sel_key_type_.Init(
[email protected]e7bff3e2012-11-14 15:34:44347 language_prefs::kChewingHsuSelKeyType.pref_name, prefs, callback);
[email protected]b65c5d22010-08-20 02:50:23348 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
[email protected]c67a30932012-03-14 05:23:00349 chewing_integer_prefs_[i].Init(
[email protected]e7bff3e2012-11-14 15:34:44350 language_prefs::kChewingIntegerPrefs[i].pref_name, prefs, callback);
[email protected]15c53082010-06-03 03:28:21351 }
[email protected]e7bff3e2012-11-14 15:34:44352 hangul_keyboard_.Init(prefs::kLanguageHangulKeyboard, prefs, callback);
[email protected]c67a30932012-03-14 05:23:00353 hangul_hanja_binding_keys_.Init(
[email protected]e7bff3e2012-11-14 15:34:44354 prefs::kLanguageHangulHanjaBindingKeys, prefs, callback);
[email protected]b65c5d22010-08-20 02:50:23355 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
[email protected]c67a30932012-03-14 05:23:00356 pinyin_boolean_prefs_[i].Init(
[email protected]e7bff3e2012-11-14 15:34:44357 language_prefs::kPinyinBooleanPrefs[i].pref_name, prefs, callback);
[email protected]9040ad22010-04-22 04:29:28358 }
[email protected]b65c5d22010-08-20 02:50:23359 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
[email protected]c67a30932012-03-14 05:23:00360 pinyin_int_prefs_[i].Init(
[email protected]e7bff3e2012-11-14 15:34:44361 language_prefs::kPinyinIntegerPrefs[i].pref_name, prefs, callback);
[email protected]9040ad22010-04-22 04:29:28362 }
[email protected]c67a30932012-03-14 05:23:00363 pinyin_double_pinyin_schema_.Init(
[email protected]e7bff3e2012-11-14 15:34:44364 language_prefs::kPinyinDoublePinyinSchema.pref_name, prefs, callback);
[email protected]b65c5d22010-08-20 02:50:23365 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
[email protected]c67a30932012-03-14 05:23:00366 mozc_boolean_prefs_[i].Init(
[email protected]e7bff3e2012-11-14 15:34:44367 language_prefs::kMozcBooleanPrefs[i].pref_name, prefs, callback);
[email protected]8a1ace22010-06-10 05:38:25368 }
[email protected]b65c5d22010-08-20 02:50:23369 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
[email protected]c67a30932012-03-14 05:23:00370 mozc_multiple_choice_prefs_[i].Init(
[email protected]e7bff3e2012-11-14 15:34:44371 language_prefs::kMozcMultipleChoicePrefs[i].pref_name, prefs, callback);
[email protected]6e5c4b82010-05-24 08:18:44372 }
[email protected]b65c5d22010-08-20 02:50:23373 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
[email protected]c67a30932012-03-14 05:23:00374 mozc_integer_prefs_[i].Init(
[email protected]e7bff3e2012-11-14 15:34:44375 language_prefs::kMozcIntegerPrefs[i].pref_name, prefs, callback);
[email protected]54037462010-06-22 02:06:23376 }
[email protected]c67a30932012-03-14 05:23:00377 xkb_auto_repeat_enabled_.Init(
[email protected]e7bff3e2012-11-14 15:34:44378 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback);
[email protected]c67a30932012-03-14 05:23:00379 xkb_auto_repeat_delay_pref_.Init(
[email protected]e7bff3e2012-11-14 15:34:44380 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback);
[email protected]c67a30932012-03-14 05:23:00381 xkb_auto_repeat_interval_pref_.Init(
[email protected]e7bff3e2012-11-14 15:34:44382 prefs::kLanguageXkbAutoRepeatInterval, prefs, callback);
[email protected]fecc1522009-10-15 21:08:29383
[email protected]e7bff3e2012-11-14 15:34:44384 enable_screen_lock_.Init(prefs::kEnableScreenLock, prefs, callback);
[email protected]595a5ed2012-05-04 00:39:16385
[email protected]e7bff3e2012-11-14 15:34:44386 enable_drm_.Init(prefs::kEnableCrosDRM, prefs, callback);
[email protected]2c62b3f2012-04-12 12:07:50387}
388
[email protected]5b199522012-12-22 17:24:44389void Preferences::Init(PrefServiceSyncable* prefs) {
[email protected]2c62b3f2012-04-12 12:07:50390 InitUserPrefs(prefs);
[email protected]4ccc05e2010-10-06 19:32:15391
[email protected]7f914fd2012-12-20 23:55:25392 // This causes OnIsSyncingChanged to be called when the value of
393 // PrefService::IsSyncing() changes.
394 prefs->AddObserver(this);
395
[email protected]d7ca1ba2011-05-09 20:09:08396 // Initialize preferences to currently saved state.
[email protected]fecc1522009-10-15 21:08:29397 NotifyPrefChanged(NULL);
[email protected]26012e22010-12-01 06:44:27398
399 // If a guest is logged in, initialize the prefs as if this is the first
400 // login.
401 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) {
402 LoginUtils::Get()->SetFirstLoginPrefs(prefs);
403 }
[email protected]fecc1522009-10-15 21:08:29404}
405
[email protected]5b199522012-12-22 17:24:44406void Preferences::InitUserPrefsForTesting(PrefServiceSyncable* prefs) {
[email protected]2c62b3f2012-04-12 12:07:50407 InitUserPrefs(prefs);
408}
409
410void Preferences::SetInputMethodListForTesting() {
411 SetInputMethodList();
412}
413
[email protected]e7bff3e2012-11-14 15:34:44414void Preferences::OnPreferenceChanged(const std::string& pref_name) {
[email protected]a6a7ced2012-11-01 17:24:18415 NotifyPrefChanged(&pref_name);
[email protected]fecc1522009-10-15 21:08:29416}
417
[email protected]57ecc4b2010-08-11 03:02:51418void Preferences::NotifyPrefChanged(const std::string* pref_name) {
[email protected]3b02de292010-05-13 06:05:05419 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) {
[email protected]b685fbd2012-03-24 09:23:04420 const bool enabled = tap_to_click_enabled_.GetValue();
[email protected]1cbfb3b2011-07-11 23:34:08421 system::touchpad_settings::SetTapToClick(enabled);
[email protected]d7ca1ba2011-05-09 20:09:08422 if (pref_name)
423 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled);
424 else
425 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Started", enabled);
[email protected]022c3b92012-09-13 19:45:59426
427 // Save owner preference in local state to use on login screen.
428 if (chromeos::UserManager::Get()->IsCurrentUserOwner()) {
429 PrefService* prefs = g_browser_process->local_state();
430 if (prefs->GetBoolean(prefs::kOwnerTapToClickEnabled) != enabled)
431 prefs->SetBoolean(prefs::kOwnerTapToClickEnabled, enabled);
432 }
[email protected]3b02de292010-05-13 06:05:05433 }
[email protected]1b46af02012-10-31 05:23:54434 if (!pref_name || *pref_name == prefs::kTapDraggingEnabled) {
435 const bool enabled = tap_dragging_enabled_.GetValue();
436 system::touchpad_settings::SetTapDragging(enabled);
437 if (pref_name)
438 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Changed", enabled);
439 else
440 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Started", enabled);
441 }
[email protected]190349fd2012-05-02 00:10:47442 if (!pref_name || *pref_name == prefs::kEnableTouchpadThreeFingerClick) {
443 const bool enabled = three_finger_click_enabled_.GetValue();
444 system::touchpad_settings::SetThreeFingerClick(enabled);
445 if (pref_name)
446 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Changed", enabled);
447 else
448 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Started", enabled);
449 }
[email protected]fbc176b62012-10-27 02:19:58450 if (!pref_name || *pref_name == prefs::kEnableTouchpadThreeFingerSwipe) {
451 const bool enabled = three_finger_swipe_enabled_.GetValue();
452 system::touchpad_settings::SetThreeFingerSwipe(enabled);
453 if (pref_name)
454 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerSwipe.Changed", enabled);
455 else
456 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerSwipe.Started", enabled);
457 }
[email protected]b685fbd2012-03-24 09:23:04458 if (!pref_name || *pref_name == prefs::kNaturalScroll) {
[email protected]7f914fd2012-12-20 23:55:25459 // Force natural scroll default if we've sync'd and if the cmd line arg is
460 // set.
461 ForceNaturalScrollDefault();
[email protected]223059e2012-10-05 01:44:49462
[email protected]b685fbd2012-03-24 09:23:04463 const bool enabled = natural_scroll_.GetValue();
[email protected]223059e2012-10-05 01:44:49464 DVLOG(1) << "Natural scroll set to " << enabled;
[email protected]b685fbd2012-03-24 09:23:04465 ui::SetNaturalScroll(enabled);
466 if (pref_name)
467 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Changed", enabled);
468 else
469 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Started", enabled);
470 }
[email protected]563fb5f2012-03-31 00:39:28471 if (!pref_name || *pref_name == prefs::kMouseSensitivity) {
472 const int sensitivity = mouse_sensitivity_.GetValue();
473 system::mouse_settings::SetSensitivity(sensitivity);
474 if (pref_name) {
475 UMA_HISTOGRAM_CUSTOM_COUNTS(
476 "Mouse.Sensitivity.Changed", sensitivity, 1, 5, 5);
477 } else {
478 UMA_HISTOGRAM_CUSTOM_COUNTS(
479 "Mouse.Sensitivity.Started", sensitivity, 1, 5, 5);
480 }
481 }
[email protected]3b02de292010-05-13 06:05:05482 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) {
[email protected]563fb5f2012-03-31 00:39:28483 const int sensitivity = touchpad_sensitivity_.GetValue();
484 system::touchpad_settings::SetSensitivity(sensitivity);
[email protected]d7ca1ba2011-05-09 20:09:08485 if (pref_name) {
486 UMA_HISTOGRAM_CUSTOM_COUNTS(
487 "Touchpad.Sensitivity.Changed", sensitivity, 1, 5, 5);
488 } else {
489 UMA_HISTOGRAM_CUSTOM_COUNTS(
490 "Touchpad.Sensitivity.Started", sensitivity, 1, 5, 5);
491 }
[email protected]3b02de292010-05-13 06:05:05492 }
[email protected]0027fde12011-12-15 05:09:38493 if (!pref_name || *pref_name == prefs::kPrimaryMouseButtonRight) {
494 const bool right = primary_mouse_button_right_.GetValue();
495 system::mouse_settings::SetPrimaryButtonRight(right);
496 if (pref_name)
[email protected]6c8599e2012-01-20 04:31:58497 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Changed", right);
[email protected]0027fde12011-12-15 05:09:38498 else
[email protected]6c8599e2012-01-20 04:31:58499 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Started", right);
[email protected]022c3b92012-09-13 19:45:59500
501 // Save owner preference in local state to use on login screen.
502 if (chromeos::UserManager::Get()->IsCurrentUserOwner()) {
503 PrefService* prefs = g_browser_process->local_state();
504 if (prefs->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight) != right)
505 prefs->SetBoolean(prefs::kOwnerPrimaryMouseButtonRight, right);
506 }
[email protected]0027fde12011-12-15 05:09:38507 }
[email protected]78a6b642012-09-12 02:07:03508 if (!pref_name || *pref_name == prefs::kDownloadDefaultDirectory) {
[email protected]d9d04df2012-10-12 07:06:35509 const bool default_download_to_drive = drive::util::IsUnderDriveMountPoint(
[email protected]78a6b642012-09-12 02:07:03510 download_default_directory_.GetValue());
511 if (pref_name)
[email protected]e8307a12012-09-12 20:06:34512 UMA_HISTOGRAM_BOOLEAN(
513 "FileBrowser.DownloadDestination.IsGoogleDrive.Changed",
[email protected]78a6b642012-09-12 02:07:03514 default_download_to_drive);
515 else
[email protected]e8307a12012-09-12 20:06:34516 UMA_HISTOGRAM_BOOLEAN(
517 "FileBrowser.DownloadDestination.IsGoogleDrive.Started",
[email protected]78a6b642012-09-12 02:07:03518 default_download_to_drive);
519 }
[email protected]8be9ff22010-06-08 02:13:54520
[email protected]74b42fc12010-07-20 10:15:41521 if (!pref_name || *pref_name == prefs::kLanguagePreferredLanguages) {
522 // Unlike kLanguagePreloadEngines and some other input method
523 // preferencs, we don't need to send this to ibus-daemon.
524 }
[email protected]a6e90772011-02-09 05:38:54525
[email protected]a6e90772011-02-09 05:38:54526 if (!pref_name || *pref_name == prefs::kLanguageXkbAutoRepeatEnabled) {
[email protected]c67a30932012-03-14 05:23:00527 const bool enabled = xkb_auto_repeat_enabled_.GetValue();
[email protected]cf61f6b0a2013-01-03 00:34:12528 input_method::XKeyboard::SetAutoRepeatEnabled(enabled);
[email protected]a6e90772011-02-09 05:38:54529 }
530 if (!pref_name || ((*pref_name == prefs::kLanguageXkbAutoRepeatDelay) ||
531 (*pref_name == prefs::kLanguageXkbAutoRepeatInterval))) {
532 UpdateAutoRepeatRate();
533 }
534
[email protected]2c62b3f2012-04-12 12:07:50535 if (!pref_name) {
536 SetInputMethodList();
537 } else if (*pref_name == prefs::kLanguagePreloadEngines) {
[email protected]7f132d02013-01-03 00:32:26538 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
539 language_prefs::kPreloadEnginesConfigName,
[email protected]c67a30932012-03-14 05:23:00540 preload_engines_.GetValue());
[email protected]3b02de292010-05-13 06:05:05541 }
[email protected]22bec1a2012-03-27 06:33:48542
[email protected]797c6802012-09-20 10:36:13543 if (!pref_name || *pref_name == prefs::kLanguageFilteredExtensionImes) {
544 std::string value(filtered_extension_imes_.GetValue());
545
546 std::vector<std::string> split_values;
547 if (!value.empty())
548 base::SplitString(value, ',', &split_values);
549
550 input_method_manager_->SetFilteredExtensionImes(&split_values);
551 }
552
[email protected]2c62b3f2012-04-12 12:07:50553 // Do not check |*pref_name| of the prefs for remembering current/previous
554 // input methods here. We're only interested in initial values of the prefs.
[email protected]22bec1a2012-03-27 06:33:48555
[email protected]b65c5d22010-08-20 02:50:23556 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
557 if (!pref_name ||
558 *pref_name == language_prefs::kChewingBooleanPrefs[i].pref_name) {
559 SetLanguageConfigBoolean(
[email protected]7f132d02013-01-03 00:32:26560 language_prefs::kChewingSectionName,
[email protected]b65c5d22010-08-20 02:50:23561 language_prefs::kChewingBooleanPrefs[i].ibus_config_name,
[email protected]c67a30932012-03-14 05:23:00562 chewing_boolean_prefs_[i].GetValue());
[email protected]525dbe22010-06-01 07:05:43563 }
564 }
[email protected]b65c5d22010-08-20 02:50:23565 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
566 if (!pref_name ||
567 *pref_name ==
568 language_prefs::kChewingMultipleChoicePrefs[i].pref_name) {
[email protected]525dbe22010-06-01 07:05:43569 SetLanguageConfigString(
[email protected]7f132d02013-01-03 00:32:26570 language_prefs::kChewingSectionName,
[email protected]b65c5d22010-08-20 02:50:23571 language_prefs::kChewingMultipleChoicePrefs[i].ibus_config_name,
[email protected]c67a30932012-03-14 05:23:00572 chewing_multiple_choice_prefs_[i].GetValue());
[email protected]525dbe22010-06-01 07:05:43573 }
574 }
[email protected]b65c5d22010-08-20 02:50:23575 if (!pref_name ||
576 *pref_name == language_prefs::kChewingHsuSelKeyType.pref_name) {
[email protected]7ac5af92010-06-07 01:25:44577 SetLanguageConfigInteger(
[email protected]7f132d02013-01-03 00:32:26578 language_prefs::kChewingSectionName,
[email protected]b65c5d22010-08-20 02:50:23579 language_prefs::kChewingHsuSelKeyType.ibus_config_name,
[email protected]c67a30932012-03-14 05:23:00580 chewing_hsu_sel_key_type_.GetValue());
[email protected]7ac5af92010-06-07 01:25:44581 }
[email protected]b65c5d22010-08-20 02:50:23582 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
583 if (!pref_name ||
584 *pref_name == language_prefs::kChewingIntegerPrefs[i].pref_name) {
585 SetLanguageConfigInteger(
[email protected]7f132d02013-01-03 00:32:26586 language_prefs::kChewingSectionName,
[email protected]b65c5d22010-08-20 02:50:23587 language_prefs::kChewingIntegerPrefs[i].ibus_config_name,
[email protected]c67a30932012-03-14 05:23:00588 chewing_integer_prefs_[i].GetValue());
[email protected]15c53082010-06-03 03:28:21589 }
590 }
[email protected]b65c5d22010-08-20 02:50:23591 if (!pref_name ||
592 *pref_name == prefs::kLanguageHangulKeyboard) {
[email protected]7f132d02013-01-03 00:32:26593 SetLanguageConfigString(language_prefs::kHangulSectionName,
594 language_prefs::kHangulKeyboardConfigName,
[email protected]c67a30932012-03-14 05:23:00595 hangul_keyboard_.GetValue());
[email protected]3b02de292010-05-13 06:05:05596 }
[email protected]33444cf2011-08-04 06:33:55597 if (!pref_name || *pref_name == prefs::kLanguageHangulHanjaBindingKeys) {
[email protected]7f132d02013-01-03 00:32:26598 SetLanguageConfigString(language_prefs::kHangulSectionName,
599 language_prefs::kHangulHanjaBindingKeysConfigName,
[email protected]c67a30932012-03-14 05:23:00600 hangul_hanja_binding_keys_.GetValue());
[email protected]33444cf2011-08-04 06:33:55601 }
[email protected]b65c5d22010-08-20 02:50:23602 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
603 if (!pref_name ||
604 *pref_name == language_prefs::kPinyinBooleanPrefs[i].pref_name) {
605 SetLanguageConfigBoolean(
[email protected]7f132d02013-01-03 00:32:26606 language_prefs::kPinyinSectionName,
[email protected]b65c5d22010-08-20 02:50:23607 language_prefs::kPinyinBooleanPrefs[i].ibus_config_name,
[email protected]c67a30932012-03-14 05:23:00608 pinyin_boolean_prefs_[i].GetValue());
[email protected]9040ad22010-04-22 04:29:28609 }
610 }
[email protected]b65c5d22010-08-20 02:50:23611 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
612 if (!pref_name ||
613 *pref_name == language_prefs::kPinyinIntegerPrefs[i].pref_name) {
614 SetLanguageConfigInteger(
[email protected]7f132d02013-01-03 00:32:26615 language_prefs::kPinyinSectionName,
[email protected]b65c5d22010-08-20 02:50:23616 language_prefs::kPinyinIntegerPrefs[i].ibus_config_name,
[email protected]c67a30932012-03-14 05:23:00617 pinyin_int_prefs_[i].GetValue());
[email protected]9040ad22010-04-22 04:29:28618 }
619 }
[email protected]b65c5d22010-08-20 02:50:23620 if (!pref_name ||
621 *pref_name == language_prefs::kPinyinDoublePinyinSchema.pref_name) {
[email protected]7ac5af92010-06-07 01:25:44622 SetLanguageConfigInteger(
[email protected]7f132d02013-01-03 00:32:26623 language_prefs::kPinyinSectionName,
[email protected]b65c5d22010-08-20 02:50:23624 language_prefs::kPinyinDoublePinyinSchema.ibus_config_name,
[email protected]c67a30932012-03-14 05:23:00625 pinyin_double_pinyin_schema_.GetValue());
[email protected]7ac5af92010-06-07 01:25:44626 }
[email protected]b65c5d22010-08-20 02:50:23627 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
628 if (!pref_name ||
629 *pref_name == language_prefs::kMozcBooleanPrefs[i].pref_name) {
630 SetLanguageConfigBoolean(
[email protected]7f132d02013-01-03 00:32:26631 language_prefs::kMozcSectionName,
[email protected]b65c5d22010-08-20 02:50:23632 language_prefs::kMozcBooleanPrefs[i].ibus_config_name,
[email protected]c67a30932012-03-14 05:23:00633 mozc_boolean_prefs_[i].GetValue());
[email protected]8a1ace22010-06-10 05:38:25634 }
635 }
[email protected]b65c5d22010-08-20 02:50:23636 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
637 if (!pref_name ||
638 *pref_name == language_prefs::kMozcMultipleChoicePrefs[i].pref_name) {
[email protected]6e5c4b82010-05-24 08:18:44639 SetLanguageConfigString(
[email protected]7f132d02013-01-03 00:32:26640 language_prefs::kMozcSectionName,
[email protected]b65c5d22010-08-20 02:50:23641 language_prefs::kMozcMultipleChoicePrefs[i].ibus_config_name,
[email protected]c67a30932012-03-14 05:23:00642 mozc_multiple_choice_prefs_[i].GetValue());
[email protected]6e5c4b82010-05-24 08:18:44643 }
644 }
[email protected]b65c5d22010-08-20 02:50:23645 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
646 if (!pref_name ||
647 *pref_name == language_prefs::kMozcIntegerPrefs[i].pref_name) {
648 SetLanguageConfigInteger(
[email protected]7f132d02013-01-03 00:32:26649 language_prefs::kMozcSectionName,
[email protected]b65c5d22010-08-20 02:50:23650 language_prefs::kMozcIntegerPrefs[i].ibus_config_name,
[email protected]c67a30932012-03-14 05:23:00651 mozc_integer_prefs_[i].GetValue());
[email protected]54037462010-06-22 02:06:23652 }
653 }
[email protected]4793c942010-09-21 23:17:17654
[email protected]4ccc05e2010-10-06 19:32:15655 // Init or update power manager config.
656 if (!pref_name || *pref_name == prefs::kEnableScreenLock) {
[email protected]58a46772012-07-11 02:16:08657 system::power_manager_settings::EnableScreenLock(
[email protected]4ccc05e2010-10-06 19:32:15658 enable_screen_lock_.GetValue());
659 }
[email protected]595a5ed2012-05-04 00:39:16660
661 // Init or update protected content (DRM) support.
662 if (!pref_name || *pref_name == prefs::kEnableCrosDRM) {
663 system::ToggleDrm(enable_drm_.GetValue());
664 }
[email protected]155e1b42012-07-14 03:06:01665
[email protected]e1619ee02012-10-22 08:14:49666 // Change the download directory to the default value if a Drive directory is
667 // selected and Drive is disabled.
668 if (!pref_name || *pref_name == prefs::kDisableDrive) {
[email protected]78a6b642012-09-12 02:07:03669 if (disable_drive_.GetValue()) {
[email protected]d9d04df2012-10-12 07:06:35670 if (drive::util::IsUnderDriveMountPoint(
[email protected]78a6b642012-09-12 02:07:03671 download_default_directory_.GetValue())) {
[email protected]155e1b42012-07-14 03:06:01672 prefs_->SetFilePath(prefs::kDownloadDefaultDirectory,
673 download_util::GetDefaultDownloadDirectory());
674 }
675 }
676 }
[email protected]fecc1522009-10-15 21:08:29677}
678
[email protected]7f914fd2012-12-20 23:55:25679void Preferences::OnIsSyncingChanged() {
680 DVLOG(1) << "OnIsSyncingChanged";
681 ForceNaturalScrollDefault();
682}
683
684void Preferences::ForceNaturalScrollDefault() {
685 DVLOG(1) << "ForceNaturalScrollDefault";
686 if (CommandLine::ForCurrentProcess()->HasSwitch(
687 switches::kNaturalScrollDefault) &&
688 prefs_->IsSyncing() &&
689 !prefs_->GetUserPrefValue(prefs::kNaturalScroll)) {
690 DVLOG(1) << "Natural scroll forced to true";
691 natural_scroll_.SetValue(true);
692 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Forced", true);
693 }
694}
695
[email protected]70aa5b32010-04-05 08:30:34696void Preferences::SetLanguageConfigBoolean(const char* section,
697 const char* name,
698 bool value) {
[email protected]62308c22012-03-13 12:07:10699 input_method::InputMethodConfigValue config;
700 config.type = input_method::InputMethodConfigValue::kValueTypeBool;
[email protected]70aa5b32010-04-05 08:30:34701 config.bool_value = value;
[email protected]2c62b3f2012-04-12 12:07:50702 input_method_manager_->SetInputMethodConfig(section, name, config);
[email protected]70aa5b32010-04-05 08:30:34703}
704
[email protected]9040ad22010-04-22 04:29:28705void Preferences::SetLanguageConfigInteger(const char* section,
706 const char* name,
707 int value) {
[email protected]62308c22012-03-13 12:07:10708 input_method::InputMethodConfigValue config;
709 config.type = input_method::InputMethodConfigValue::kValueTypeInt;
[email protected]9040ad22010-04-22 04:29:28710 config.int_value = value;
[email protected]2c62b3f2012-04-12 12:07:50711 input_method_manager_->SetInputMethodConfig(section, name, config);
[email protected]9040ad22010-04-22 04:29:28712}
713
[email protected]50951432010-03-31 12:12:42714void Preferences::SetLanguageConfigString(const char* section,
715 const char* name,
[email protected]ddd231e2010-06-29 20:35:19716 const std::string& value) {
[email protected]62308c22012-03-13 12:07:10717 input_method::InputMethodConfigValue config;
718 config.type = input_method::InputMethodConfigValue::kValueTypeString;
[email protected]ddd231e2010-06-29 20:35:19719 config.string_value = value;
[email protected]2c62b3f2012-04-12 12:07:50720 input_method_manager_->SetInputMethodConfig(section, name, config);
[email protected]50951432010-03-31 12:12:42721}
722
[email protected]2c25ddfd2010-04-09 10:35:55723void Preferences::SetLanguageConfigStringList(
724 const char* section,
725 const char* name,
[email protected]ddd231e2010-06-29 20:35:19726 const std::vector<std::string>& values) {
[email protected]62308c22012-03-13 12:07:10727 input_method::InputMethodConfigValue config;
728 config.type = input_method::InputMethodConfigValue::kValueTypeStringList;
[email protected]ddd231e2010-06-29 20:35:19729 for (size_t i = 0; i < values.size(); ++i)
730 config.string_list_value.push_back(values[i]);
731
[email protected]2c62b3f2012-04-12 12:07:50732 input_method_manager_->SetInputMethodConfig(section, name, config);
[email protected]2c25ddfd2010-04-09 10:35:55733}
734
[email protected]d01bb8072010-04-12 13:00:15735void Preferences::SetLanguageConfigStringListAsCSV(const char* section,
736 const char* name,
[email protected]ddd231e2010-06-29 20:35:19737 const std::string& value) {
[email protected]e24c2c92010-10-23 01:39:24738 VLOG(1) << "Setting " << name << " to '" << value << "'";
[email protected]d01bb8072010-04-12 13:00:15739
[email protected]ddd231e2010-06-29 20:35:19740 std::vector<std::string> split_values;
741 if (!value.empty())
[email protected]76eb0242010-10-14 00:35:36742 base::SplitString(value, ',', &split_values);
[email protected]ddd231e2010-06-29 20:35:19743
[email protected]7f132d02013-01-03 00:32:26744 if (section == std::string(language_prefs::kGeneralSectionName) &&
745 name == std::string(language_prefs::kPreloadEnginesConfigName)) {
[email protected]dbc9b192012-04-18 05:55:34746 input_method_manager_->EnableInputMethods(split_values);
747 return;
748 }
749
[email protected]2c25ddfd2010-04-09 10:35:55750 // We should call the cros API even when |value| is empty, to disable default
[email protected]d01bb8072010-04-12 13:00:15751 // config.
752 SetLanguageConfigStringList(section, name, split_values);
[email protected]70aa5b32010-04-05 08:30:34753}
754
[email protected]2c62b3f2012-04-12 12:07:50755void Preferences::SetInputMethodList() {
756 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod()
757 // might be called to change the current input method to the first one in the
758 // |preload_engines_| list. This also updates previous/current input method
759 // prefs. That's why GetValue() calls are placed before the
760 // SetLanguageConfigStringListAsCSV() call below.
761 const std::string previous_input_method_id =
762 previous_input_method_.GetValue();
763 const std::string current_input_method_id = current_input_method_.GetValue();
[email protected]7f132d02013-01-03 00:32:26764 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
765 language_prefs::kPreloadEnginesConfigName,
[email protected]2c62b3f2012-04-12 12:07:50766 preload_engines_.GetValue());
767
768 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_|
769 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request
770 // might be ignored as an invalid input method ID. The ChangeInputMethod()
771 // calls are also necessary to restore the previous/current input method prefs
772 // which could have been modified by the SetLanguageConfigStringListAsCSV call
773 // above to the original state.
774 if (!previous_input_method_id.empty())
775 input_method_manager_->ChangeInputMethod(previous_input_method_id);
776 if (!current_input_method_id.empty())
777 input_method_manager_->ChangeInputMethod(current_input_method_id);
778}
779
[email protected]a995b392010-08-11 04:38:59780void Preferences::UpdateAutoRepeatRate() {
[email protected]20979d492012-02-15 09:26:02781 // Avoid setting repeat rate on desktop dev environment.
[email protected]20d2a79d2012-03-16 23:01:02782 if (!base::chromeos::IsRunningOnChromeOS())
[email protected]20979d492012-02-15 09:26:02783 return;
784
[email protected]c010f632011-04-01 06:44:39785 input_method::AutoRepeatRate rate;
[email protected]c67a30932012-03-14 05:23:00786 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue();
787 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue();
[email protected]a995b392010-08-11 04:38:59788 DCHECK(rate.initial_delay_in_ms > 0);
789 DCHECK(rate.repeat_interval_in_ms > 0);
[email protected]cf61f6b0a2013-01-03 00:34:12790 input_method::XKeyboard::SetAutoRepeatRate(rate);
[email protected]a995b392010-08-11 04:38:59791}
792
[email protected]fecc1522009-10-15 21:08:29793} // namespace chromeos