blob: 6be339aa537df02662abb14ebb2a1fcceb7c8129 [file] [log] [blame]
[email protected]2b2820a2011-03-07 22:28:401// Copyright (c) 2011 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]775caec2011-09-01 17:14:327#include "base/command_line.h"
[email protected]530cd622011-04-14 15:45:008#include "base/i18n/time_formatting.h"
[email protected]d7ca1ba2011-05-09 20:09:089#include "base/metrics/histogram.h"
[email protected]4e5ae20f2010-09-24 04:52:1110#include "base/string_split.h"
[email protected]fecc1522009-10-15 21:08:2911#include "base/string_util.h"
[email protected]50951432010-03-31 12:12:4212#include "base/utf_string_conversions.h"
[email protected]c0a2128d92011-07-20 15:04:4613#include "chrome/browser/browser_process.h"
[email protected]c8d4e9462011-06-29 23:18:5714#include "chrome/browser/chromeos/input_method/input_method_manager.h"
[email protected]9199bd52010-07-01 05:04:4115#include "chrome/browser/chromeos/input_method/input_method_util.h"
[email protected]c010f632011-04-01 06:44:3916#include "chrome/browser/chromeos/input_method/xkeyboard.h"
[email protected]26012e22010-12-01 06:44:2717#include "chrome/browser/chromeos/login/login_utils.h"
[email protected]a329ebe2011-11-22 23:26:4918#include "chrome/browser/chromeos/system/screen_locker_settings.h"
[email protected]1cbfb3b2011-07-11 23:34:0819#include "chrome/browser/chromeos/system/touchpad_settings.h"
[email protected]37858e52010-08-26 00:22:0220#include "chrome/browser/prefs/pref_member.h"
21#include "chrome/browser/prefs/pref_service.h"
[email protected]b3362572011-08-17 09:28:5022#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]432115822011-07-10 15:52:2723#include "chrome/common/chrome_notification_types.h"
[email protected]775caec2011-09-01 17:14:3224#include "chrome/common/chrome_switches.h"
[email protected]fecc1522009-10-15 21:08:2925#include "chrome/common/pref_names.h"
[email protected]86ab86b2011-10-19 03:07:5526#include "content/public/browser/notification_details.h"
27#include "content/public/browser/notification_source.h"
[email protected]6f96cbcb2011-11-04 02:26:0728#include "googleurl/src/gurl.h"
[email protected]fecc1522009-10-15 21:08:2929#include "unicode/timezone.h"
30
31namespace chromeos {
32
[email protected]9199bd52010-07-01 05:04:4133static const char kFallbackInputMethodLocale[] = "en-US";
[email protected]4793c942010-09-21 23:17:1734
[email protected]d743a5982010-11-08 17:54:0935Preferences::Preferences() {}
36
37Preferences::~Preferences() {}
[email protected]9199bd52010-07-01 05:04:4138
[email protected]fecc1522009-10-15 21:08:2939// static
40void Preferences::RegisterUserPrefs(PrefService* prefs) {
[email protected]a9a81812011-09-16 11:01:1741 input_method::InputMethodManager* manager =
42 input_method::InputMethodManager::GetInstance();
43
[email protected]d36f941b2011-05-09 06:19:1644 prefs->RegisterBooleanPref(prefs::kTapToClickEnabled,
45 false,
46 PrefService::SYNCABLE_PREF);
47 prefs->RegisterBooleanPref(prefs::kLabsMediaplayerEnabled,
48 false,
49 PrefService::UNSYNCABLE_PREF);
50 prefs->RegisterBooleanPref(prefs::kLabsAdvancedFilesystemEnabled,
51 false,
52 PrefService::UNSYNCABLE_PREF);
[email protected]27f20d52010-09-18 00:59:3153 // Check if the accessibility pref is already registered, which can happen
54 // in WizardController::RegisterPrefs. We still want to try to register
55 // the pref here in case of Chrome/Linux with ChromeOS=1.
[email protected]7ef254b2011-12-08 03:24:4556 if (prefs->FindPreference(prefs::kSpokenFeedbackEnabled) == NULL) {
57 prefs->RegisterBooleanPref(prefs::kSpokenFeedbackEnabled,
[email protected]d36f941b2011-05-09 06:19:1658 false,
59 PrefService::UNSYNCABLE_PREF);
[email protected]27f20d52010-09-18 00:59:3160 }
[email protected]d36f941b2011-05-09 06:19:1661 prefs->RegisterIntegerPref(prefs::kTouchpadSensitivity,
62 3,
63 PrefService::UNSYNCABLE_PREF);
[email protected]530cd622011-04-14 15:45:0064 prefs->RegisterBooleanPref(prefs::kUse24HourClock,
[email protected]d36f941b2011-05-09 06:19:1665 base::GetHourClockType() == base::k24HourClock,
66 PrefService::SYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:1067 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod
68 // because they're just used to track the logout state of the device.
[email protected]d36f941b2011-05-09 06:19:1669 prefs->RegisterStringPref(prefs::kLanguageCurrentInputMethod,
70 "",
71 PrefService::UNSYNCABLE_PREF);
72 prefs->RegisterStringPref(prefs::kLanguagePreviousInputMethod,
73 "",
74 PrefService::UNSYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:1075 // We don't sync input method hotkeys since they're not configurable.
[email protected]3b02de292010-05-13 06:05:0576 prefs->RegisterStringPref(prefs::kLanguageHotkeyNextEngineInMenu,
[email protected]d36f941b2011-05-09 06:19:1677 language_prefs::kHotkeyNextEngineInMenu,
78 PrefService::UNSYNCABLE_PREF);
[email protected]3b02de292010-05-13 06:05:0579 prefs->RegisterStringPref(prefs::kLanguageHotkeyPreviousEngine,
[email protected]d36f941b2011-05-09 06:19:1680 language_prefs::kHotkeyPreviousEngine,
81 PrefService::UNSYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:1082 // We don't sync the list of input methods and preferred languages since a
83 // user might use two or more devices with different hardware keyboards.
84 // crosbug.com/15181
[email protected]c5d45432010-09-07 08:25:3585 prefs->RegisterStringPref(prefs::kLanguagePreferredLanguages,
[email protected]d36f941b2011-05-09 06:19:1686 kFallbackInputMethodLocale,
[email protected]aa96e372011-05-16 06:23:1087 PrefService::UNSYNCABLE_PREF);
[email protected]a9a81812011-09-16 11:01:1788 prefs->RegisterStringPref(
89 prefs::kLanguagePreloadEngines,
90 manager->GetInputMethodUtil()->GetHardwareInputMethodId(),
91 PrefService::UNSYNCABLE_PREF);
[email protected]b65c5d22010-08-20 02:50:2392 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
93 prefs->RegisterBooleanPref(
94 language_prefs::kChewingBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:1695 language_prefs::kChewingBooleanPrefs[i].default_pref_value,
96 PrefService::UNSYNCABLE_PREF);
[email protected]525dbe22010-06-01 07:05:4397 }
[email protected]b65c5d22010-08-20 02:50:2398 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:4399 prefs->RegisterStringPref(
[email protected]b65c5d22010-08-20 02:50:23100 language_prefs::kChewingMultipleChoicePrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16101 language_prefs::kChewingMultipleChoicePrefs[i].default_pref_value,
102 PrefService::UNSYNCABLE_PREF);
[email protected]525dbe22010-06-01 07:05:43103 }
[email protected]b65c5d22010-08-20 02:50:23104 prefs->RegisterIntegerPref(
105 language_prefs::kChewingHsuSelKeyType.pref_name,
[email protected]d36f941b2011-05-09 06:19:16106 language_prefs::kChewingHsuSelKeyType.default_pref_value,
107 PrefService::UNSYNCABLE_PREF);
[email protected]7ac5af92010-06-07 01:25:44108
[email protected]b65c5d22010-08-20 02:50:23109 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
110 prefs->RegisterIntegerPref(
111 language_prefs::kChewingIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16112 language_prefs::kChewingIntegerPrefs[i].default_pref_value,
113 PrefService::UNSYNCABLE_PREF);
[email protected]15c53082010-06-03 03:28:21114 }
[email protected]20ce516d2010-06-18 02:20:04115 prefs->RegisterStringPref(
116 prefs::kLanguageHangulKeyboard,
[email protected]d36f941b2011-05-09 06:19:16117 language_prefs::kHangulKeyboardNameIDPairs[0].keyboard_id,
118 PrefService::SYNCABLE_PREF);
[email protected]33444cf2011-08-04 06:33:55119 prefs->RegisterStringPref(prefs::kLanguageHangulHanjaBindingKeys,
120 language_prefs::kHangulHanjaBindingKeys,
121 // Don't sync the pref as it's not user-configurable
122 PrefService::UNSYNCABLE_PREF);
[email protected]b65c5d22010-08-20 02:50:23123 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
124 prefs->RegisterBooleanPref(
125 language_prefs::kPinyinBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16126 language_prefs::kPinyinBooleanPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51127 language_prefs::kPinyinBooleanPrefs[i].sync_status);
[email protected]9040ad22010-04-22 04:29:28128 }
[email protected]b65c5d22010-08-20 02:50:23129 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
130 prefs->RegisterIntegerPref(
131 language_prefs::kPinyinIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16132 language_prefs::kPinyinIntegerPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51133 language_prefs::kPinyinIntegerPrefs[i].sync_status);
[email protected]6e5c4b82010-05-24 08:18:44134 }
[email protected]b65c5d22010-08-20 02:50:23135 prefs->RegisterIntegerPref(
136 language_prefs::kPinyinDoublePinyinSchema.pref_name,
[email protected]d36f941b2011-05-09 06:19:16137 language_prefs::kPinyinDoublePinyinSchema.default_pref_value,
138 PrefService::UNSYNCABLE_PREF);
[email protected]7ac5af92010-06-07 01:25:44139
[email protected]b65c5d22010-08-20 02:50:23140 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
141 prefs->RegisterBooleanPref(
142 language_prefs::kMozcBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16143 language_prefs::kMozcBooleanPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51144 language_prefs::kMozcBooleanPrefs[i].sync_status);
[email protected]8a1ace22010-06-10 05:38:25145 }
[email protected]b65c5d22010-08-20 02:50:23146 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
[email protected]7ac5af92010-06-07 01:25:44147 prefs->RegisterStringPref(
[email protected]b65c5d22010-08-20 02:50:23148 language_prefs::kMozcMultipleChoicePrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16149 language_prefs::kMozcMultipleChoicePrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51150 language_prefs::kMozcMultipleChoicePrefs[i].sync_status);
[email protected]9040ad22010-04-22 04:29:28151 }
[email protected]b65c5d22010-08-20 02:50:23152 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
153 prefs->RegisterIntegerPref(
154 language_prefs::kMozcIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16155 language_prefs::kMozcIntegerPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51156 language_prefs::kMozcIntegerPrefs[i].sync_status);
[email protected]54037462010-06-22 02:06:23157 }
[email protected]c010f632011-04-01 06:44:39158 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapSearchKeyTo,
[email protected]d36f941b2011-05-09 06:19:16159 input_method::kSearchKey,
160 PrefService::SYNCABLE_PREF);
[email protected]b5194dd32010-08-12 10:40:04161 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapControlKeyTo,
[email protected]d36f941b2011-05-09 06:19:16162 input_method::kLeftControlKey,
163 PrefService::SYNCABLE_PREF);
[email protected]c010f632011-04-01 06:44:39164 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapAltKeyTo,
[email protected]d36f941b2011-05-09 06:19:16165 input_method::kLeftAltKey,
166 PrefService::SYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:10167 // We don't sync the following keyboard prefs since they are not user-
168 // configurable.
[email protected]d36f941b2011-05-09 06:19:16169 prefs->RegisterBooleanPref(prefs::kLanguageXkbAutoRepeatEnabled,
170 true,
171 PrefService::UNSYNCABLE_PREF);
[email protected]4743dad2010-08-30 01:41:07172 prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatDelay,
[email protected]d36f941b2011-05-09 06:19:16173 language_prefs::kXkbAutoRepeatDelayInMs,
174 PrefService::UNSYNCABLE_PREF);
[email protected]4743dad2010-08-30 01:41:07175 prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatInterval,
[email protected]d36f941b2011-05-09 06:19:16176 language_prefs::kXkbAutoRepeatIntervalInMs,
177 PrefService::UNSYNCABLE_PREF);
[email protected]4ccc05e2010-10-06 19:32:15178
[email protected]f410d612011-08-05 04:32:24179 prefs->RegisterDictionaryPref(prefs::kLanguagePreferredVirtualKeyboard,
180 PrefService::SYNCABLE_PREF);
181
[email protected]4ccc05e2010-10-06 19:32:15182 // Screen lock default to off.
[email protected]d36f941b2011-05-09 06:19:16183 prefs->RegisterBooleanPref(prefs::kEnableScreenLock,
184 false,
185 PrefService::SYNCABLE_PREF);
[email protected]ea1eba52010-11-23 18:05:38186
187 // Mobile plan notifications default to on.
[email protected]d36f941b2011-05-09 06:19:16188 prefs->RegisterBooleanPref(prefs::kShowPlanNotifications,
189 true,
190 PrefService::SYNCABLE_PREF);
[email protected]c74fffa2011-04-27 13:32:24191
192 // 3G first-time usage promo will be shown at least once.
[email protected]d36f941b2011-05-09 06:19:16193 prefs->RegisterBooleanPref(prefs::kShow3gPromoNotification,
194 true,
195 PrefService::UNSYNCABLE_PREF);
[email protected]d6ae9502011-05-05 18:23:09196
[email protected]cc8f2472011-08-01 07:14:46197 // OAuth1 all access token and secret pair.
198 prefs->RegisterStringPref(prefs::kOAuth1Token,
199 "",
200 PrefService::UNSYNCABLE_PREF);
201 prefs->RegisterStringPref(prefs::kOAuth1Secret,
202 "",
203 PrefService::UNSYNCABLE_PREF);
[email protected]fecc1522009-10-15 21:08:29204}
205
206void Preferences::Init(PrefService* prefs) {
[email protected]fecc1522009-10-15 21:08:29207 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this);
[email protected]7ef254b2011-12-08 03:24:45208 accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, prefs, this);
[email protected]fecc1522009-10-15 21:08:29209 sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, this);
[email protected]530cd622011-04-14 15:45:00210 use_24hour_clock_.Init(prefs::kUse24HourClock, prefs, this);
[email protected]3b02de292010-05-13 06:05:05211 language_hotkey_next_engine_in_menu_.Init(
212 prefs::kLanguageHotkeyNextEngineInMenu, prefs, this);
213 language_hotkey_previous_engine_.Init(
214 prefs::kLanguageHotkeyPreviousEngine, prefs, this);
[email protected]74b42fc12010-07-20 10:15:41215 language_preferred_languages_.Init(prefs::kLanguagePreferredLanguages,
216 prefs, this);
[email protected]70aa5b32010-04-05 08:30:34217 language_preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, this);
[email protected]b65c5d22010-08-20 02:50:23218 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:43219 language_chewing_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23220 language_prefs::kChewingBooleanPrefs[i].pref_name, prefs, this);
[email protected]525dbe22010-06-01 07:05:43221 }
[email protected]b65c5d22010-08-20 02:50:23222 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:43223 language_chewing_multiple_choice_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23224 language_prefs::kChewingMultipleChoicePrefs[i].pref_name, prefs, this);
[email protected]525dbe22010-06-01 07:05:43225 }
[email protected]7ac5af92010-06-07 01:25:44226 language_chewing_hsu_sel_key_type_.Init(
[email protected]b65c5d22010-08-20 02:50:23227 language_prefs::kChewingHsuSelKeyType.pref_name, prefs, this);
228 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
[email protected]15c53082010-06-03 03:28:21229 language_chewing_integer_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23230 language_prefs::kChewingIntegerPrefs[i].pref_name, prefs, this);
[email protected]15c53082010-06-03 03:28:21231 }
[email protected]50951432010-03-31 12:12:42232 language_hangul_keyboard_.Init(prefs::kLanguageHangulKeyboard, prefs, this);
[email protected]33444cf2011-08-04 06:33:55233 language_hangul_hanja_binding_keys_.Init(
234 prefs::kLanguageHangulHanjaBindingKeys, prefs, this);
[email protected]b65c5d22010-08-20 02:50:23235 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
[email protected]9040ad22010-04-22 04:29:28236 language_pinyin_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23237 language_prefs::kPinyinBooleanPrefs[i].pref_name, prefs, this);
[email protected]9040ad22010-04-22 04:29:28238 }
[email protected]b65c5d22010-08-20 02:50:23239 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
[email protected]9040ad22010-04-22 04:29:28240 language_pinyin_int_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23241 language_prefs::kPinyinIntegerPrefs[i].pref_name, prefs, this);
[email protected]9040ad22010-04-22 04:29:28242 }
[email protected]7ac5af92010-06-07 01:25:44243 language_pinyin_double_pinyin_schema_.Init(
[email protected]b65c5d22010-08-20 02:50:23244 language_prefs::kPinyinDoublePinyinSchema.pref_name, prefs, this);
245 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
[email protected]8a1ace22010-06-10 05:38:25246 language_mozc_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23247 language_prefs::kMozcBooleanPrefs[i].pref_name, prefs, this);
[email protected]8a1ace22010-06-10 05:38:25248 }
[email protected]b65c5d22010-08-20 02:50:23249 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
[email protected]6e5c4b82010-05-24 08:18:44250 language_mozc_multiple_choice_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23251 language_prefs::kMozcMultipleChoicePrefs[i].pref_name, prefs, this);
[email protected]6e5c4b82010-05-24 08:18:44252 }
[email protected]b65c5d22010-08-20 02:50:23253 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
[email protected]54037462010-06-22 02:06:23254 language_mozc_integer_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23255 language_prefs::kMozcIntegerPrefs[i].pref_name, prefs, this);
[email protected]54037462010-06-22 02:06:23256 }
[email protected]b5194dd32010-08-12 10:40:04257 language_xkb_remap_search_key_to_.Init(
258 prefs::kLanguageXkbRemapSearchKeyTo, prefs, this);
259 language_xkb_remap_control_key_to_.Init(
260 prefs::kLanguageXkbRemapControlKeyTo, prefs, this);
261 language_xkb_remap_alt_key_to_.Init(
262 prefs::kLanguageXkbRemapAltKeyTo, prefs, this);
[email protected]a995b392010-08-11 04:38:59263 language_xkb_auto_repeat_enabled_.Init(
264 prefs::kLanguageXkbAutoRepeatEnabled, prefs, this);
265 language_xkb_auto_repeat_delay_pref_.Init(
[email protected]4743dad2010-08-30 01:41:07266 prefs::kLanguageXkbAutoRepeatDelay, prefs, this);
[email protected]a995b392010-08-11 04:38:59267 language_xkb_auto_repeat_interval_pref_.Init(
[email protected]4743dad2010-08-30 01:41:07268 prefs::kLanguageXkbAutoRepeatInterval, prefs, this);
[email protected]fecc1522009-10-15 21:08:29269
[email protected]4ccc05e2010-10-06 19:32:15270 enable_screen_lock_.Init(prefs::kEnableScreenLock, prefs, this);
271
[email protected]d7ca1ba2011-05-09 20:09:08272 // Initialize preferences to currently saved state.
[email protected]fecc1522009-10-15 21:08:29273 NotifyPrefChanged(NULL);
[email protected]26012e22010-12-01 06:44:27274
[email protected]f410d612011-08-05 04:32:24275 // Initialize virtual keyboard settings to currently saved state.
276 UpdateVirturalKeyboardPreference(prefs);
277
[email protected]26012e22010-12-01 06:44:27278 // If a guest is logged in, initialize the prefs as if this is the first
279 // login.
280 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) {
281 LoginUtils::Get()->SetFirstLoginPrefs(prefs);
282 }
[email protected]fecc1522009-10-15 21:08:29283}
284
[email protected]432115822011-07-10 15:52:27285void Preferences::Observe(int type,
[email protected]86ab86b2011-10-19 03:07:55286 const content::NotificationSource& source,
287 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27288 if (type == chrome::NOTIFICATION_PREF_CHANGED)
[email protected]a0bbc402011-10-19 04:28:30289 NotifyPrefChanged(content::Details<std::string>(details).ptr());
[email protected]fecc1522009-10-15 21:08:29290}
291
[email protected]57ecc4b2010-08-11 03:02:51292void Preferences::NotifyPrefChanged(const std::string* pref_name) {
[email protected]3b02de292010-05-13 06:05:05293 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) {
[email protected]d7ca1ba2011-05-09 20:09:08294 bool enabled = tap_to_click_enabled_.GetValue();
[email protected]1cbfb3b2011-07-11 23:34:08295 system::touchpad_settings::SetTapToClick(enabled);
[email protected]d7ca1ba2011-05-09 20:09:08296 if (pref_name)
297 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled);
298 else
299 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Started", enabled);
[email protected]3b02de292010-05-13 06:05:05300 }
[email protected]3b02de292010-05-13 06:05:05301 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) {
[email protected]d7ca1ba2011-05-09 20:09:08302 int sensitivity = sensitivity_.GetValue();
[email protected]1cbfb3b2011-07-11 23:34:08303 system::touchpad_settings::SetSensitivity(sensitivity);
[email protected]d7ca1ba2011-05-09 20:09:08304 if (pref_name) {
305 UMA_HISTOGRAM_CUSTOM_COUNTS(
306 "Touchpad.Sensitivity.Changed", sensitivity, 1, 5, 5);
307 } else {
308 UMA_HISTOGRAM_CUSTOM_COUNTS(
309 "Touchpad.Sensitivity.Started", sensitivity, 1, 5, 5);
310 }
[email protected]3b02de292010-05-13 06:05:05311 }
[email protected]8be9ff22010-06-08 02:13:54312
313 // We don't handle prefs::kLanguageCurrentInputMethod and PreviousInputMethod
314 // here.
315
[email protected]3b02de292010-05-13 06:05:05316 if (!pref_name || *pref_name == prefs::kLanguageHotkeyNextEngineInMenu) {
[email protected]ddd231e2010-06-29 20:35:19317 SetLanguageConfigStringListAsCSV(
[email protected]b65c5d22010-08-20 02:50:23318 language_prefs::kHotKeySectionName,
319 language_prefs::kNextEngineInMenuConfigName,
[email protected]ddd231e2010-06-29 20:35:19320 language_hotkey_next_engine_in_menu_.GetValue());
[email protected]3b02de292010-05-13 06:05:05321 }
322 if (!pref_name || *pref_name == prefs::kLanguageHotkeyPreviousEngine) {
[email protected]ddd231e2010-06-29 20:35:19323 SetLanguageConfigStringListAsCSV(
[email protected]b65c5d22010-08-20 02:50:23324 language_prefs::kHotKeySectionName,
325 language_prefs::kPreviousEngineConfigName,
[email protected]ddd231e2010-06-29 20:35:19326 language_hotkey_previous_engine_.GetValue());
[email protected]3b02de292010-05-13 06:05:05327 }
[email protected]74b42fc12010-07-20 10:15:41328 if (!pref_name || *pref_name == prefs::kLanguagePreferredLanguages) {
329 // Unlike kLanguagePreloadEngines and some other input method
330 // preferencs, we don't need to send this to ibus-daemon.
331 }
[email protected]a6e90772011-02-09 05:38:54332
333 // Here, we set up the the modifier key mapping. This has to be done
334 // before changing the current keyboard layout, so that the modifier key
335 // preference is properly preserved. For this reason, we should do this
336 // before setting preload engines, that could change the current
337 // keyboard layout as needed.
338 if (!pref_name || (*pref_name == prefs::kLanguageXkbRemapSearchKeyTo ||
339 *pref_name == prefs::kLanguageXkbRemapControlKeyTo ||
340 *pref_name == prefs::kLanguageXkbRemapAltKeyTo)) {
341 UpdateModifierKeyMapping();
342 }
343 if (!pref_name || *pref_name == prefs::kLanguageXkbAutoRepeatEnabled) {
344 const bool enabled = language_xkb_auto_repeat_enabled_.GetValue();
[email protected]e6e83362011-09-16 07:28:00345 input_method::XKeyboard::SetAutoRepeatEnabled(enabled);
[email protected]a6e90772011-02-09 05:38:54346 }
347 if (!pref_name || ((*pref_name == prefs::kLanguageXkbAutoRepeatDelay) ||
348 (*pref_name == prefs::kLanguageXkbAutoRepeatInterval))) {
349 UpdateAutoRepeatRate();
350 }
351
[email protected]3b02de292010-05-13 06:05:05352 if (!pref_name || *pref_name == prefs::kLanguagePreloadEngines) {
[email protected]b65c5d22010-08-20 02:50:23353 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
354 language_prefs::kPreloadEnginesConfigName,
[email protected]d01bb8072010-04-12 13:00:15355 language_preload_engines_.GetValue());
[email protected]3b02de292010-05-13 06:05:05356 }
[email protected]b65c5d22010-08-20 02:50:23357 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
358 if (!pref_name ||
359 *pref_name == language_prefs::kChewingBooleanPrefs[i].pref_name) {
360 SetLanguageConfigBoolean(
361 language_prefs::kChewingSectionName,
362 language_prefs::kChewingBooleanPrefs[i].ibus_config_name,
363 language_chewing_boolean_prefs_[i].GetValue());
[email protected]525dbe22010-06-01 07:05:43364 }
365 }
[email protected]b65c5d22010-08-20 02:50:23366 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
367 if (!pref_name ||
368 *pref_name ==
369 language_prefs::kChewingMultipleChoicePrefs[i].pref_name) {
[email protected]525dbe22010-06-01 07:05:43370 SetLanguageConfigString(
[email protected]b65c5d22010-08-20 02:50:23371 language_prefs::kChewingSectionName,
372 language_prefs::kChewingMultipleChoicePrefs[i].ibus_config_name,
[email protected]525dbe22010-06-01 07:05:43373 language_chewing_multiple_choice_prefs_[i].GetValue());
374 }
375 }
[email protected]b65c5d22010-08-20 02:50:23376 if (!pref_name ||
377 *pref_name == language_prefs::kChewingHsuSelKeyType.pref_name) {
[email protected]7ac5af92010-06-07 01:25:44378 SetLanguageConfigInteger(
[email protected]b65c5d22010-08-20 02:50:23379 language_prefs::kChewingSectionName,
380 language_prefs::kChewingHsuSelKeyType.ibus_config_name,
[email protected]7ac5af92010-06-07 01:25:44381 language_chewing_hsu_sel_key_type_.GetValue());
382 }
[email protected]b65c5d22010-08-20 02:50:23383 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
384 if (!pref_name ||
385 *pref_name == language_prefs::kChewingIntegerPrefs[i].pref_name) {
386 SetLanguageConfigInteger(
387 language_prefs::kChewingSectionName,
388 language_prefs::kChewingIntegerPrefs[i].ibus_config_name,
389 language_chewing_integer_prefs_[i].GetValue());
[email protected]15c53082010-06-03 03:28:21390 }
391 }
[email protected]b65c5d22010-08-20 02:50:23392 if (!pref_name ||
393 *pref_name == prefs::kLanguageHangulKeyboard) {
394 SetLanguageConfigString(language_prefs::kHangulSectionName,
395 language_prefs::kHangulKeyboardConfigName,
[email protected]50951432010-03-31 12:12:42396 language_hangul_keyboard_.GetValue());
[email protected]3b02de292010-05-13 06:05:05397 }
[email protected]33444cf2011-08-04 06:33:55398 if (!pref_name || *pref_name == prefs::kLanguageHangulHanjaBindingKeys) {
399 SetLanguageConfigString(language_prefs::kHangulSectionName,
400 language_prefs::kHangulHanjaBindingKeysConfigName,
401 language_hangul_hanja_binding_keys_.GetValue());
402 }
[email protected]b65c5d22010-08-20 02:50:23403 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
404 if (!pref_name ||
405 *pref_name == language_prefs::kPinyinBooleanPrefs[i].pref_name) {
406 SetLanguageConfigBoolean(
407 language_prefs::kPinyinSectionName,
408 language_prefs::kPinyinBooleanPrefs[i].ibus_config_name,
409 language_pinyin_boolean_prefs_[i].GetValue());
[email protected]9040ad22010-04-22 04:29:28410 }
411 }
[email protected]b65c5d22010-08-20 02:50:23412 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
413 if (!pref_name ||
414 *pref_name == language_prefs::kPinyinIntegerPrefs[i].pref_name) {
415 SetLanguageConfigInteger(
416 language_prefs::kPinyinSectionName,
417 language_prefs::kPinyinIntegerPrefs[i].ibus_config_name,
418 language_pinyin_int_prefs_[i].GetValue());
[email protected]9040ad22010-04-22 04:29:28419 }
420 }
[email protected]b65c5d22010-08-20 02:50:23421 if (!pref_name ||
422 *pref_name == language_prefs::kPinyinDoublePinyinSchema.pref_name) {
[email protected]7ac5af92010-06-07 01:25:44423 SetLanguageConfigInteger(
[email protected]b65c5d22010-08-20 02:50:23424 language_prefs::kPinyinSectionName,
425 language_prefs::kPinyinDoublePinyinSchema.ibus_config_name,
[email protected]7ac5af92010-06-07 01:25:44426 language_pinyin_double_pinyin_schema_.GetValue());
427 }
[email protected]b65c5d22010-08-20 02:50:23428 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
429 if (!pref_name ||
430 *pref_name == language_prefs::kMozcBooleanPrefs[i].pref_name) {
431 SetLanguageConfigBoolean(
432 language_prefs::kMozcSectionName,
433 language_prefs::kMozcBooleanPrefs[i].ibus_config_name,
434 language_mozc_boolean_prefs_[i].GetValue());
[email protected]8a1ace22010-06-10 05:38:25435 }
436 }
[email protected]b65c5d22010-08-20 02:50:23437 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
438 if (!pref_name ||
439 *pref_name == language_prefs::kMozcMultipleChoicePrefs[i].pref_name) {
[email protected]6e5c4b82010-05-24 08:18:44440 SetLanguageConfigString(
[email protected]b65c5d22010-08-20 02:50:23441 language_prefs::kMozcSectionName,
442 language_prefs::kMozcMultipleChoicePrefs[i].ibus_config_name,
[email protected]6e5c4b82010-05-24 08:18:44443 language_mozc_multiple_choice_prefs_[i].GetValue());
444 }
445 }
[email protected]b65c5d22010-08-20 02:50:23446 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
447 if (!pref_name ||
448 *pref_name == language_prefs::kMozcIntegerPrefs[i].pref_name) {
449 SetLanguageConfigInteger(
450 language_prefs::kMozcSectionName,
451 language_prefs::kMozcIntegerPrefs[i].ibus_config_name,
452 language_mozc_integer_prefs_[i].GetValue());
[email protected]54037462010-06-22 02:06:23453 }
454 }
[email protected]4793c942010-09-21 23:17:17455
[email protected]4ccc05e2010-10-06 19:32:15456 // Init or update power manager config.
457 if (!pref_name || *pref_name == prefs::kEnableScreenLock) {
[email protected]a329ebe2011-11-22 23:26:49458 system::screen_locker_settings::EnableScreenLock(
[email protected]4ccc05e2010-10-06 19:32:15459 enable_screen_lock_.GetValue());
460 }
[email protected]fecc1522009-10-15 21:08:29461}
462
[email protected]70aa5b32010-04-05 08:30:34463void Preferences::SetLanguageConfigBoolean(const char* section,
464 const char* name,
465 bool value) {
[email protected]dc7b0942011-06-15 06:45:53466 input_method::ImeConfigValue config;
467 config.type = input_method::ImeConfigValue::kValueTypeBool;
[email protected]70aa5b32010-04-05 08:30:34468 config.bool_value = value;
[email protected]c8d4e9462011-06-29 23:18:57469 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28470 SetImeConfig(section, name, config);
[email protected]70aa5b32010-04-05 08:30:34471}
472
[email protected]9040ad22010-04-22 04:29:28473void Preferences::SetLanguageConfigInteger(const char* section,
474 const char* name,
475 int value) {
[email protected]dc7b0942011-06-15 06:45:53476 input_method::ImeConfigValue config;
477 config.type = input_method::ImeConfigValue::kValueTypeInt;
[email protected]9040ad22010-04-22 04:29:28478 config.int_value = value;
[email protected]c8d4e9462011-06-29 23:18:57479 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28480 SetImeConfig(section, name, config);
[email protected]9040ad22010-04-22 04:29:28481}
482
[email protected]50951432010-03-31 12:12:42483void Preferences::SetLanguageConfigString(const char* section,
484 const char* name,
[email protected]ddd231e2010-06-29 20:35:19485 const std::string& value) {
[email protected]dc7b0942011-06-15 06:45:53486 input_method::ImeConfigValue config;
487 config.type = input_method::ImeConfigValue::kValueTypeString;
[email protected]ddd231e2010-06-29 20:35:19488 config.string_value = value;
[email protected]c8d4e9462011-06-29 23:18:57489 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28490 SetImeConfig(section, name, config);
[email protected]50951432010-03-31 12:12:42491}
492
[email protected]2c25ddfd2010-04-09 10:35:55493void Preferences::SetLanguageConfigStringList(
494 const char* section,
495 const char* name,
[email protected]ddd231e2010-06-29 20:35:19496 const std::vector<std::string>& values) {
[email protected]dc7b0942011-06-15 06:45:53497 input_method::ImeConfigValue config;
498 config.type = input_method::ImeConfigValue::kValueTypeStringList;
[email protected]ddd231e2010-06-29 20:35:19499 for (size_t i = 0; i < values.size(); ++i)
500 config.string_list_value.push_back(values[i]);
501
[email protected]c8d4e9462011-06-29 23:18:57502 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28503 SetImeConfig(section, name, config);
[email protected]2c25ddfd2010-04-09 10:35:55504}
505
[email protected]d01bb8072010-04-12 13:00:15506void Preferences::SetLanguageConfigStringListAsCSV(const char* section,
507 const char* name,
[email protected]ddd231e2010-06-29 20:35:19508 const std::string& value) {
[email protected]e24c2c92010-10-23 01:39:24509 VLOG(1) << "Setting " << name << " to '" << value << "'";
[email protected]d01bb8072010-04-12 13:00:15510
[email protected]ddd231e2010-06-29 20:35:19511 std::vector<std::string> split_values;
512 if (!value.empty())
[email protected]76eb0242010-10-14 00:35:36513 base::SplitString(value, ',', &split_values);
[email protected]ddd231e2010-06-29 20:35:19514
[email protected]2c25ddfd2010-04-09 10:35:55515 // We should call the cros API even when |value| is empty, to disable default
[email protected]d01bb8072010-04-12 13:00:15516 // config.
517 SetLanguageConfigStringList(section, name, split_values);
[email protected]70aa5b32010-04-05 08:30:34518}
519
[email protected]b5194dd32010-08-12 10:40:04520void Preferences::UpdateModifierKeyMapping() {
521 const int search_remap = language_xkb_remap_search_key_to_.GetValue();
522 const int control_remap = language_xkb_remap_control_key_to_.GetValue();
523 const int alt_remap = language_xkb_remap_alt_key_to_.GetValue();
[email protected]c010f632011-04-01 06:44:39524 if ((search_remap < input_method::kNumModifierKeys) && (search_remap >= 0) &&
525 (control_remap < input_method::kNumModifierKeys) &&
526 (control_remap >= 0) &&
527 (alt_remap < input_method::kNumModifierKeys) && (alt_remap >= 0)) {
528 input_method::ModifierMap modifier_map;
[email protected]b5194dd32010-08-12 10:40:04529 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39530 input_method::ModifierKeyPair(
531 input_method::kSearchKey,
532 input_method::ModifierKey(search_remap)));
[email protected]b5194dd32010-08-12 10:40:04533 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39534 input_method::ModifierKeyPair(
535 input_method::kLeftControlKey,
536 input_method::ModifierKey(control_remap)));
[email protected]b5194dd32010-08-12 10:40:04537 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39538 input_method::ModifierKeyPair(
539 input_method::kLeftAltKey,
540 input_method::ModifierKey(alt_remap)));
[email protected]e6e83362011-09-16 07:28:00541 input_method::InputMethodManager::GetInstance()->GetXKeyboard()->
542 RemapModifierKeys(modifier_map);
[email protected]b5194dd32010-08-12 10:40:04543 } else {
544 LOG(ERROR) << "Failed to remap modifier keys. Unexpected value(s): "
545 << search_remap << ", " << control_remap << ", " << alt_remap;
546 }
547}
548
[email protected]a995b392010-08-11 04:38:59549void Preferences::UpdateAutoRepeatRate() {
[email protected]c010f632011-04-01 06:44:39550 input_method::AutoRepeatRate rate;
[email protected]a995b392010-08-11 04:38:59551 rate.initial_delay_in_ms = language_xkb_auto_repeat_delay_pref_.GetValue();
552 rate.repeat_interval_in_ms =
553 language_xkb_auto_repeat_interval_pref_.GetValue();
554 DCHECK(rate.initial_delay_in_ms > 0);
555 DCHECK(rate.repeat_interval_in_ms > 0);
[email protected]e6e83362011-09-16 07:28:00556 input_method::XKeyboard::SetAutoRepeatRate(rate);
[email protected]a995b392010-08-11 04:38:59557}
558
[email protected]f410d612011-08-05 04:32:24559void Preferences::UpdateVirturalKeyboardPreference(PrefService* prefs) {
560 const DictionaryValue* virtual_keyboard_pref =
561 prefs->GetDictionary(prefs::kLanguagePreferredVirtualKeyboard);
562 DCHECK(virtual_keyboard_pref);
563
564 input_method::InputMethodManager* input_method_manager =
565 input_method::InputMethodManager::GetInstance();
566 input_method_manager->ClearAllVirtualKeyboardPreferences();
567
568 std::string url;
[email protected]b3362572011-08-17 09:28:50569 std::vector<std::string> layouts_to_remove;
[email protected]f410d612011-08-05 04:32:24570 for (DictionaryValue::key_iterator iter = virtual_keyboard_pref->begin_keys();
571 iter != virtual_keyboard_pref->end_keys();
572 ++iter) {
[email protected]b3362572011-08-17 09:28:50573 const std::string& layout_id = *iter; // e.g. "us", "handwriting-vk"
574 if (!virtual_keyboard_pref->GetString(layout_id, &url))
[email protected]f410d612011-08-05 04:32:24575 continue;
[email protected]b3362572011-08-17 09:28:50576 if (!input_method_manager->SetVirtualKeyboardPreference(
577 layout_id, GURL(url))) {
578 // Either |layout_id| or |url| is invalid. Remove the key from |prefs|
579 // later.
580 layouts_to_remove.push_back(layout_id);
[email protected]148994e2011-08-17 10:01:48581 LOG(ERROR) << "Removing invalid virtual keyboard pref: layout="
582 << layout_id;
[email protected]b3362572011-08-17 09:28:50583 }
584 }
585
586 // Remove invalid prefs.
587 DictionaryPrefUpdate updater(prefs, prefs::kLanguagePreferredVirtualKeyboard);
588 DictionaryValue* pref_value = updater.Get();
589 for (size_t i = 0; i < layouts_to_remove.size(); ++i) {
590 pref_value->RemoveWithoutPathExpansion(layouts_to_remove[i], NULL);
[email protected]f410d612011-08-05 04:32:24591 }
592}
593
[email protected]fecc1522009-10-15 21:08:29594} // namespace chromeos