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