blob: 4aee054fb852f79c416ce22e74c986242674185e [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]62c7ef32010-03-23 23:44:2414#include "chrome/browser/chromeos/cros/cros_library.h"
[email protected]4ccc05e2010-10-06 19:32:1515#include "chrome/browser/chromeos/cros/power_library.h"
[email protected]c8d4e9462011-06-29 23:18:5716#include "chrome/browser/chromeos/input_method/input_method_manager.h"
[email protected]9199bd52010-07-01 05:04:4117#include "chrome/browser/chromeos/input_method/input_method_util.h"
[email protected]c010f632011-04-01 06:44:3918#include "chrome/browser/chromeos/input_method/xkeyboard.h"
[email protected]26012e22010-12-01 06:44:2719#include "chrome/browser/chromeos/login/login_utils.h"
[email protected]1cbfb3b2011-07-11 23:34:0820#include "chrome/browser/chromeos/system/touchpad_settings.h"
[email protected]37858e52010-08-26 00:22:0221#include "chrome/browser/prefs/pref_member.h"
22#include "chrome/browser/prefs/pref_service.h"
[email protected]b3362572011-08-17 09:28:5023#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]432115822011-07-10 15:52:2724#include "chrome/common/chrome_notification_types.h"
[email protected]775caec2011-09-01 17:14:3225#include "chrome/common/chrome_switches.h"
[email protected]fecc1522009-10-15 21:08:2926#include "chrome/common/pref_names.h"
[email protected]86ab86b2011-10-19 03:07:5527#include "content/public/browser/notification_details.h"
28#include "content/public/browser/notification_source.h"
[email protected]6f96cbcb2011-11-04 02:26:0729#include "googleurl/src/gurl.h"
[email protected]fecc1522009-10-15 21:08:2930#include "unicode/timezone.h"
31
32namespace chromeos {
33
[email protected]9199bd52010-07-01 05:04:4134static const char kFallbackInputMethodLocale[] = "en-US";
[email protected]4793c942010-09-21 23:17:1735
[email protected]d743a5982010-11-08 17:54:0936Preferences::Preferences() {}
37
38Preferences::~Preferences() {}
[email protected]9199bd52010-07-01 05:04:4139
[email protected]fecc1522009-10-15 21:08:2940// static
41void Preferences::RegisterUserPrefs(PrefService* prefs) {
[email protected]a9a81812011-09-16 11:01:1742 input_method::InputMethodManager* manager =
43 input_method::InputMethodManager::GetInstance();
44
[email protected]d36f941b2011-05-09 06:19:1645 prefs->RegisterBooleanPref(prefs::kTapToClickEnabled,
46 false,
47 PrefService::SYNCABLE_PREF);
48 prefs->RegisterBooleanPref(prefs::kLabsMediaplayerEnabled,
49 false,
50 PrefService::UNSYNCABLE_PREF);
51 prefs->RegisterBooleanPref(prefs::kLabsAdvancedFilesystemEnabled,
52 false,
53 PrefService::UNSYNCABLE_PREF);
[email protected]27f20d52010-09-18 00:59:3154 // Check if the accessibility pref is already registered, which can happen
55 // in WizardController::RegisterPrefs. We still want to try to register
56 // the pref here in case of Chrome/Linux with ChromeOS=1.
57 if (prefs->FindPreference(prefs::kAccessibilityEnabled) == NULL) {
[email protected]d36f941b2011-05-09 06:19:1658 prefs->RegisterBooleanPref(prefs::kAccessibilityEnabled,
59 false,
60 PrefService::UNSYNCABLE_PREF);
[email protected]27f20d52010-09-18 00:59:3161 }
[email protected]d36f941b2011-05-09 06:19:1662 prefs->RegisterIntegerPref(prefs::kTouchpadSensitivity,
63 3,
64 PrefService::UNSYNCABLE_PREF);
[email protected]530cd622011-04-14 15:45:0065 prefs->RegisterBooleanPref(prefs::kUse24HourClock,
[email protected]d36f941b2011-05-09 06:19:1666 base::GetHourClockType() == base::k24HourClock,
67 PrefService::SYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:1068 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod
69 // because they're just used to track the logout state of the device.
[email protected]d36f941b2011-05-09 06:19:1670 prefs->RegisterStringPref(prefs::kLanguageCurrentInputMethod,
71 "",
72 PrefService::UNSYNCABLE_PREF);
73 prefs->RegisterStringPref(prefs::kLanguagePreviousInputMethod,
74 "",
75 PrefService::UNSYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:1076 // We don't sync input method hotkeys since they're not configurable.
[email protected]3b02de292010-05-13 06:05:0577 prefs->RegisterStringPref(prefs::kLanguageHotkeyNextEngineInMenu,
[email protected]d36f941b2011-05-09 06:19:1678 language_prefs::kHotkeyNextEngineInMenu,
79 PrefService::UNSYNCABLE_PREF);
[email protected]3b02de292010-05-13 06:05:0580 prefs->RegisterStringPref(prefs::kLanguageHotkeyPreviousEngine,
[email protected]d36f941b2011-05-09 06:19:1681 language_prefs::kHotkeyPreviousEngine,
82 PrefService::UNSYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:1083 // We don't sync the list of input methods and preferred languages since a
84 // user might use two or more devices with different hardware keyboards.
85 // crosbug.com/15181
[email protected]c5d45432010-09-07 08:25:3586 prefs->RegisterStringPref(prefs::kLanguagePreferredLanguages,
[email protected]d36f941b2011-05-09 06:19:1687 kFallbackInputMethodLocale,
[email protected]aa96e372011-05-16 06:23:1088 PrefService::UNSYNCABLE_PREF);
[email protected]a9a81812011-09-16 11:01:1789 prefs->RegisterStringPref(
90 prefs::kLanguagePreloadEngines,
91 manager->GetInputMethodUtil()->GetHardwareInputMethodId(),
92 PrefService::UNSYNCABLE_PREF);
[email protected]b65c5d22010-08-20 02:50:2393 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
94 prefs->RegisterBooleanPref(
95 language_prefs::kChewingBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:1696 language_prefs::kChewingBooleanPrefs[i].default_pref_value,
97 PrefService::UNSYNCABLE_PREF);
[email protected]525dbe22010-06-01 07:05:4398 }
[email protected]b65c5d22010-08-20 02:50:2399 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:43100 prefs->RegisterStringPref(
[email protected]b65c5d22010-08-20 02:50:23101 language_prefs::kChewingMultipleChoicePrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16102 language_prefs::kChewingMultipleChoicePrefs[i].default_pref_value,
103 PrefService::UNSYNCABLE_PREF);
[email protected]525dbe22010-06-01 07:05:43104 }
[email protected]b65c5d22010-08-20 02:50:23105 prefs->RegisterIntegerPref(
106 language_prefs::kChewingHsuSelKeyType.pref_name,
[email protected]d36f941b2011-05-09 06:19:16107 language_prefs::kChewingHsuSelKeyType.default_pref_value,
108 PrefService::UNSYNCABLE_PREF);
[email protected]7ac5af92010-06-07 01:25:44109
[email protected]b65c5d22010-08-20 02:50:23110 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
111 prefs->RegisterIntegerPref(
112 language_prefs::kChewingIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16113 language_prefs::kChewingIntegerPrefs[i].default_pref_value,
114 PrefService::UNSYNCABLE_PREF);
[email protected]15c53082010-06-03 03:28:21115 }
[email protected]20ce516d2010-06-18 02:20:04116 prefs->RegisterStringPref(
117 prefs::kLanguageHangulKeyboard,
[email protected]d36f941b2011-05-09 06:19:16118 language_prefs::kHangulKeyboardNameIDPairs[0].keyboard_id,
119 PrefService::SYNCABLE_PREF);
[email protected]33444cf2011-08-04 06:33:55120 prefs->RegisterStringPref(prefs::kLanguageHangulHanjaBindingKeys,
121 language_prefs::kHangulHanjaBindingKeys,
122 // Don't sync the pref as it's not user-configurable
123 PrefService::UNSYNCABLE_PREF);
[email protected]b65c5d22010-08-20 02:50:23124 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
125 prefs->RegisterBooleanPref(
126 language_prefs::kPinyinBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16127 language_prefs::kPinyinBooleanPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51128 language_prefs::kPinyinBooleanPrefs[i].sync_status);
[email protected]9040ad22010-04-22 04:29:28129 }
[email protected]b65c5d22010-08-20 02:50:23130 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
131 prefs->RegisterIntegerPref(
132 language_prefs::kPinyinIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16133 language_prefs::kPinyinIntegerPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51134 language_prefs::kPinyinIntegerPrefs[i].sync_status);
[email protected]6e5c4b82010-05-24 08:18:44135 }
[email protected]b65c5d22010-08-20 02:50:23136 prefs->RegisterIntegerPref(
137 language_prefs::kPinyinDoublePinyinSchema.pref_name,
[email protected]d36f941b2011-05-09 06:19:16138 language_prefs::kPinyinDoublePinyinSchema.default_pref_value,
139 PrefService::UNSYNCABLE_PREF);
[email protected]7ac5af92010-06-07 01:25:44140
[email protected]b65c5d22010-08-20 02:50:23141 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
142 prefs->RegisterBooleanPref(
143 language_prefs::kMozcBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16144 language_prefs::kMozcBooleanPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51145 language_prefs::kMozcBooleanPrefs[i].sync_status);
[email protected]8a1ace22010-06-10 05:38:25146 }
[email protected]b65c5d22010-08-20 02:50:23147 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
[email protected]7ac5af92010-06-07 01:25:44148 prefs->RegisterStringPref(
[email protected]b65c5d22010-08-20 02:50:23149 language_prefs::kMozcMultipleChoicePrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16150 language_prefs::kMozcMultipleChoicePrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51151 language_prefs::kMozcMultipleChoicePrefs[i].sync_status);
[email protected]9040ad22010-04-22 04:29:28152 }
[email protected]b65c5d22010-08-20 02:50:23153 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
154 prefs->RegisterIntegerPref(
155 language_prefs::kMozcIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16156 language_prefs::kMozcIntegerPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51157 language_prefs::kMozcIntegerPrefs[i].sync_status);
[email protected]54037462010-06-22 02:06:23158 }
[email protected]c010f632011-04-01 06:44:39159 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapSearchKeyTo,
[email protected]d36f941b2011-05-09 06:19:16160 input_method::kSearchKey,
161 PrefService::SYNCABLE_PREF);
[email protected]b5194dd32010-08-12 10:40:04162 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapControlKeyTo,
[email protected]d36f941b2011-05-09 06:19:16163 input_method::kLeftControlKey,
164 PrefService::SYNCABLE_PREF);
[email protected]c010f632011-04-01 06:44:39165 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapAltKeyTo,
[email protected]d36f941b2011-05-09 06:19:16166 input_method::kLeftAltKey,
167 PrefService::SYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:10168 // We don't sync the following keyboard prefs since they are not user-
169 // configurable.
[email protected]d36f941b2011-05-09 06:19:16170 prefs->RegisterBooleanPref(prefs::kLanguageXkbAutoRepeatEnabled,
171 true,
172 PrefService::UNSYNCABLE_PREF);
[email protected]4743dad2010-08-30 01:41:07173 prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatDelay,
[email protected]d36f941b2011-05-09 06:19:16174 language_prefs::kXkbAutoRepeatDelayInMs,
175 PrefService::UNSYNCABLE_PREF);
[email protected]4743dad2010-08-30 01:41:07176 prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatInterval,
[email protected]d36f941b2011-05-09 06:19:16177 language_prefs::kXkbAutoRepeatIntervalInMs,
178 PrefService::UNSYNCABLE_PREF);
[email protected]4ccc05e2010-10-06 19:32:15179
[email protected]f410d612011-08-05 04:32:24180 prefs->RegisterDictionaryPref(prefs::kLanguagePreferredVirtualKeyboard,
181 PrefService::SYNCABLE_PREF);
182
[email protected]4ccc05e2010-10-06 19:32:15183 // Screen lock default to off.
[email protected]d36f941b2011-05-09 06:19:16184 prefs->RegisterBooleanPref(prefs::kEnableScreenLock,
185 false,
186 PrefService::SYNCABLE_PREF);
[email protected]ea1eba52010-11-23 18:05:38187
188 // Mobile plan notifications default to on.
[email protected]d36f941b2011-05-09 06:19:16189 prefs->RegisterBooleanPref(prefs::kShowPlanNotifications,
190 true,
191 PrefService::SYNCABLE_PREF);
[email protected]c74fffa2011-04-27 13:32:24192
193 // 3G first-time usage promo will be shown at least once.
[email protected]d36f941b2011-05-09 06:19:16194 prefs->RegisterBooleanPref(prefs::kShow3gPromoNotification,
195 true,
196 PrefService::UNSYNCABLE_PREF);
[email protected]d6ae9502011-05-05 18:23:09197
[email protected]cc8f2472011-08-01 07:14:46198 // OAuth1 all access token and secret pair.
199 prefs->RegisterStringPref(prefs::kOAuth1Token,
200 "",
201 PrefService::UNSYNCABLE_PREF);
202 prefs->RegisterStringPref(prefs::kOAuth1Secret,
203 "",
204 PrefService::UNSYNCABLE_PREF);
[email protected]fecc1522009-10-15 21:08:29205}
206
207void Preferences::Init(PrefService* prefs) {
[email protected]fecc1522009-10-15 21:08:29208 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this);
[email protected]fe23d5a32010-05-28 02:43:04209 accessibility_enabled_.Init(prefs::kAccessibilityEnabled, prefs, this);
[email protected]fecc1522009-10-15 21:08:29210 sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, this);
[email protected]530cd622011-04-14 15:45:00211 use_24hour_clock_.Init(prefs::kUse24HourClock, prefs, this);
[email protected]3b02de292010-05-13 06:05:05212 language_hotkey_next_engine_in_menu_.Init(
213 prefs::kLanguageHotkeyNextEngineInMenu, prefs, this);
214 language_hotkey_previous_engine_.Init(
215 prefs::kLanguageHotkeyPreviousEngine, prefs, this);
[email protected]74b42fc12010-07-20 10:15:41216 language_preferred_languages_.Init(prefs::kLanguagePreferredLanguages,
217 prefs, this);
[email protected]70aa5b32010-04-05 08:30:34218 language_preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, this);
[email protected]b65c5d22010-08-20 02:50:23219 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:43220 language_chewing_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23221 language_prefs::kChewingBooleanPrefs[i].pref_name, prefs, this);
[email protected]525dbe22010-06-01 07:05:43222 }
[email protected]b65c5d22010-08-20 02:50:23223 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:43224 language_chewing_multiple_choice_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23225 language_prefs::kChewingMultipleChoicePrefs[i].pref_name, prefs, this);
[email protected]525dbe22010-06-01 07:05:43226 }
[email protected]7ac5af92010-06-07 01:25:44227 language_chewing_hsu_sel_key_type_.Init(
[email protected]b65c5d22010-08-20 02:50:23228 language_prefs::kChewingHsuSelKeyType.pref_name, prefs, this);
229 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
[email protected]15c53082010-06-03 03:28:21230 language_chewing_integer_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23231 language_prefs::kChewingIntegerPrefs[i].pref_name, prefs, this);
[email protected]15c53082010-06-03 03:28:21232 }
[email protected]50951432010-03-31 12:12:42233 language_hangul_keyboard_.Init(prefs::kLanguageHangulKeyboard, prefs, this);
[email protected]33444cf2011-08-04 06:33:55234 language_hangul_hanja_binding_keys_.Init(
235 prefs::kLanguageHangulHanjaBindingKeys, prefs, this);
[email protected]b65c5d22010-08-20 02:50:23236 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
[email protected]9040ad22010-04-22 04:29:28237 language_pinyin_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23238 language_prefs::kPinyinBooleanPrefs[i].pref_name, prefs, this);
[email protected]9040ad22010-04-22 04:29:28239 }
[email protected]b65c5d22010-08-20 02:50:23240 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
[email protected]9040ad22010-04-22 04:29:28241 language_pinyin_int_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23242 language_prefs::kPinyinIntegerPrefs[i].pref_name, prefs, this);
[email protected]9040ad22010-04-22 04:29:28243 }
[email protected]7ac5af92010-06-07 01:25:44244 language_pinyin_double_pinyin_schema_.Init(
[email protected]b65c5d22010-08-20 02:50:23245 language_prefs::kPinyinDoublePinyinSchema.pref_name, prefs, this);
246 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
[email protected]8a1ace22010-06-10 05:38:25247 language_mozc_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23248 language_prefs::kMozcBooleanPrefs[i].pref_name, prefs, this);
[email protected]8a1ace22010-06-10 05:38:25249 }
[email protected]b65c5d22010-08-20 02:50:23250 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
[email protected]6e5c4b82010-05-24 08:18:44251 language_mozc_multiple_choice_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23252 language_prefs::kMozcMultipleChoicePrefs[i].pref_name, prefs, this);
[email protected]6e5c4b82010-05-24 08:18:44253 }
[email protected]b65c5d22010-08-20 02:50:23254 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
[email protected]54037462010-06-22 02:06:23255 language_mozc_integer_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23256 language_prefs::kMozcIntegerPrefs[i].pref_name, prefs, this);
[email protected]54037462010-06-22 02:06:23257 }
[email protected]b5194dd32010-08-12 10:40:04258 language_xkb_remap_search_key_to_.Init(
259 prefs::kLanguageXkbRemapSearchKeyTo, prefs, this);
260 language_xkb_remap_control_key_to_.Init(
261 prefs::kLanguageXkbRemapControlKeyTo, prefs, this);
262 language_xkb_remap_alt_key_to_.Init(
263 prefs::kLanguageXkbRemapAltKeyTo, prefs, this);
[email protected]a995b392010-08-11 04:38:59264 language_xkb_auto_repeat_enabled_.Init(
265 prefs::kLanguageXkbAutoRepeatEnabled, prefs, this);
266 language_xkb_auto_repeat_delay_pref_.Init(
[email protected]4743dad2010-08-30 01:41:07267 prefs::kLanguageXkbAutoRepeatDelay, prefs, this);
[email protected]a995b392010-08-11 04:38:59268 language_xkb_auto_repeat_interval_pref_.Init(
[email protected]4743dad2010-08-30 01:41:07269 prefs::kLanguageXkbAutoRepeatInterval, prefs, this);
[email protected]fecc1522009-10-15 21:08:29270
[email protected]4ccc05e2010-10-06 19:32:15271 enable_screen_lock_.Init(prefs::kEnableScreenLock, prefs, this);
272
[email protected]d7ca1ba2011-05-09 20:09:08273 // Initialize preferences to currently saved state.
[email protected]fecc1522009-10-15 21:08:29274 NotifyPrefChanged(NULL);
[email protected]26012e22010-12-01 06:44:27275
[email protected]f410d612011-08-05 04:32:24276 // Initialize virtual keyboard settings to currently saved state.
277 UpdateVirturalKeyboardPreference(prefs);
278
[email protected]26012e22010-12-01 06:44:27279 // If a guest is logged in, initialize the prefs as if this is the first
280 // login.
281 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) {
282 LoginUtils::Get()->SetFirstLoginPrefs(prefs);
283 }
[email protected]fecc1522009-10-15 21:08:29284}
285
[email protected]432115822011-07-10 15:52:27286void Preferences::Observe(int type,
[email protected]86ab86b2011-10-19 03:07:55287 const content::NotificationSource& source,
288 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27289 if (type == chrome::NOTIFICATION_PREF_CHANGED)
[email protected]a0bbc402011-10-19 04:28:30290 NotifyPrefChanged(content::Details<std::string>(details).ptr());
[email protected]fecc1522009-10-15 21:08:29291}
292
[email protected]57ecc4b2010-08-11 03:02:51293void Preferences::NotifyPrefChanged(const std::string* pref_name) {
[email protected]3b02de292010-05-13 06:05:05294 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) {
[email protected]d7ca1ba2011-05-09 20:09:08295 bool enabled = tap_to_click_enabled_.GetValue();
[email protected]1cbfb3b2011-07-11 23:34:08296 system::touchpad_settings::SetTapToClick(enabled);
[email protected]d7ca1ba2011-05-09 20:09:08297 if (pref_name)
298 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled);
299 else
300 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Started", enabled);
[email protected]3b02de292010-05-13 06:05:05301 }
[email protected]3b02de292010-05-13 06:05:05302 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) {
[email protected]d7ca1ba2011-05-09 20:09:08303 int sensitivity = sensitivity_.GetValue();
[email protected]1cbfb3b2011-07-11 23:34:08304 system::touchpad_settings::SetSensitivity(sensitivity);
[email protected]d7ca1ba2011-05-09 20:09:08305 if (pref_name) {
306 UMA_HISTOGRAM_CUSTOM_COUNTS(
307 "Touchpad.Sensitivity.Changed", sensitivity, 1, 5, 5);
308 } else {
309 UMA_HISTOGRAM_CUSTOM_COUNTS(
310 "Touchpad.Sensitivity.Started", sensitivity, 1, 5, 5);
311 }
[email protected]3b02de292010-05-13 06:05:05312 }
[email protected]8be9ff22010-06-08 02:13:54313
314 // We don't handle prefs::kLanguageCurrentInputMethod and PreviousInputMethod
315 // here.
316
[email protected]3b02de292010-05-13 06:05:05317 if (!pref_name || *pref_name == prefs::kLanguageHotkeyNextEngineInMenu) {
[email protected]ddd231e2010-06-29 20:35:19318 SetLanguageConfigStringListAsCSV(
[email protected]b65c5d22010-08-20 02:50:23319 language_prefs::kHotKeySectionName,
320 language_prefs::kNextEngineInMenuConfigName,
[email protected]ddd231e2010-06-29 20:35:19321 language_hotkey_next_engine_in_menu_.GetValue());
[email protected]3b02de292010-05-13 06:05:05322 }
323 if (!pref_name || *pref_name == prefs::kLanguageHotkeyPreviousEngine) {
[email protected]ddd231e2010-06-29 20:35:19324 SetLanguageConfigStringListAsCSV(
[email protected]b65c5d22010-08-20 02:50:23325 language_prefs::kHotKeySectionName,
326 language_prefs::kPreviousEngineConfigName,
[email protected]ddd231e2010-06-29 20:35:19327 language_hotkey_previous_engine_.GetValue());
[email protected]3b02de292010-05-13 06:05:05328 }
[email protected]74b42fc12010-07-20 10:15:41329 if (!pref_name || *pref_name == prefs::kLanguagePreferredLanguages) {
330 // Unlike kLanguagePreloadEngines and some other input method
331 // preferencs, we don't need to send this to ibus-daemon.
332 }
[email protected]a6e90772011-02-09 05:38:54333
334 // Here, we set up the the modifier key mapping. This has to be done
335 // before changing the current keyboard layout, so that the modifier key
336 // preference is properly preserved. For this reason, we should do this
337 // before setting preload engines, that could change the current
338 // keyboard layout as needed.
339 if (!pref_name || (*pref_name == prefs::kLanguageXkbRemapSearchKeyTo ||
340 *pref_name == prefs::kLanguageXkbRemapControlKeyTo ||
341 *pref_name == prefs::kLanguageXkbRemapAltKeyTo)) {
342 UpdateModifierKeyMapping();
343 }
344 if (!pref_name || *pref_name == prefs::kLanguageXkbAutoRepeatEnabled) {
345 const bool enabled = language_xkb_auto_repeat_enabled_.GetValue();
[email protected]e6e83362011-09-16 07:28:00346 input_method::XKeyboard::SetAutoRepeatEnabled(enabled);
[email protected]a6e90772011-02-09 05:38:54347 }
348 if (!pref_name || ((*pref_name == prefs::kLanguageXkbAutoRepeatDelay) ||
349 (*pref_name == prefs::kLanguageXkbAutoRepeatInterval))) {
350 UpdateAutoRepeatRate();
351 }
352
[email protected]3b02de292010-05-13 06:05:05353 if (!pref_name || *pref_name == prefs::kLanguagePreloadEngines) {
[email protected]b65c5d22010-08-20 02:50:23354 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
355 language_prefs::kPreloadEnginesConfigName,
[email protected]d01bb8072010-04-12 13:00:15356 language_preload_engines_.GetValue());
[email protected]3b02de292010-05-13 06:05:05357 }
[email protected]b65c5d22010-08-20 02:50:23358 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
359 if (!pref_name ||
360 *pref_name == language_prefs::kChewingBooleanPrefs[i].pref_name) {
361 SetLanguageConfigBoolean(
362 language_prefs::kChewingSectionName,
363 language_prefs::kChewingBooleanPrefs[i].ibus_config_name,
364 language_chewing_boolean_prefs_[i].GetValue());
[email protected]525dbe22010-06-01 07:05:43365 }
366 }
[email protected]b65c5d22010-08-20 02:50:23367 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
368 if (!pref_name ||
369 *pref_name ==
370 language_prefs::kChewingMultipleChoicePrefs[i].pref_name) {
[email protected]525dbe22010-06-01 07:05:43371 SetLanguageConfigString(
[email protected]b65c5d22010-08-20 02:50:23372 language_prefs::kChewingSectionName,
373 language_prefs::kChewingMultipleChoicePrefs[i].ibus_config_name,
[email protected]525dbe22010-06-01 07:05:43374 language_chewing_multiple_choice_prefs_[i].GetValue());
375 }
376 }
[email protected]b65c5d22010-08-20 02:50:23377 if (!pref_name ||
378 *pref_name == language_prefs::kChewingHsuSelKeyType.pref_name) {
[email protected]7ac5af92010-06-07 01:25:44379 SetLanguageConfigInteger(
[email protected]b65c5d22010-08-20 02:50:23380 language_prefs::kChewingSectionName,
381 language_prefs::kChewingHsuSelKeyType.ibus_config_name,
[email protected]7ac5af92010-06-07 01:25:44382 language_chewing_hsu_sel_key_type_.GetValue());
383 }
[email protected]b65c5d22010-08-20 02:50:23384 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
385 if (!pref_name ||
386 *pref_name == language_prefs::kChewingIntegerPrefs[i].pref_name) {
387 SetLanguageConfigInteger(
388 language_prefs::kChewingSectionName,
389 language_prefs::kChewingIntegerPrefs[i].ibus_config_name,
390 language_chewing_integer_prefs_[i].GetValue());
[email protected]15c53082010-06-03 03:28:21391 }
392 }
[email protected]b65c5d22010-08-20 02:50:23393 if (!pref_name ||
394 *pref_name == prefs::kLanguageHangulKeyboard) {
395 SetLanguageConfigString(language_prefs::kHangulSectionName,
396 language_prefs::kHangulKeyboardConfigName,
[email protected]50951432010-03-31 12:12:42397 language_hangul_keyboard_.GetValue());
[email protected]3b02de292010-05-13 06:05:05398 }
[email protected]33444cf2011-08-04 06:33:55399 if (!pref_name || *pref_name == prefs::kLanguageHangulHanjaBindingKeys) {
400 SetLanguageConfigString(language_prefs::kHangulSectionName,
401 language_prefs::kHangulHanjaBindingKeysConfigName,
402 language_hangul_hanja_binding_keys_.GetValue());
403 }
[email protected]b65c5d22010-08-20 02:50:23404 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
405 if (!pref_name ||
406 *pref_name == language_prefs::kPinyinBooleanPrefs[i].pref_name) {
407 SetLanguageConfigBoolean(
408 language_prefs::kPinyinSectionName,
409 language_prefs::kPinyinBooleanPrefs[i].ibus_config_name,
410 language_pinyin_boolean_prefs_[i].GetValue());
[email protected]9040ad22010-04-22 04:29:28411 }
412 }
[email protected]b65c5d22010-08-20 02:50:23413 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
414 if (!pref_name ||
415 *pref_name == language_prefs::kPinyinIntegerPrefs[i].pref_name) {
416 SetLanguageConfigInteger(
417 language_prefs::kPinyinSectionName,
418 language_prefs::kPinyinIntegerPrefs[i].ibus_config_name,
419 language_pinyin_int_prefs_[i].GetValue());
[email protected]9040ad22010-04-22 04:29:28420 }
421 }
[email protected]b65c5d22010-08-20 02:50:23422 if (!pref_name ||
423 *pref_name == language_prefs::kPinyinDoublePinyinSchema.pref_name) {
[email protected]7ac5af92010-06-07 01:25:44424 SetLanguageConfigInteger(
[email protected]b65c5d22010-08-20 02:50:23425 language_prefs::kPinyinSectionName,
426 language_prefs::kPinyinDoublePinyinSchema.ibus_config_name,
[email protected]7ac5af92010-06-07 01:25:44427 language_pinyin_double_pinyin_schema_.GetValue());
428 }
[email protected]b65c5d22010-08-20 02:50:23429 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
430 if (!pref_name ||
431 *pref_name == language_prefs::kMozcBooleanPrefs[i].pref_name) {
432 SetLanguageConfigBoolean(
433 language_prefs::kMozcSectionName,
434 language_prefs::kMozcBooleanPrefs[i].ibus_config_name,
435 language_mozc_boolean_prefs_[i].GetValue());
[email protected]8a1ace22010-06-10 05:38:25436 }
437 }
[email protected]b65c5d22010-08-20 02:50:23438 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
439 if (!pref_name ||
440 *pref_name == language_prefs::kMozcMultipleChoicePrefs[i].pref_name) {
[email protected]6e5c4b82010-05-24 08:18:44441 SetLanguageConfigString(
[email protected]b65c5d22010-08-20 02:50:23442 language_prefs::kMozcSectionName,
443 language_prefs::kMozcMultipleChoicePrefs[i].ibus_config_name,
[email protected]6e5c4b82010-05-24 08:18:44444 language_mozc_multiple_choice_prefs_[i].GetValue());
445 }
446 }
[email protected]b65c5d22010-08-20 02:50:23447 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
448 if (!pref_name ||
449 *pref_name == language_prefs::kMozcIntegerPrefs[i].pref_name) {
450 SetLanguageConfigInteger(
451 language_prefs::kMozcSectionName,
452 language_prefs::kMozcIntegerPrefs[i].ibus_config_name,
453 language_mozc_integer_prefs_[i].GetValue());
[email protected]54037462010-06-22 02:06:23454 }
455 }
[email protected]4793c942010-09-21 23:17:17456
[email protected]4ccc05e2010-10-06 19:32:15457 // Init or update power manager config.
458 if (!pref_name || *pref_name == prefs::kEnableScreenLock) {
459 CrosLibrary::Get()->GetPowerLibrary()->EnableScreenLock(
460 enable_screen_lock_.GetValue());
461 }
[email protected]fecc1522009-10-15 21:08:29462}
463
[email protected]70aa5b32010-04-05 08:30:34464void Preferences::SetLanguageConfigBoolean(const char* section,
465 const char* name,
466 bool value) {
[email protected]dc7b0942011-06-15 06:45:53467 input_method::ImeConfigValue config;
468 config.type = input_method::ImeConfigValue::kValueTypeBool;
[email protected]70aa5b32010-04-05 08:30:34469 config.bool_value = value;
[email protected]c8d4e9462011-06-29 23:18:57470 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28471 SetImeConfig(section, name, config);
[email protected]70aa5b32010-04-05 08:30:34472}
473
[email protected]9040ad22010-04-22 04:29:28474void Preferences::SetLanguageConfigInteger(const char* section,
475 const char* name,
476 int value) {
[email protected]dc7b0942011-06-15 06:45:53477 input_method::ImeConfigValue config;
478 config.type = input_method::ImeConfigValue::kValueTypeInt;
[email protected]9040ad22010-04-22 04:29:28479 config.int_value = value;
[email protected]c8d4e9462011-06-29 23:18:57480 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28481 SetImeConfig(section, name, config);
[email protected]9040ad22010-04-22 04:29:28482}
483
[email protected]50951432010-03-31 12:12:42484void Preferences::SetLanguageConfigString(const char* section,
485 const char* name,
[email protected]ddd231e2010-06-29 20:35:19486 const std::string& value) {
[email protected]dc7b0942011-06-15 06:45:53487 input_method::ImeConfigValue config;
488 config.type = input_method::ImeConfigValue::kValueTypeString;
[email protected]ddd231e2010-06-29 20:35:19489 config.string_value = value;
[email protected]c8d4e9462011-06-29 23:18:57490 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28491 SetImeConfig(section, name, config);
[email protected]50951432010-03-31 12:12:42492}
493
[email protected]2c25ddfd2010-04-09 10:35:55494void Preferences::SetLanguageConfigStringList(
495 const char* section,
496 const char* name,
[email protected]ddd231e2010-06-29 20:35:19497 const std::vector<std::string>& values) {
[email protected]dc7b0942011-06-15 06:45:53498 input_method::ImeConfigValue config;
499 config.type = input_method::ImeConfigValue::kValueTypeStringList;
[email protected]ddd231e2010-06-29 20:35:19500 for (size_t i = 0; i < values.size(); ++i)
501 config.string_list_value.push_back(values[i]);
502
[email protected]c8d4e9462011-06-29 23:18:57503 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28504 SetImeConfig(section, name, config);
[email protected]2c25ddfd2010-04-09 10:35:55505}
506
[email protected]d01bb8072010-04-12 13:00:15507void Preferences::SetLanguageConfigStringListAsCSV(const char* section,
508 const char* name,
[email protected]ddd231e2010-06-29 20:35:19509 const std::string& value) {
[email protected]e24c2c92010-10-23 01:39:24510 VLOG(1) << "Setting " << name << " to '" << value << "'";
[email protected]d01bb8072010-04-12 13:00:15511
[email protected]ddd231e2010-06-29 20:35:19512 std::vector<std::string> split_values;
513 if (!value.empty())
[email protected]76eb0242010-10-14 00:35:36514 base::SplitString(value, ',', &split_values);
[email protected]ddd231e2010-06-29 20:35:19515
[email protected]2c25ddfd2010-04-09 10:35:55516 // We should call the cros API even when |value| is empty, to disable default
[email protected]d01bb8072010-04-12 13:00:15517 // config.
518 SetLanguageConfigStringList(section, name, split_values);
[email protected]70aa5b32010-04-05 08:30:34519}
520
[email protected]b5194dd32010-08-12 10:40:04521void Preferences::UpdateModifierKeyMapping() {
522 const int search_remap = language_xkb_remap_search_key_to_.GetValue();
523 const int control_remap = language_xkb_remap_control_key_to_.GetValue();
524 const int alt_remap = language_xkb_remap_alt_key_to_.GetValue();
[email protected]c010f632011-04-01 06:44:39525 if ((search_remap < input_method::kNumModifierKeys) && (search_remap >= 0) &&
526 (control_remap < input_method::kNumModifierKeys) &&
527 (control_remap >= 0) &&
528 (alt_remap < input_method::kNumModifierKeys) && (alt_remap >= 0)) {
529 input_method::ModifierMap modifier_map;
[email protected]b5194dd32010-08-12 10:40:04530 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39531 input_method::ModifierKeyPair(
532 input_method::kSearchKey,
533 input_method::ModifierKey(search_remap)));
[email protected]b5194dd32010-08-12 10:40:04534 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39535 input_method::ModifierKeyPair(
536 input_method::kLeftControlKey,
537 input_method::ModifierKey(control_remap)));
[email protected]b5194dd32010-08-12 10:40:04538 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39539 input_method::ModifierKeyPair(
540 input_method::kLeftAltKey,
541 input_method::ModifierKey(alt_remap)));
[email protected]e6e83362011-09-16 07:28:00542 input_method::InputMethodManager::GetInstance()->GetXKeyboard()->
543 RemapModifierKeys(modifier_map);
[email protected]b5194dd32010-08-12 10:40:04544 } else {
545 LOG(ERROR) << "Failed to remap modifier keys. Unexpected value(s): "
546 << search_remap << ", " << control_remap << ", " << alt_remap;
547 }
548}
549
[email protected]a995b392010-08-11 04:38:59550void Preferences::UpdateAutoRepeatRate() {
[email protected]c010f632011-04-01 06:44:39551 input_method::AutoRepeatRate rate;
[email protected]a995b392010-08-11 04:38:59552 rate.initial_delay_in_ms = language_xkb_auto_repeat_delay_pref_.GetValue();
553 rate.repeat_interval_in_ms =
554 language_xkb_auto_repeat_interval_pref_.GetValue();
555 DCHECK(rate.initial_delay_in_ms > 0);
556 DCHECK(rate.repeat_interval_in_ms > 0);
[email protected]e6e83362011-09-16 07:28:00557 input_method::XKeyboard::SetAutoRepeatRate(rate);
[email protected]a995b392010-08-11 04:38:59558}
559
[email protected]f410d612011-08-05 04:32:24560void Preferences::UpdateVirturalKeyboardPreference(PrefService* prefs) {
561 const DictionaryValue* virtual_keyboard_pref =
562 prefs->GetDictionary(prefs::kLanguagePreferredVirtualKeyboard);
563 DCHECK(virtual_keyboard_pref);
564
565 input_method::InputMethodManager* input_method_manager =
566 input_method::InputMethodManager::GetInstance();
567 input_method_manager->ClearAllVirtualKeyboardPreferences();
568
569 std::string url;
[email protected]b3362572011-08-17 09:28:50570 std::vector<std::string> layouts_to_remove;
[email protected]f410d612011-08-05 04:32:24571 for (DictionaryValue::key_iterator iter = virtual_keyboard_pref->begin_keys();
572 iter != virtual_keyboard_pref->end_keys();
573 ++iter) {
[email protected]b3362572011-08-17 09:28:50574 const std::string& layout_id = *iter; // e.g. "us", "handwriting-vk"
575 if (!virtual_keyboard_pref->GetString(layout_id, &url))
[email protected]f410d612011-08-05 04:32:24576 continue;
[email protected]b3362572011-08-17 09:28:50577 if (!input_method_manager->SetVirtualKeyboardPreference(
578 layout_id, GURL(url))) {
579 // Either |layout_id| or |url| is invalid. Remove the key from |prefs|
580 // later.
581 layouts_to_remove.push_back(layout_id);
[email protected]148994e2011-08-17 10:01:48582 LOG(ERROR) << "Removing invalid virtual keyboard pref: layout="
583 << layout_id;
[email protected]b3362572011-08-17 09:28:50584 }
585 }
586
587 // Remove invalid prefs.
588 DictionaryPrefUpdate updater(prefs, prefs::kLanguagePreferredVirtualKeyboard);
589 DictionaryValue* pref_value = updater.Get();
590 for (size_t i = 0; i < layouts_to_remove.size(); ++i) {
591 pref_value->RemoveWithoutPathExpansion(layouts_to_remove[i], NULL);
[email protected]f410d612011-08-05 04:32:24592 }
593}
594
[email protected]fecc1522009-10-15 21:08:29595} // namespace chromeos