[email protected] | 2b2820a | 2011-03-07 22:28:40 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/chromeos/preferences.h" |
| 6 | |
[email protected] | 775caec | 2011-09-01 17:14:32 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | 530cd62 | 2011-04-14 15:45:00 | [diff] [blame] | 8 | #include "base/i18n/time_formatting.h" |
[email protected] | d7ca1ba | 2011-05-09 20:09:08 | [diff] [blame] | 9 | #include "base/metrics/histogram.h" |
[email protected] | 4e5ae20f | 2010-09-24 04:52:11 | [diff] [blame] | 10 | #include "base/string_split.h" |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 11 | #include "base/string_util.h" |
[email protected] | 5095143 | 2010-03-31 12:12:42 | [diff] [blame] | 12 | #include "base/utf_string_conversions.h" |
[email protected] | c0a2128d9 | 2011-07-20 15:04:46 | [diff] [blame] | 13 | #include "chrome/browser/browser_process.h" |
[email protected] | c8d4e946 | 2011-06-29 23:18:57 | [diff] [blame] | 14 | #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
[email protected] | 9199bd5 | 2010-07-01 05:04:41 | [diff] [blame] | 15 | #include "chrome/browser/chromeos/input_method/input_method_util.h" |
[email protected] | c010f63 | 2011-04-01 06:44:39 | [diff] [blame] | 16 | #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
[email protected] | 26012e2 | 2010-12-01 06:44:27 | [diff] [blame] | 17 | #include "chrome/browser/chromeos/login/login_utils.h" |
[email protected] | a329ebe | 2011-11-22 23:26:49 | [diff] [blame] | 18 | #include "chrome/browser/chromeos/system/screen_locker_settings.h" |
[email protected] | 1cbfb3b | 2011-07-11 23:34:08 | [diff] [blame] | 19 | #include "chrome/browser/chromeos/system/touchpad_settings.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 20 | #include "chrome/browser/prefs/pref_member.h" |
| 21 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | b336257 | 2011-08-17 09:28:50 | [diff] [blame] | 22 | #include "chrome/browser/prefs/scoped_user_pref_update.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 23 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 775caec | 2011-09-01 17:14:32 | [diff] [blame] | 24 | #include "chrome/common/chrome_switches.h" |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 25 | #include "chrome/common/pref_names.h" |
[email protected] | 86ab86b | 2011-10-19 03:07:55 | [diff] [blame] | 26 | #include "content/public/browser/notification_details.h" |
| 27 | #include "content/public/browser/notification_source.h" |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 28 | #include "googleurl/src/gurl.h" |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 29 | #include "unicode/timezone.h" |
| 30 | |
| 31 | namespace chromeos { |
| 32 | |
[email protected] | 9199bd5 | 2010-07-01 05:04:41 | [diff] [blame] | 33 | static const char kFallbackInputMethodLocale[] = "en-US"; |
[email protected] | 4793c94 | 2010-09-21 23:17:17 | [diff] [blame] | 34 | |
[email protected] | d743a598 | 2010-11-08 17:54:09 | [diff] [blame] | 35 | Preferences::Preferences() {} |
| 36 | |
| 37 | Preferences::~Preferences() {} |
[email protected] | 9199bd5 | 2010-07-01 05:04:41 | [diff] [blame] | 38 | |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 39 | // static |
| 40 | void Preferences::RegisterUserPrefs(PrefService* prefs) { |
[email protected] | a9a8181 | 2011-09-16 11:01:17 | [diff] [blame] | 41 | input_method::InputMethodManager* manager = |
| 42 | input_method::InputMethodManager::GetInstance(); |
| 43 | |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 44 | 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] | 27f20d5 | 2010-09-18 00:59:31 | [diff] [blame] | 53 | // 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] | 7ef254b | 2011-12-08 03:24:45 | [diff] [blame^] | 56 | if (prefs->FindPreference(prefs::kSpokenFeedbackEnabled) == NULL) { |
| 57 | prefs->RegisterBooleanPref(prefs::kSpokenFeedbackEnabled, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 58 | false, |
| 59 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 27f20d5 | 2010-09-18 00:59:31 | [diff] [blame] | 60 | } |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 61 | prefs->RegisterIntegerPref(prefs::kTouchpadSensitivity, |
| 62 | 3, |
| 63 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 530cd62 | 2011-04-14 15:45:00 | [diff] [blame] | 64 | prefs->RegisterBooleanPref(prefs::kUse24HourClock, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 65 | base::GetHourClockType() == base::k24HourClock, |
| 66 | PrefService::SYNCABLE_PREF); |
[email protected] | aa96e37 | 2011-05-16 06:23:10 | [diff] [blame] | 67 | // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod |
| 68 | // because they're just used to track the logout state of the device. |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 69 | prefs->RegisterStringPref(prefs::kLanguageCurrentInputMethod, |
| 70 | "", |
| 71 | PrefService::UNSYNCABLE_PREF); |
| 72 | prefs->RegisterStringPref(prefs::kLanguagePreviousInputMethod, |
| 73 | "", |
| 74 | PrefService::UNSYNCABLE_PREF); |
[email protected] | aa96e37 | 2011-05-16 06:23:10 | [diff] [blame] | 75 | // We don't sync input method hotkeys since they're not configurable. |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 76 | prefs->RegisterStringPref(prefs::kLanguageHotkeyNextEngineInMenu, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 77 | language_prefs::kHotkeyNextEngineInMenu, |
| 78 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 79 | prefs->RegisterStringPref(prefs::kLanguageHotkeyPreviousEngine, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 80 | language_prefs::kHotkeyPreviousEngine, |
| 81 | PrefService::UNSYNCABLE_PREF); |
[email protected] | aa96e37 | 2011-05-16 06:23:10 | [diff] [blame] | 82 | // 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] | c5d4543 | 2010-09-07 08:25:35 | [diff] [blame] | 85 | prefs->RegisterStringPref(prefs::kLanguagePreferredLanguages, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 86 | kFallbackInputMethodLocale, |
[email protected] | aa96e37 | 2011-05-16 06:23:10 | [diff] [blame] | 87 | PrefService::UNSYNCABLE_PREF); |
[email protected] | a9a8181 | 2011-09-16 11:01:17 | [diff] [blame] | 88 | prefs->RegisterStringPref( |
| 89 | prefs::kLanguagePreloadEngines, |
| 90 | manager->GetInputMethodUtil()->GetHardwareInputMethodId(), |
| 91 | PrefService::UNSYNCABLE_PREF); |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 92 | for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { |
| 93 | prefs->RegisterBooleanPref( |
| 94 | language_prefs::kChewingBooleanPrefs[i].pref_name, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 95 | language_prefs::kChewingBooleanPrefs[i].default_pref_value, |
| 96 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 525dbe2 | 2010-06-01 07:05:43 | [diff] [blame] | 97 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 98 | for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { |
[email protected] | 525dbe2 | 2010-06-01 07:05:43 | [diff] [blame] | 99 | prefs->RegisterStringPref( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 100 | language_prefs::kChewingMultipleChoicePrefs[i].pref_name, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 101 | language_prefs::kChewingMultipleChoicePrefs[i].default_pref_value, |
| 102 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 525dbe2 | 2010-06-01 07:05:43 | [diff] [blame] | 103 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 104 | prefs->RegisterIntegerPref( |
| 105 | language_prefs::kChewingHsuSelKeyType.pref_name, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 106 | language_prefs::kChewingHsuSelKeyType.default_pref_value, |
| 107 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 7ac5af9 | 2010-06-07 01:25:44 | [diff] [blame] | 108 | |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 109 | for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) { |
| 110 | prefs->RegisterIntegerPref( |
| 111 | language_prefs::kChewingIntegerPrefs[i].pref_name, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 112 | language_prefs::kChewingIntegerPrefs[i].default_pref_value, |
| 113 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 15c5308 | 2010-06-03 03:28:21 | [diff] [blame] | 114 | } |
[email protected] | 20ce516d | 2010-06-18 02:20:04 | [diff] [blame] | 115 | prefs->RegisterStringPref( |
| 116 | prefs::kLanguageHangulKeyboard, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 117 | language_prefs::kHangulKeyboardNameIDPairs[0].keyboard_id, |
| 118 | PrefService::SYNCABLE_PREF); |
[email protected] | 33444cf | 2011-08-04 06:33:55 | [diff] [blame] | 119 | 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] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 123 | for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { |
| 124 | prefs->RegisterBooleanPref( |
| 125 | language_prefs::kPinyinBooleanPrefs[i].pref_name, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 126 | language_prefs::kPinyinBooleanPrefs[i].default_pref_value, |
[email protected] | 203bec6 | 2011-05-16 06:17:51 | [diff] [blame] | 127 | language_prefs::kPinyinBooleanPrefs[i].sync_status); |
[email protected] | 9040ad2 | 2010-04-22 04:29:28 | [diff] [blame] | 128 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 129 | for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) { |
| 130 | prefs->RegisterIntegerPref( |
| 131 | language_prefs::kPinyinIntegerPrefs[i].pref_name, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 132 | language_prefs::kPinyinIntegerPrefs[i].default_pref_value, |
[email protected] | 203bec6 | 2011-05-16 06:17:51 | [diff] [blame] | 133 | language_prefs::kPinyinIntegerPrefs[i].sync_status); |
[email protected] | 6e5c4b8 | 2010-05-24 08:18:44 | [diff] [blame] | 134 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 135 | prefs->RegisterIntegerPref( |
| 136 | language_prefs::kPinyinDoublePinyinSchema.pref_name, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 137 | language_prefs::kPinyinDoublePinyinSchema.default_pref_value, |
| 138 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 7ac5af9 | 2010-06-07 01:25:44 | [diff] [blame] | 139 | |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 140 | for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { |
| 141 | prefs->RegisterBooleanPref( |
| 142 | language_prefs::kMozcBooleanPrefs[i].pref_name, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 143 | language_prefs::kMozcBooleanPrefs[i].default_pref_value, |
[email protected] | 203bec6 | 2011-05-16 06:17:51 | [diff] [blame] | 144 | language_prefs::kMozcBooleanPrefs[i].sync_status); |
[email protected] | 8a1ace2 | 2010-06-10 05:38:25 | [diff] [blame] | 145 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 146 | for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { |
[email protected] | 7ac5af9 | 2010-06-07 01:25:44 | [diff] [blame] | 147 | prefs->RegisterStringPref( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 148 | language_prefs::kMozcMultipleChoicePrefs[i].pref_name, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 149 | language_prefs::kMozcMultipleChoicePrefs[i].default_pref_value, |
[email protected] | 203bec6 | 2011-05-16 06:17:51 | [diff] [blame] | 150 | language_prefs::kMozcMultipleChoicePrefs[i].sync_status); |
[email protected] | 9040ad2 | 2010-04-22 04:29:28 | [diff] [blame] | 151 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 152 | for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { |
| 153 | prefs->RegisterIntegerPref( |
| 154 | language_prefs::kMozcIntegerPrefs[i].pref_name, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 155 | language_prefs::kMozcIntegerPrefs[i].default_pref_value, |
[email protected] | 203bec6 | 2011-05-16 06:17:51 | [diff] [blame] | 156 | language_prefs::kMozcIntegerPrefs[i].sync_status); |
[email protected] | 5403746 | 2010-06-22 02:06:23 | [diff] [blame] | 157 | } |
[email protected] | c010f63 | 2011-04-01 06:44:39 | [diff] [blame] | 158 | prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapSearchKeyTo, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 159 | input_method::kSearchKey, |
| 160 | PrefService::SYNCABLE_PREF); |
[email protected] | b5194dd3 | 2010-08-12 10:40:04 | [diff] [blame] | 161 | prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapControlKeyTo, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 162 | input_method::kLeftControlKey, |
| 163 | PrefService::SYNCABLE_PREF); |
[email protected] | c010f63 | 2011-04-01 06:44:39 | [diff] [blame] | 164 | prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapAltKeyTo, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 165 | input_method::kLeftAltKey, |
| 166 | PrefService::SYNCABLE_PREF); |
[email protected] | aa96e37 | 2011-05-16 06:23:10 | [diff] [blame] | 167 | // We don't sync the following keyboard prefs since they are not user- |
| 168 | // configurable. |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 169 | prefs->RegisterBooleanPref(prefs::kLanguageXkbAutoRepeatEnabled, |
| 170 | true, |
| 171 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 4743dad | 2010-08-30 01:41:07 | [diff] [blame] | 172 | prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatDelay, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 173 | language_prefs::kXkbAutoRepeatDelayInMs, |
| 174 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 4743dad | 2010-08-30 01:41:07 | [diff] [blame] | 175 | prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatInterval, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 176 | language_prefs::kXkbAutoRepeatIntervalInMs, |
| 177 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 4ccc05e | 2010-10-06 19:32:15 | [diff] [blame] | 178 | |
[email protected] | f410d61 | 2011-08-05 04:32:24 | [diff] [blame] | 179 | prefs->RegisterDictionaryPref(prefs::kLanguagePreferredVirtualKeyboard, |
| 180 | PrefService::SYNCABLE_PREF); |
| 181 | |
[email protected] | 4ccc05e | 2010-10-06 19:32:15 | [diff] [blame] | 182 | // Screen lock default to off. |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 183 | prefs->RegisterBooleanPref(prefs::kEnableScreenLock, |
| 184 | false, |
| 185 | PrefService::SYNCABLE_PREF); |
[email protected] | ea1eba5 | 2010-11-23 18:05:38 | [diff] [blame] | 186 | |
| 187 | // Mobile plan notifications default to on. |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 188 | prefs->RegisterBooleanPref(prefs::kShowPlanNotifications, |
| 189 | true, |
| 190 | PrefService::SYNCABLE_PREF); |
[email protected] | c74fffa | 2011-04-27 13:32:24 | [diff] [blame] | 191 | |
| 192 | // 3G first-time usage promo will be shown at least once. |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 193 | prefs->RegisterBooleanPref(prefs::kShow3gPromoNotification, |
| 194 | true, |
| 195 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d6ae950 | 2011-05-05 18:23:09 | [diff] [blame] | 196 | |
[email protected] | cc8f247 | 2011-08-01 07:14:46 | [diff] [blame] | 197 | // 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] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void Preferences::Init(PrefService* prefs) { |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 207 | tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this); |
[email protected] | 7ef254b | 2011-12-08 03:24:45 | [diff] [blame^] | 208 | accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, prefs, this); |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 209 | sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, this); |
[email protected] | 530cd62 | 2011-04-14 15:45:00 | [diff] [blame] | 210 | use_24hour_clock_.Init(prefs::kUse24HourClock, prefs, this); |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 211 | 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] | 74b42fc1 | 2010-07-20 10:15:41 | [diff] [blame] | 215 | language_preferred_languages_.Init(prefs::kLanguagePreferredLanguages, |
| 216 | prefs, this); |
[email protected] | 70aa5b3 | 2010-04-05 08:30:34 | [diff] [blame] | 217 | language_preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, this); |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 218 | for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { |
[email protected] | 525dbe2 | 2010-06-01 07:05:43 | [diff] [blame] | 219 | language_chewing_boolean_prefs_[i].Init( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 220 | language_prefs::kChewingBooleanPrefs[i].pref_name, prefs, this); |
[email protected] | 525dbe2 | 2010-06-01 07:05:43 | [diff] [blame] | 221 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 222 | for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) { |
[email protected] | 525dbe2 | 2010-06-01 07:05:43 | [diff] [blame] | 223 | language_chewing_multiple_choice_prefs_[i].Init( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 224 | language_prefs::kChewingMultipleChoicePrefs[i].pref_name, prefs, this); |
[email protected] | 525dbe2 | 2010-06-01 07:05:43 | [diff] [blame] | 225 | } |
[email protected] | 7ac5af9 | 2010-06-07 01:25:44 | [diff] [blame] | 226 | language_chewing_hsu_sel_key_type_.Init( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 227 | language_prefs::kChewingHsuSelKeyType.pref_name, prefs, this); |
| 228 | for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) { |
[email protected] | 15c5308 | 2010-06-03 03:28:21 | [diff] [blame] | 229 | language_chewing_integer_prefs_[i].Init( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 230 | language_prefs::kChewingIntegerPrefs[i].pref_name, prefs, this); |
[email protected] | 15c5308 | 2010-06-03 03:28:21 | [diff] [blame] | 231 | } |
[email protected] | 5095143 | 2010-03-31 12:12:42 | [diff] [blame] | 232 | language_hangul_keyboard_.Init(prefs::kLanguageHangulKeyboard, prefs, this); |
[email protected] | 33444cf | 2011-08-04 06:33:55 | [diff] [blame] | 233 | language_hangul_hanja_binding_keys_.Init( |
| 234 | prefs::kLanguageHangulHanjaBindingKeys, prefs, this); |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 235 | for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { |
[email protected] | 9040ad2 | 2010-04-22 04:29:28 | [diff] [blame] | 236 | language_pinyin_boolean_prefs_[i].Init( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 237 | language_prefs::kPinyinBooleanPrefs[i].pref_name, prefs, this); |
[email protected] | 9040ad2 | 2010-04-22 04:29:28 | [diff] [blame] | 238 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 239 | for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) { |
[email protected] | 9040ad2 | 2010-04-22 04:29:28 | [diff] [blame] | 240 | language_pinyin_int_prefs_[i].Init( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 241 | language_prefs::kPinyinIntegerPrefs[i].pref_name, prefs, this); |
[email protected] | 9040ad2 | 2010-04-22 04:29:28 | [diff] [blame] | 242 | } |
[email protected] | 7ac5af9 | 2010-06-07 01:25:44 | [diff] [blame] | 243 | language_pinyin_double_pinyin_schema_.Init( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 244 | language_prefs::kPinyinDoublePinyinSchema.pref_name, prefs, this); |
| 245 | for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) { |
[email protected] | 8a1ace2 | 2010-06-10 05:38:25 | [diff] [blame] | 246 | language_mozc_boolean_prefs_[i].Init( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 247 | language_prefs::kMozcBooleanPrefs[i].pref_name, prefs, this); |
[email protected] | 8a1ace2 | 2010-06-10 05:38:25 | [diff] [blame] | 248 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 249 | for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) { |
[email protected] | 6e5c4b8 | 2010-05-24 08:18:44 | [diff] [blame] | 250 | language_mozc_multiple_choice_prefs_[i].Init( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 251 | language_prefs::kMozcMultipleChoicePrefs[i].pref_name, prefs, this); |
[email protected] | 6e5c4b8 | 2010-05-24 08:18:44 | [diff] [blame] | 252 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 253 | for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) { |
[email protected] | 5403746 | 2010-06-22 02:06:23 | [diff] [blame] | 254 | language_mozc_integer_prefs_[i].Init( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 255 | language_prefs::kMozcIntegerPrefs[i].pref_name, prefs, this); |
[email protected] | 5403746 | 2010-06-22 02:06:23 | [diff] [blame] | 256 | } |
[email protected] | b5194dd3 | 2010-08-12 10:40:04 | [diff] [blame] | 257 | 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] | a995b39 | 2010-08-11 04:38:59 | [diff] [blame] | 263 | language_xkb_auto_repeat_enabled_.Init( |
| 264 | prefs::kLanguageXkbAutoRepeatEnabled, prefs, this); |
| 265 | language_xkb_auto_repeat_delay_pref_.Init( |
[email protected] | 4743dad | 2010-08-30 01:41:07 | [diff] [blame] | 266 | prefs::kLanguageXkbAutoRepeatDelay, prefs, this); |
[email protected] | a995b39 | 2010-08-11 04:38:59 | [diff] [blame] | 267 | language_xkb_auto_repeat_interval_pref_.Init( |
[email protected] | 4743dad | 2010-08-30 01:41:07 | [diff] [blame] | 268 | prefs::kLanguageXkbAutoRepeatInterval, prefs, this); |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 269 | |
[email protected] | 4ccc05e | 2010-10-06 19:32:15 | [diff] [blame] | 270 | enable_screen_lock_.Init(prefs::kEnableScreenLock, prefs, this); |
| 271 | |
[email protected] | d7ca1ba | 2011-05-09 20:09:08 | [diff] [blame] | 272 | // Initialize preferences to currently saved state. |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 273 | NotifyPrefChanged(NULL); |
[email protected] | 26012e2 | 2010-12-01 06:44:27 | [diff] [blame] | 274 | |
[email protected] | f410d61 | 2011-08-05 04:32:24 | [diff] [blame] | 275 | // Initialize virtual keyboard settings to currently saved state. |
| 276 | UpdateVirturalKeyboardPreference(prefs); |
| 277 | |
[email protected] | 26012e2 | 2010-12-01 06:44:27 | [diff] [blame] | 278 | // 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] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 283 | } |
| 284 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 285 | void Preferences::Observe(int type, |
[email protected] | 86ab86b | 2011-10-19 03:07:55 | [diff] [blame] | 286 | const content::NotificationSource& source, |
| 287 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 288 | if (type == chrome::NOTIFICATION_PREF_CHANGED) |
[email protected] | a0bbc40 | 2011-10-19 04:28:30 | [diff] [blame] | 289 | NotifyPrefChanged(content::Details<std::string>(details).ptr()); |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 290 | } |
| 291 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 292 | void Preferences::NotifyPrefChanged(const std::string* pref_name) { |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 293 | if (!pref_name || *pref_name == prefs::kTapToClickEnabled) { |
[email protected] | d7ca1ba | 2011-05-09 20:09:08 | [diff] [blame] | 294 | bool enabled = tap_to_click_enabled_.GetValue(); |
[email protected] | 1cbfb3b | 2011-07-11 23:34:08 | [diff] [blame] | 295 | system::touchpad_settings::SetTapToClick(enabled); |
[email protected] | d7ca1ba | 2011-05-09 20:09:08 | [diff] [blame] | 296 | if (pref_name) |
| 297 | UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled); |
| 298 | else |
| 299 | UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Started", enabled); |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 300 | } |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 301 | if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) { |
[email protected] | d7ca1ba | 2011-05-09 20:09:08 | [diff] [blame] | 302 | int sensitivity = sensitivity_.GetValue(); |
[email protected] | 1cbfb3b | 2011-07-11 23:34:08 | [diff] [blame] | 303 | system::touchpad_settings::SetSensitivity(sensitivity); |
[email protected] | d7ca1ba | 2011-05-09 20:09:08 | [diff] [blame] | 304 | 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] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 311 | } |
[email protected] | 8be9ff2 | 2010-06-08 02:13:54 | [diff] [blame] | 312 | |
| 313 | // We don't handle prefs::kLanguageCurrentInputMethod and PreviousInputMethod |
| 314 | // here. |
| 315 | |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 316 | if (!pref_name || *pref_name == prefs::kLanguageHotkeyNextEngineInMenu) { |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 317 | SetLanguageConfigStringListAsCSV( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 318 | language_prefs::kHotKeySectionName, |
| 319 | language_prefs::kNextEngineInMenuConfigName, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 320 | language_hotkey_next_engine_in_menu_.GetValue()); |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 321 | } |
| 322 | if (!pref_name || *pref_name == prefs::kLanguageHotkeyPreviousEngine) { |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 323 | SetLanguageConfigStringListAsCSV( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 324 | language_prefs::kHotKeySectionName, |
| 325 | language_prefs::kPreviousEngineConfigName, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 326 | language_hotkey_previous_engine_.GetValue()); |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 327 | } |
[email protected] | 74b42fc1 | 2010-07-20 10:15:41 | [diff] [blame] | 328 | 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] | a6e9077 | 2011-02-09 05:38:54 | [diff] [blame] | 332 | |
| 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] | e6e8336 | 2011-09-16 07:28:00 | [diff] [blame] | 345 | input_method::XKeyboard::SetAutoRepeatEnabled(enabled); |
[email protected] | a6e9077 | 2011-02-09 05:38:54 | [diff] [blame] | 346 | } |
| 347 | if (!pref_name || ((*pref_name == prefs::kLanguageXkbAutoRepeatDelay) || |
| 348 | (*pref_name == prefs::kLanguageXkbAutoRepeatInterval))) { |
| 349 | UpdateAutoRepeatRate(); |
| 350 | } |
| 351 | |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 352 | if (!pref_name || *pref_name == prefs::kLanguagePreloadEngines) { |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 353 | SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, |
| 354 | language_prefs::kPreloadEnginesConfigName, |
[email protected] | d01bb807 | 2010-04-12 13:00:15 | [diff] [blame] | 355 | language_preload_engines_.GetValue()); |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 356 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 357 | 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] | 525dbe2 | 2010-06-01 07:05:43 | [diff] [blame] | 364 | } |
| 365 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 366 | 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] | 525dbe2 | 2010-06-01 07:05:43 | [diff] [blame] | 370 | SetLanguageConfigString( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 371 | language_prefs::kChewingSectionName, |
| 372 | language_prefs::kChewingMultipleChoicePrefs[i].ibus_config_name, |
[email protected] | 525dbe2 | 2010-06-01 07:05:43 | [diff] [blame] | 373 | language_chewing_multiple_choice_prefs_[i].GetValue()); |
| 374 | } |
| 375 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 376 | if (!pref_name || |
| 377 | *pref_name == language_prefs::kChewingHsuSelKeyType.pref_name) { |
[email protected] | 7ac5af9 | 2010-06-07 01:25:44 | [diff] [blame] | 378 | SetLanguageConfigInteger( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 379 | language_prefs::kChewingSectionName, |
| 380 | language_prefs::kChewingHsuSelKeyType.ibus_config_name, |
[email protected] | 7ac5af9 | 2010-06-07 01:25:44 | [diff] [blame] | 381 | language_chewing_hsu_sel_key_type_.GetValue()); |
| 382 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 383 | 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] | 15c5308 | 2010-06-03 03:28:21 | [diff] [blame] | 390 | } |
| 391 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 392 | if (!pref_name || |
| 393 | *pref_name == prefs::kLanguageHangulKeyboard) { |
| 394 | SetLanguageConfigString(language_prefs::kHangulSectionName, |
| 395 | language_prefs::kHangulKeyboardConfigName, |
[email protected] | 5095143 | 2010-03-31 12:12:42 | [diff] [blame] | 396 | language_hangul_keyboard_.GetValue()); |
[email protected] | 3b02de29 | 2010-05-13 06:05:05 | [diff] [blame] | 397 | } |
[email protected] | 33444cf | 2011-08-04 06:33:55 | [diff] [blame] | 398 | 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] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 403 | 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] | 9040ad2 | 2010-04-22 04:29:28 | [diff] [blame] | 410 | } |
| 411 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 412 | 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] | 9040ad2 | 2010-04-22 04:29:28 | [diff] [blame] | 419 | } |
| 420 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 421 | if (!pref_name || |
| 422 | *pref_name == language_prefs::kPinyinDoublePinyinSchema.pref_name) { |
[email protected] | 7ac5af9 | 2010-06-07 01:25:44 | [diff] [blame] | 423 | SetLanguageConfigInteger( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 424 | language_prefs::kPinyinSectionName, |
| 425 | language_prefs::kPinyinDoublePinyinSchema.ibus_config_name, |
[email protected] | 7ac5af9 | 2010-06-07 01:25:44 | [diff] [blame] | 426 | language_pinyin_double_pinyin_schema_.GetValue()); |
| 427 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 428 | 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] | 8a1ace2 | 2010-06-10 05:38:25 | [diff] [blame] | 435 | } |
| 436 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 437 | 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] | 6e5c4b8 | 2010-05-24 08:18:44 | [diff] [blame] | 440 | SetLanguageConfigString( |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 441 | language_prefs::kMozcSectionName, |
| 442 | language_prefs::kMozcMultipleChoicePrefs[i].ibus_config_name, |
[email protected] | 6e5c4b8 | 2010-05-24 08:18:44 | [diff] [blame] | 443 | language_mozc_multiple_choice_prefs_[i].GetValue()); |
| 444 | } |
| 445 | } |
[email protected] | b65c5d2 | 2010-08-20 02:50:23 | [diff] [blame] | 446 | 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] | 5403746 | 2010-06-22 02:06:23 | [diff] [blame] | 453 | } |
| 454 | } |
[email protected] | 4793c94 | 2010-09-21 23:17:17 | [diff] [blame] | 455 | |
[email protected] | 4ccc05e | 2010-10-06 19:32:15 | [diff] [blame] | 456 | // Init or update power manager config. |
| 457 | if (!pref_name || *pref_name == prefs::kEnableScreenLock) { |
[email protected] | a329ebe | 2011-11-22 23:26:49 | [diff] [blame] | 458 | system::screen_locker_settings::EnableScreenLock( |
[email protected] | 4ccc05e | 2010-10-06 19:32:15 | [diff] [blame] | 459 | enable_screen_lock_.GetValue()); |
| 460 | } |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 461 | } |
| 462 | |
[email protected] | 70aa5b3 | 2010-04-05 08:30:34 | [diff] [blame] | 463 | void Preferences::SetLanguageConfigBoolean(const char* section, |
| 464 | const char* name, |
| 465 | bool value) { |
[email protected] | dc7b094 | 2011-06-15 06:45:53 | [diff] [blame] | 466 | input_method::ImeConfigValue config; |
| 467 | config.type = input_method::ImeConfigValue::kValueTypeBool; |
[email protected] | 70aa5b3 | 2010-04-05 08:30:34 | [diff] [blame] | 468 | config.bool_value = value; |
[email protected] | c8d4e946 | 2011-06-29 23:18:57 | [diff] [blame] | 469 | input_method::InputMethodManager::GetInstance()-> |
[email protected] | 60b0768 | 2010-06-17 08:45:28 | [diff] [blame] | 470 | SetImeConfig(section, name, config); |
[email protected] | 70aa5b3 | 2010-04-05 08:30:34 | [diff] [blame] | 471 | } |
| 472 | |
[email protected] | 9040ad2 | 2010-04-22 04:29:28 | [diff] [blame] | 473 | void Preferences::SetLanguageConfigInteger(const char* section, |
| 474 | const char* name, |
| 475 | int value) { |
[email protected] | dc7b094 | 2011-06-15 06:45:53 | [diff] [blame] | 476 | input_method::ImeConfigValue config; |
| 477 | config.type = input_method::ImeConfigValue::kValueTypeInt; |
[email protected] | 9040ad2 | 2010-04-22 04:29:28 | [diff] [blame] | 478 | config.int_value = value; |
[email protected] | c8d4e946 | 2011-06-29 23:18:57 | [diff] [blame] | 479 | input_method::InputMethodManager::GetInstance()-> |
[email protected] | 60b0768 | 2010-06-17 08:45:28 | [diff] [blame] | 480 | SetImeConfig(section, name, config); |
[email protected] | 9040ad2 | 2010-04-22 04:29:28 | [diff] [blame] | 481 | } |
| 482 | |
[email protected] | 5095143 | 2010-03-31 12:12:42 | [diff] [blame] | 483 | void Preferences::SetLanguageConfigString(const char* section, |
| 484 | const char* name, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 485 | const std::string& value) { |
[email protected] | dc7b094 | 2011-06-15 06:45:53 | [diff] [blame] | 486 | input_method::ImeConfigValue config; |
| 487 | config.type = input_method::ImeConfigValue::kValueTypeString; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 488 | config.string_value = value; |
[email protected] | c8d4e946 | 2011-06-29 23:18:57 | [diff] [blame] | 489 | input_method::InputMethodManager::GetInstance()-> |
[email protected] | 60b0768 | 2010-06-17 08:45:28 | [diff] [blame] | 490 | SetImeConfig(section, name, config); |
[email protected] | 5095143 | 2010-03-31 12:12:42 | [diff] [blame] | 491 | } |
| 492 | |
[email protected] | 2c25ddfd | 2010-04-09 10:35:55 | [diff] [blame] | 493 | void Preferences::SetLanguageConfigStringList( |
| 494 | const char* section, |
| 495 | const char* name, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 496 | const std::vector<std::string>& values) { |
[email protected] | dc7b094 | 2011-06-15 06:45:53 | [diff] [blame] | 497 | input_method::ImeConfigValue config; |
| 498 | config.type = input_method::ImeConfigValue::kValueTypeStringList; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 499 | for (size_t i = 0; i < values.size(); ++i) |
| 500 | config.string_list_value.push_back(values[i]); |
| 501 | |
[email protected] | c8d4e946 | 2011-06-29 23:18:57 | [diff] [blame] | 502 | input_method::InputMethodManager::GetInstance()-> |
[email protected] | 60b0768 | 2010-06-17 08:45:28 | [diff] [blame] | 503 | SetImeConfig(section, name, config); |
[email protected] | 2c25ddfd | 2010-04-09 10:35:55 | [diff] [blame] | 504 | } |
| 505 | |
[email protected] | d01bb807 | 2010-04-12 13:00:15 | [diff] [blame] | 506 | void Preferences::SetLanguageConfigStringListAsCSV(const char* section, |
| 507 | const char* name, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 508 | const std::string& value) { |
[email protected] | e24c2c9 | 2010-10-23 01:39:24 | [diff] [blame] | 509 | VLOG(1) << "Setting " << name << " to '" << value << "'"; |
[email protected] | d01bb807 | 2010-04-12 13:00:15 | [diff] [blame] | 510 | |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 511 | std::vector<std::string> split_values; |
| 512 | if (!value.empty()) |
[email protected] | 76eb024 | 2010-10-14 00:35:36 | [diff] [blame] | 513 | base::SplitString(value, ',', &split_values); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 514 | |
[email protected] | 2c25ddfd | 2010-04-09 10:35:55 | [diff] [blame] | 515 | // We should call the cros API even when |value| is empty, to disable default |
[email protected] | d01bb807 | 2010-04-12 13:00:15 | [diff] [blame] | 516 | // config. |
| 517 | SetLanguageConfigStringList(section, name, split_values); |
[email protected] | 70aa5b3 | 2010-04-05 08:30:34 | [diff] [blame] | 518 | } |
| 519 | |
[email protected] | b5194dd3 | 2010-08-12 10:40:04 | [diff] [blame] | 520 | void 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] | c010f63 | 2011-04-01 06:44:39 | [diff] [blame] | 524 | 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] | b5194dd3 | 2010-08-12 10:40:04 | [diff] [blame] | 529 | modifier_map.push_back( |
[email protected] | c010f63 | 2011-04-01 06:44:39 | [diff] [blame] | 530 | input_method::ModifierKeyPair( |
| 531 | input_method::kSearchKey, |
| 532 | input_method::ModifierKey(search_remap))); |
[email protected] | b5194dd3 | 2010-08-12 10:40:04 | [diff] [blame] | 533 | modifier_map.push_back( |
[email protected] | c010f63 | 2011-04-01 06:44:39 | [diff] [blame] | 534 | input_method::ModifierKeyPair( |
| 535 | input_method::kLeftControlKey, |
| 536 | input_method::ModifierKey(control_remap))); |
[email protected] | b5194dd3 | 2010-08-12 10:40:04 | [diff] [blame] | 537 | modifier_map.push_back( |
[email protected] | c010f63 | 2011-04-01 06:44:39 | [diff] [blame] | 538 | input_method::ModifierKeyPair( |
| 539 | input_method::kLeftAltKey, |
| 540 | input_method::ModifierKey(alt_remap))); |
[email protected] | e6e8336 | 2011-09-16 07:28:00 | [diff] [blame] | 541 | input_method::InputMethodManager::GetInstance()->GetXKeyboard()-> |
| 542 | RemapModifierKeys(modifier_map); |
[email protected] | b5194dd3 | 2010-08-12 10:40:04 | [diff] [blame] | 543 | } else { |
| 544 | LOG(ERROR) << "Failed to remap modifier keys. Unexpected value(s): " |
| 545 | << search_remap << ", " << control_remap << ", " << alt_remap; |
| 546 | } |
| 547 | } |
| 548 | |
[email protected] | a995b39 | 2010-08-11 04:38:59 | [diff] [blame] | 549 | void Preferences::UpdateAutoRepeatRate() { |
[email protected] | c010f63 | 2011-04-01 06:44:39 | [diff] [blame] | 550 | input_method::AutoRepeatRate rate; |
[email protected] | a995b39 | 2010-08-11 04:38:59 | [diff] [blame] | 551 | 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] | e6e8336 | 2011-09-16 07:28:00 | [diff] [blame] | 556 | input_method::XKeyboard::SetAutoRepeatRate(rate); |
[email protected] | a995b39 | 2010-08-11 04:38:59 | [diff] [blame] | 557 | } |
| 558 | |
[email protected] | f410d61 | 2011-08-05 04:32:24 | [diff] [blame] | 559 | void 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] | b336257 | 2011-08-17 09:28:50 | [diff] [blame] | 569 | std::vector<std::string> layouts_to_remove; |
[email protected] | f410d61 | 2011-08-05 04:32:24 | [diff] [blame] | 570 | for (DictionaryValue::key_iterator iter = virtual_keyboard_pref->begin_keys(); |
| 571 | iter != virtual_keyboard_pref->end_keys(); |
| 572 | ++iter) { |
[email protected] | b336257 | 2011-08-17 09:28:50 | [diff] [blame] | 573 | const std::string& layout_id = *iter; // e.g. "us", "handwriting-vk" |
| 574 | if (!virtual_keyboard_pref->GetString(layout_id, &url)) |
[email protected] | f410d61 | 2011-08-05 04:32:24 | [diff] [blame] | 575 | continue; |
[email protected] | b336257 | 2011-08-17 09:28:50 | [diff] [blame] | 576 | 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] | 148994e | 2011-08-17 10:01:48 | [diff] [blame] | 581 | LOG(ERROR) << "Removing invalid virtual keyboard pref: layout=" |
| 582 | << layout_id; |
[email protected] | b336257 | 2011-08-17 09:28:50 | [diff] [blame] | 583 | } |
| 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] | f410d61 | 2011-08-05 04:32:24 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
[email protected] | fecc152 | 2009-10-15 21:08:29 | [diff] [blame] | 594 | } // namespace chromeos |