blob: bcf86f2e4a82f3931866b37c5b31c39da4a63a7d [file] [log] [blame]
[email protected]2b2820a2011-03-07 22:28:401// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]fecc1522009-10-15 21:08:292// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chromeos/preferences.h"
6
[email protected]775caec2011-09-01 17:14:327#include "base/command_line.h"
[email protected]530cd622011-04-14 15:45:008#include "base/i18n/time_formatting.h"
[email protected]d7ca1ba2011-05-09 20:09:089#include "base/metrics/histogram.h"
[email protected]4e5ae20f2010-09-24 04:52:1110#include "base/string_split.h"
[email protected]fecc1522009-10-15 21:08:2911#include "base/string_util.h"
[email protected]50951432010-03-31 12:12:4212#include "base/utf_string_conversions.h"
[email protected]c0a2128d92011-07-20 15:04:4613#include "chrome/browser/browser_process.h"
[email protected]62c7ef32010-03-23 23:44:2414#include "chrome/browser/chromeos/cros/cros_library.h"
[email protected]4ccc05e2010-10-06 19:32:1515#include "chrome/browser/chromeos/cros/power_library.h"
[email protected]c8d4e9462011-06-29 23:18:5716#include "chrome/browser/chromeos/input_method/input_method_manager.h"
[email protected]9199bd52010-07-01 05:04:4117#include "chrome/browser/chromeos/input_method/input_method_util.h"
[email protected]c010f632011-04-01 06:44:3918#include "chrome/browser/chromeos/input_method/xkeyboard.h"
[email protected]26012e22010-12-01 06:44:2719#include "chrome/browser/chromeos/login/login_utils.h"
[email protected]c0a2128d92011-07-20 15:04:4620#include "chrome/browser/chromeos/proxy_config_service_impl.h"
[email protected]1cbfb3b2011-07-11 23:34:0821#include "chrome/browser/chromeos/system/touchpad_settings.h"
[email protected]37858e52010-08-26 00:22:0222#include "chrome/browser/prefs/pref_member.h"
23#include "chrome/browser/prefs/pref_service.h"
[email protected]b3362572011-08-17 09:28:5024#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]432115822011-07-10 15:52:2725#include "chrome/common/chrome_notification_types.h"
[email protected]775caec2011-09-01 17:14:3226#include "chrome/common/chrome_switches.h"
[email protected]fecc1522009-10-15 21:08:2927#include "chrome/common/pref_names.h"
[email protected]2b2820a2011-03-07 22:28:4028#include "content/common/notification_details.h"
29#include "content/common/notification_source.h"
[email protected]fecc1522009-10-15 21:08:2930#include "unicode/timezone.h"
31
32namespace chromeos {
33
[email protected]9199bd52010-07-01 05:04:4134static const char kFallbackInputMethodLocale[] = "en-US";
[email protected]4793c942010-09-21 23:17:1735
[email protected]d743a5982010-11-08 17:54:0936Preferences::Preferences() {}
37
38Preferences::~Preferences() {}
[email protected]9199bd52010-07-01 05:04:4139
[email protected]fecc1522009-10-15 21:08:2940// static
41void Preferences::RegisterUserPrefs(PrefService* prefs) {
[email protected]d36f941b2011-05-09 06:19:1642 prefs->RegisterBooleanPref(prefs::kTapToClickEnabled,
43 false,
44 PrefService::SYNCABLE_PREF);
45 prefs->RegisterBooleanPref(prefs::kLabsMediaplayerEnabled,
46 false,
47 PrefService::UNSYNCABLE_PREF);
48 prefs->RegisterBooleanPref(prefs::kLabsAdvancedFilesystemEnabled,
49 false,
50 PrefService::UNSYNCABLE_PREF);
[email protected]27f20d52010-09-18 00:59:3151 // Check if the accessibility pref is already registered, which can happen
52 // in WizardController::RegisterPrefs. We still want to try to register
53 // the pref here in case of Chrome/Linux with ChromeOS=1.
54 if (prefs->FindPreference(prefs::kAccessibilityEnabled) == NULL) {
[email protected]d36f941b2011-05-09 06:19:1655 prefs->RegisterBooleanPref(prefs::kAccessibilityEnabled,
56 false,
57 PrefService::UNSYNCABLE_PREF);
[email protected]27f20d52010-09-18 00:59:3158 }
[email protected]d36f941b2011-05-09 06:19:1659 prefs->RegisterIntegerPref(prefs::kTouchpadSensitivity,
60 3,
61 PrefService::UNSYNCABLE_PREF);
[email protected]530cd622011-04-14 15:45:0062 prefs->RegisterBooleanPref(prefs::kUse24HourClock,
[email protected]d36f941b2011-05-09 06:19:1663 base::GetHourClockType() == base::k24HourClock,
64 PrefService::SYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:1065 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod
66 // because they're just used to track the logout state of the device.
[email protected]d36f941b2011-05-09 06:19:1667 prefs->RegisterStringPref(prefs::kLanguageCurrentInputMethod,
68 "",
69 PrefService::UNSYNCABLE_PREF);
70 prefs->RegisterStringPref(prefs::kLanguagePreviousInputMethod,
71 "",
72 PrefService::UNSYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:1073 // We don't sync input method hotkeys since they're not configurable.
[email protected]3b02de292010-05-13 06:05:0574 prefs->RegisterStringPref(prefs::kLanguageHotkeyNextEngineInMenu,
[email protected]d36f941b2011-05-09 06:19:1675 language_prefs::kHotkeyNextEngineInMenu,
76 PrefService::UNSYNCABLE_PREF);
[email protected]3b02de292010-05-13 06:05:0577 prefs->RegisterStringPref(prefs::kLanguageHotkeyPreviousEngine,
[email protected]d36f941b2011-05-09 06:19:1678 language_prefs::kHotkeyPreviousEngine,
79 PrefService::UNSYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:1080 // We don't sync the list of input methods and preferred languages since a
81 // user might use two or more devices with different hardware keyboards.
82 // crosbug.com/15181
[email protected]c5d45432010-09-07 08:25:3583 prefs->RegisterStringPref(prefs::kLanguagePreferredLanguages,
[email protected]d36f941b2011-05-09 06:19:1684 kFallbackInputMethodLocale,
[email protected]aa96e372011-05-16 06:23:1085 PrefService::UNSYNCABLE_PREF);
[email protected]d36f941b2011-05-09 06:19:1686 prefs->RegisterStringPref(prefs::kLanguagePreloadEngines,
87 input_method::GetHardwareInputMethodId(),
[email protected]aa96e372011-05-16 06:23:1088 PrefService::UNSYNCABLE_PREF);
[email protected]b65c5d22010-08-20 02:50:2389 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
90 prefs->RegisterBooleanPref(
91 language_prefs::kChewingBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:1692 language_prefs::kChewingBooleanPrefs[i].default_pref_value,
93 PrefService::UNSYNCABLE_PREF);
[email protected]525dbe22010-06-01 07:05:4394 }
[email protected]b65c5d22010-08-20 02:50:2395 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:4396 prefs->RegisterStringPref(
[email protected]b65c5d22010-08-20 02:50:2397 language_prefs::kChewingMultipleChoicePrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:1698 language_prefs::kChewingMultipleChoicePrefs[i].default_pref_value,
99 PrefService::UNSYNCABLE_PREF);
[email protected]525dbe22010-06-01 07:05:43100 }
[email protected]b65c5d22010-08-20 02:50:23101 prefs->RegisterIntegerPref(
102 language_prefs::kChewingHsuSelKeyType.pref_name,
[email protected]d36f941b2011-05-09 06:19:16103 language_prefs::kChewingHsuSelKeyType.default_pref_value,
104 PrefService::UNSYNCABLE_PREF);
[email protected]7ac5af92010-06-07 01:25:44105
[email protected]b65c5d22010-08-20 02:50:23106 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
107 prefs->RegisterIntegerPref(
108 language_prefs::kChewingIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16109 language_prefs::kChewingIntegerPrefs[i].default_pref_value,
110 PrefService::UNSYNCABLE_PREF);
[email protected]15c53082010-06-03 03:28:21111 }
[email protected]20ce516d2010-06-18 02:20:04112 prefs->RegisterStringPref(
113 prefs::kLanguageHangulKeyboard,
[email protected]d36f941b2011-05-09 06:19:16114 language_prefs::kHangulKeyboardNameIDPairs[0].keyboard_id,
115 PrefService::SYNCABLE_PREF);
[email protected]33444cf2011-08-04 06:33:55116 prefs->RegisterStringPref(prefs::kLanguageHangulHanjaBindingKeys,
117 language_prefs::kHangulHanjaBindingKeys,
118 // Don't sync the pref as it's not user-configurable
119 PrefService::UNSYNCABLE_PREF);
[email protected]b65c5d22010-08-20 02:50:23120 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
121 prefs->RegisterBooleanPref(
122 language_prefs::kPinyinBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16123 language_prefs::kPinyinBooleanPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51124 language_prefs::kPinyinBooleanPrefs[i].sync_status);
[email protected]9040ad22010-04-22 04:29:28125 }
[email protected]b65c5d22010-08-20 02:50:23126 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
127 prefs->RegisterIntegerPref(
128 language_prefs::kPinyinIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16129 language_prefs::kPinyinIntegerPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51130 language_prefs::kPinyinIntegerPrefs[i].sync_status);
[email protected]6e5c4b82010-05-24 08:18:44131 }
[email protected]b65c5d22010-08-20 02:50:23132 prefs->RegisterIntegerPref(
133 language_prefs::kPinyinDoublePinyinSchema.pref_name,
[email protected]d36f941b2011-05-09 06:19:16134 language_prefs::kPinyinDoublePinyinSchema.default_pref_value,
135 PrefService::UNSYNCABLE_PREF);
[email protected]7ac5af92010-06-07 01:25:44136
[email protected]b65c5d22010-08-20 02:50:23137 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
138 prefs->RegisterBooleanPref(
139 language_prefs::kMozcBooleanPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16140 language_prefs::kMozcBooleanPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51141 language_prefs::kMozcBooleanPrefs[i].sync_status);
[email protected]8a1ace22010-06-10 05:38:25142 }
[email protected]b65c5d22010-08-20 02:50:23143 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
[email protected]7ac5af92010-06-07 01:25:44144 prefs->RegisterStringPref(
[email protected]b65c5d22010-08-20 02:50:23145 language_prefs::kMozcMultipleChoicePrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16146 language_prefs::kMozcMultipleChoicePrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51147 language_prefs::kMozcMultipleChoicePrefs[i].sync_status);
[email protected]9040ad22010-04-22 04:29:28148 }
[email protected]b65c5d22010-08-20 02:50:23149 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
150 prefs->RegisterIntegerPref(
151 language_prefs::kMozcIntegerPrefs[i].pref_name,
[email protected]d36f941b2011-05-09 06:19:16152 language_prefs::kMozcIntegerPrefs[i].default_pref_value,
[email protected]203bec62011-05-16 06:17:51153 language_prefs::kMozcIntegerPrefs[i].sync_status);
[email protected]54037462010-06-22 02:06:23154 }
[email protected]c010f632011-04-01 06:44:39155 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapSearchKeyTo,
[email protected]d36f941b2011-05-09 06:19:16156 input_method::kSearchKey,
157 PrefService::SYNCABLE_PREF);
[email protected]b5194dd32010-08-12 10:40:04158 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapControlKeyTo,
[email protected]d36f941b2011-05-09 06:19:16159 input_method::kLeftControlKey,
160 PrefService::SYNCABLE_PREF);
[email protected]c010f632011-04-01 06:44:39161 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapAltKeyTo,
[email protected]d36f941b2011-05-09 06:19:16162 input_method::kLeftAltKey,
163 PrefService::SYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:10164 // We don't sync the following keyboard prefs since they are not user-
165 // configurable.
[email protected]d36f941b2011-05-09 06:19:16166 prefs->RegisterBooleanPref(prefs::kLanguageXkbAutoRepeatEnabled,
167 true,
168 PrefService::UNSYNCABLE_PREF);
[email protected]4743dad2010-08-30 01:41:07169 prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatDelay,
[email protected]d36f941b2011-05-09 06:19:16170 language_prefs::kXkbAutoRepeatDelayInMs,
171 PrefService::UNSYNCABLE_PREF);
[email protected]4743dad2010-08-30 01:41:07172 prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatInterval,
[email protected]d36f941b2011-05-09 06:19:16173 language_prefs::kXkbAutoRepeatIntervalInMs,
174 PrefService::UNSYNCABLE_PREF);
[email protected]4ccc05e2010-10-06 19:32:15175
[email protected]f410d612011-08-05 04:32:24176 prefs->RegisterDictionaryPref(prefs::kLanguagePreferredVirtualKeyboard,
177 PrefService::SYNCABLE_PREF);
178
[email protected]4ccc05e2010-10-06 19:32:15179 // Screen lock default to off.
[email protected]d36f941b2011-05-09 06:19:16180 prefs->RegisterBooleanPref(prefs::kEnableScreenLock,
181 false,
182 PrefService::SYNCABLE_PREF);
[email protected]ea1eba52010-11-23 18:05:38183
184 // Mobile plan notifications default to on.
[email protected]d36f941b2011-05-09 06:19:16185 prefs->RegisterBooleanPref(prefs::kShowPlanNotifications,
186 true,
187 PrefService::SYNCABLE_PREF);
[email protected]c74fffa2011-04-27 13:32:24188
189 // 3G first-time usage promo will be shown at least once.
[email protected]d36f941b2011-05-09 06:19:16190 prefs->RegisterBooleanPref(prefs::kShow3gPromoNotification,
191 true,
192 PrefService::UNSYNCABLE_PREF);
[email protected]d6ae9502011-05-05 18:23:09193
[email protected]ea3cd242011-05-08 17:35:56194 // The map of timestamps of the last used file browser handlers.
[email protected]d36f941b2011-05-09 06:19:16195 prefs->RegisterDictionaryPref(prefs::kLastUsedFileBrowserHandlers,
196 PrefService::UNSYNCABLE_PREF);
[email protected]c0a2128d92011-07-20 15:04:46197
198 // Use shared proxies default to off.
199 prefs->RegisterBooleanPref(prefs::kUseSharedProxies,
200 false,
201 PrefService::SYNCABLE_PREF);
[email protected]cc8f2472011-08-01 07:14:46202
203 // OAuth1 all access token and secret pair.
204 prefs->RegisterStringPref(prefs::kOAuth1Token,
205 "",
206 PrefService::UNSYNCABLE_PREF);
207 prefs->RegisterStringPref(prefs::kOAuth1Secret,
208 "",
209 PrefService::UNSYNCABLE_PREF);
[email protected]fecc1522009-10-15 21:08:29210}
211
212void Preferences::Init(PrefService* prefs) {
[email protected]fecc1522009-10-15 21:08:29213 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this);
[email protected]fe23d5a32010-05-28 02:43:04214 accessibility_enabled_.Init(prefs::kAccessibilityEnabled, prefs, this);
[email protected]fecc1522009-10-15 21:08:29215 sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, this);
[email protected]530cd622011-04-14 15:45:00216 use_24hour_clock_.Init(prefs::kUse24HourClock, prefs, this);
[email protected]3b02de292010-05-13 06:05:05217 language_hotkey_next_engine_in_menu_.Init(
218 prefs::kLanguageHotkeyNextEngineInMenu, prefs, this);
219 language_hotkey_previous_engine_.Init(
220 prefs::kLanguageHotkeyPreviousEngine, prefs, this);
[email protected]74b42fc12010-07-20 10:15:41221 language_preferred_languages_.Init(prefs::kLanguagePreferredLanguages,
222 prefs, this);
[email protected]70aa5b32010-04-05 08:30:34223 language_preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, this);
[email protected]b65c5d22010-08-20 02:50:23224 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:43225 language_chewing_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23226 language_prefs::kChewingBooleanPrefs[i].pref_name, prefs, this);
[email protected]525dbe22010-06-01 07:05:43227 }
[email protected]b65c5d22010-08-20 02:50:23228 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:43229 language_chewing_multiple_choice_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23230 language_prefs::kChewingMultipleChoicePrefs[i].pref_name, prefs, this);
[email protected]525dbe22010-06-01 07:05:43231 }
[email protected]7ac5af92010-06-07 01:25:44232 language_chewing_hsu_sel_key_type_.Init(
[email protected]b65c5d22010-08-20 02:50:23233 language_prefs::kChewingHsuSelKeyType.pref_name, prefs, this);
234 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
[email protected]15c53082010-06-03 03:28:21235 language_chewing_integer_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23236 language_prefs::kChewingIntegerPrefs[i].pref_name, prefs, this);
[email protected]15c53082010-06-03 03:28:21237 }
[email protected]50951432010-03-31 12:12:42238 language_hangul_keyboard_.Init(prefs::kLanguageHangulKeyboard, prefs, this);
[email protected]33444cf2011-08-04 06:33:55239 language_hangul_hanja_binding_keys_.Init(
240 prefs::kLanguageHangulHanjaBindingKeys, prefs, this);
[email protected]b65c5d22010-08-20 02:50:23241 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
[email protected]9040ad22010-04-22 04:29:28242 language_pinyin_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23243 language_prefs::kPinyinBooleanPrefs[i].pref_name, prefs, this);
[email protected]9040ad22010-04-22 04:29:28244 }
[email protected]b65c5d22010-08-20 02:50:23245 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
[email protected]9040ad22010-04-22 04:29:28246 language_pinyin_int_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23247 language_prefs::kPinyinIntegerPrefs[i].pref_name, prefs, this);
[email protected]9040ad22010-04-22 04:29:28248 }
[email protected]7ac5af92010-06-07 01:25:44249 language_pinyin_double_pinyin_schema_.Init(
[email protected]b65c5d22010-08-20 02:50:23250 language_prefs::kPinyinDoublePinyinSchema.pref_name, prefs, this);
251 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
[email protected]8a1ace22010-06-10 05:38:25252 language_mozc_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23253 language_prefs::kMozcBooleanPrefs[i].pref_name, prefs, this);
[email protected]8a1ace22010-06-10 05:38:25254 }
[email protected]b65c5d22010-08-20 02:50:23255 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
[email protected]6e5c4b82010-05-24 08:18:44256 language_mozc_multiple_choice_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23257 language_prefs::kMozcMultipleChoicePrefs[i].pref_name, prefs, this);
[email protected]6e5c4b82010-05-24 08:18:44258 }
[email protected]b65c5d22010-08-20 02:50:23259 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
[email protected]54037462010-06-22 02:06:23260 language_mozc_integer_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23261 language_prefs::kMozcIntegerPrefs[i].pref_name, prefs, this);
[email protected]54037462010-06-22 02:06:23262 }
[email protected]b5194dd32010-08-12 10:40:04263 language_xkb_remap_search_key_to_.Init(
264 prefs::kLanguageXkbRemapSearchKeyTo, prefs, this);
265 language_xkb_remap_control_key_to_.Init(
266 prefs::kLanguageXkbRemapControlKeyTo, prefs, this);
267 language_xkb_remap_alt_key_to_.Init(
268 prefs::kLanguageXkbRemapAltKeyTo, prefs, this);
[email protected]a995b392010-08-11 04:38:59269 language_xkb_auto_repeat_enabled_.Init(
270 prefs::kLanguageXkbAutoRepeatEnabled, prefs, this);
271 language_xkb_auto_repeat_delay_pref_.Init(
[email protected]4743dad2010-08-30 01:41:07272 prefs::kLanguageXkbAutoRepeatDelay, prefs, this);
[email protected]a995b392010-08-11 04:38:59273 language_xkb_auto_repeat_interval_pref_.Init(
[email protected]4743dad2010-08-30 01:41:07274 prefs::kLanguageXkbAutoRepeatInterval, prefs, this);
[email protected]fecc1522009-10-15 21:08:29275
[email protected]4ccc05e2010-10-06 19:32:15276 enable_screen_lock_.Init(prefs::kEnableScreenLock, prefs, this);
277
[email protected]c0a2128d92011-07-20 15:04:46278 use_shared_proxies_.Init(prefs::kUseSharedProxies, prefs, this);
279
[email protected]d7ca1ba2011-05-09 20:09:08280 // Initialize preferences to currently saved state.
[email protected]fecc1522009-10-15 21:08:29281 NotifyPrefChanged(NULL);
[email protected]26012e22010-12-01 06:44:27282
[email protected]f410d612011-08-05 04:32:24283 // Initialize virtual keyboard settings to currently saved state.
284 UpdateVirturalKeyboardPreference(prefs);
285
[email protected]26012e22010-12-01 06:44:27286 // If a guest is logged in, initialize the prefs as if this is the first
287 // login.
288 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) {
289 LoginUtils::Get()->SetFirstLoginPrefs(prefs);
290 }
[email protected]fecc1522009-10-15 21:08:29291}
292
[email protected]432115822011-07-10 15:52:27293void Preferences::Observe(int type,
[email protected]50951432010-03-31 12:12:42294 const NotificationSource& source,
295 const NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27296 if (type == chrome::NOTIFICATION_PREF_CHANGED)
[email protected]57ecc4b2010-08-11 03:02:51297 NotifyPrefChanged(Details<std::string>(details).ptr());
[email protected]fecc1522009-10-15 21:08:29298}
299
[email protected]57ecc4b2010-08-11 03:02:51300void Preferences::NotifyPrefChanged(const std::string* pref_name) {
[email protected]3b02de292010-05-13 06:05:05301 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) {
[email protected]d7ca1ba2011-05-09 20:09:08302 bool enabled = tap_to_click_enabled_.GetValue();
[email protected]1cbfb3b2011-07-11 23:34:08303 system::touchpad_settings::SetTapToClick(enabled);
[email protected]d7ca1ba2011-05-09 20:09:08304 if (pref_name)
305 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled);
306 else
307 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Started", enabled);
[email protected]3b02de292010-05-13 06:05:05308 }
[email protected]3b02de292010-05-13 06:05:05309 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) {
[email protected]d7ca1ba2011-05-09 20:09:08310 int sensitivity = sensitivity_.GetValue();
[email protected]1cbfb3b2011-07-11 23:34:08311 system::touchpad_settings::SetSensitivity(sensitivity);
[email protected]d7ca1ba2011-05-09 20:09:08312 if (pref_name) {
313 UMA_HISTOGRAM_CUSTOM_COUNTS(
314 "Touchpad.Sensitivity.Changed", sensitivity, 1, 5, 5);
315 } else {
316 UMA_HISTOGRAM_CUSTOM_COUNTS(
317 "Touchpad.Sensitivity.Started", sensitivity, 1, 5, 5);
318 }
[email protected]3b02de292010-05-13 06:05:05319 }
[email protected]8be9ff22010-06-08 02:13:54320
321 // We don't handle prefs::kLanguageCurrentInputMethod and PreviousInputMethod
322 // here.
323
[email protected]3b02de292010-05-13 06:05:05324 if (!pref_name || *pref_name == prefs::kLanguageHotkeyNextEngineInMenu) {
[email protected]ddd231e2010-06-29 20:35:19325 SetLanguageConfigStringListAsCSV(
[email protected]b65c5d22010-08-20 02:50:23326 language_prefs::kHotKeySectionName,
327 language_prefs::kNextEngineInMenuConfigName,
[email protected]ddd231e2010-06-29 20:35:19328 language_hotkey_next_engine_in_menu_.GetValue());
[email protected]3b02de292010-05-13 06:05:05329 }
330 if (!pref_name || *pref_name == prefs::kLanguageHotkeyPreviousEngine) {
[email protected]ddd231e2010-06-29 20:35:19331 SetLanguageConfigStringListAsCSV(
[email protected]b65c5d22010-08-20 02:50:23332 language_prefs::kHotKeySectionName,
333 language_prefs::kPreviousEngineConfigName,
[email protected]ddd231e2010-06-29 20:35:19334 language_hotkey_previous_engine_.GetValue());
[email protected]3b02de292010-05-13 06:05:05335 }
[email protected]74b42fc12010-07-20 10:15:41336 if (!pref_name || *pref_name == prefs::kLanguagePreferredLanguages) {
337 // Unlike kLanguagePreloadEngines and some other input method
338 // preferencs, we don't need to send this to ibus-daemon.
339 }
[email protected]a6e90772011-02-09 05:38:54340
341 // Here, we set up the the modifier key mapping. This has to be done
342 // before changing the current keyboard layout, so that the modifier key
343 // preference is properly preserved. For this reason, we should do this
344 // before setting preload engines, that could change the current
345 // keyboard layout as needed.
346 if (!pref_name || (*pref_name == prefs::kLanguageXkbRemapSearchKeyTo ||
347 *pref_name == prefs::kLanguageXkbRemapControlKeyTo ||
348 *pref_name == prefs::kLanguageXkbRemapAltKeyTo)) {
349 UpdateModifierKeyMapping();
350 }
351 if (!pref_name || *pref_name == prefs::kLanguageXkbAutoRepeatEnabled) {
352 const bool enabled = language_xkb_auto_repeat_enabled_.GetValue();
[email protected]c010f632011-04-01 06:44:39353 input_method::SetAutoRepeatEnabled(enabled);
[email protected]a6e90772011-02-09 05:38:54354 }
355 if (!pref_name || ((*pref_name == prefs::kLanguageXkbAutoRepeatDelay) ||
356 (*pref_name == prefs::kLanguageXkbAutoRepeatInterval))) {
357 UpdateAutoRepeatRate();
358 }
359
[email protected]3b02de292010-05-13 06:05:05360 if (!pref_name || *pref_name == prefs::kLanguagePreloadEngines) {
[email protected]b65c5d22010-08-20 02:50:23361 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
362 language_prefs::kPreloadEnginesConfigName,
[email protected]d01bb8072010-04-12 13:00:15363 language_preload_engines_.GetValue());
[email protected]3b02de292010-05-13 06:05:05364 }
[email protected]b65c5d22010-08-20 02:50:23365 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
366 if (!pref_name ||
367 *pref_name == language_prefs::kChewingBooleanPrefs[i].pref_name) {
368 SetLanguageConfigBoolean(
369 language_prefs::kChewingSectionName,
370 language_prefs::kChewingBooleanPrefs[i].ibus_config_name,
371 language_chewing_boolean_prefs_[i].GetValue());
[email protected]525dbe22010-06-01 07:05:43372 }
373 }
[email protected]b65c5d22010-08-20 02:50:23374 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
375 if (!pref_name ||
376 *pref_name ==
377 language_prefs::kChewingMultipleChoicePrefs[i].pref_name) {
[email protected]525dbe22010-06-01 07:05:43378 SetLanguageConfigString(
[email protected]b65c5d22010-08-20 02:50:23379 language_prefs::kChewingSectionName,
380 language_prefs::kChewingMultipleChoicePrefs[i].ibus_config_name,
[email protected]525dbe22010-06-01 07:05:43381 language_chewing_multiple_choice_prefs_[i].GetValue());
382 }
383 }
[email protected]b65c5d22010-08-20 02:50:23384 if (!pref_name ||
385 *pref_name == language_prefs::kChewingHsuSelKeyType.pref_name) {
[email protected]7ac5af92010-06-07 01:25:44386 SetLanguageConfigInteger(
[email protected]b65c5d22010-08-20 02:50:23387 language_prefs::kChewingSectionName,
388 language_prefs::kChewingHsuSelKeyType.ibus_config_name,
[email protected]7ac5af92010-06-07 01:25:44389 language_chewing_hsu_sel_key_type_.GetValue());
390 }
[email protected]b65c5d22010-08-20 02:50:23391 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
392 if (!pref_name ||
393 *pref_name == language_prefs::kChewingIntegerPrefs[i].pref_name) {
394 SetLanguageConfigInteger(
395 language_prefs::kChewingSectionName,
396 language_prefs::kChewingIntegerPrefs[i].ibus_config_name,
397 language_chewing_integer_prefs_[i].GetValue());
[email protected]15c53082010-06-03 03:28:21398 }
399 }
[email protected]b65c5d22010-08-20 02:50:23400 if (!pref_name ||
401 *pref_name == prefs::kLanguageHangulKeyboard) {
402 SetLanguageConfigString(language_prefs::kHangulSectionName,
403 language_prefs::kHangulKeyboardConfigName,
[email protected]50951432010-03-31 12:12:42404 language_hangul_keyboard_.GetValue());
[email protected]3b02de292010-05-13 06:05:05405 }
[email protected]33444cf2011-08-04 06:33:55406 if (!pref_name || *pref_name == prefs::kLanguageHangulHanjaBindingKeys) {
407 SetLanguageConfigString(language_prefs::kHangulSectionName,
408 language_prefs::kHangulHanjaBindingKeysConfigName,
409 language_hangul_hanja_binding_keys_.GetValue());
410 }
[email protected]b65c5d22010-08-20 02:50:23411 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
412 if (!pref_name ||
413 *pref_name == language_prefs::kPinyinBooleanPrefs[i].pref_name) {
414 SetLanguageConfigBoolean(
415 language_prefs::kPinyinSectionName,
416 language_prefs::kPinyinBooleanPrefs[i].ibus_config_name,
417 language_pinyin_boolean_prefs_[i].GetValue());
[email protected]9040ad22010-04-22 04:29:28418 }
419 }
[email protected]b65c5d22010-08-20 02:50:23420 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
421 if (!pref_name ||
422 *pref_name == language_prefs::kPinyinIntegerPrefs[i].pref_name) {
423 SetLanguageConfigInteger(
424 language_prefs::kPinyinSectionName,
425 language_prefs::kPinyinIntegerPrefs[i].ibus_config_name,
426 language_pinyin_int_prefs_[i].GetValue());
[email protected]9040ad22010-04-22 04:29:28427 }
428 }
[email protected]b65c5d22010-08-20 02:50:23429 if (!pref_name ||
430 *pref_name == language_prefs::kPinyinDoublePinyinSchema.pref_name) {
[email protected]7ac5af92010-06-07 01:25:44431 SetLanguageConfigInteger(
[email protected]b65c5d22010-08-20 02:50:23432 language_prefs::kPinyinSectionName,
433 language_prefs::kPinyinDoublePinyinSchema.ibus_config_name,
[email protected]7ac5af92010-06-07 01:25:44434 language_pinyin_double_pinyin_schema_.GetValue());
435 }
[email protected]b65c5d22010-08-20 02:50:23436 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
437 if (!pref_name ||
438 *pref_name == language_prefs::kMozcBooleanPrefs[i].pref_name) {
439 SetLanguageConfigBoolean(
440 language_prefs::kMozcSectionName,
441 language_prefs::kMozcBooleanPrefs[i].ibus_config_name,
442 language_mozc_boolean_prefs_[i].GetValue());
[email protected]8a1ace22010-06-10 05:38:25443 }
444 }
[email protected]b65c5d22010-08-20 02:50:23445 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
446 if (!pref_name ||
447 *pref_name == language_prefs::kMozcMultipleChoicePrefs[i].pref_name) {
[email protected]6e5c4b82010-05-24 08:18:44448 SetLanguageConfigString(
[email protected]b65c5d22010-08-20 02:50:23449 language_prefs::kMozcSectionName,
450 language_prefs::kMozcMultipleChoicePrefs[i].ibus_config_name,
[email protected]6e5c4b82010-05-24 08:18:44451 language_mozc_multiple_choice_prefs_[i].GetValue());
452 }
453 }
[email protected]b65c5d22010-08-20 02:50:23454 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
455 if (!pref_name ||
456 *pref_name == language_prefs::kMozcIntegerPrefs[i].pref_name) {
457 SetLanguageConfigInteger(
458 language_prefs::kMozcSectionName,
459 language_prefs::kMozcIntegerPrefs[i].ibus_config_name,
460 language_mozc_integer_prefs_[i].GetValue());
[email protected]54037462010-06-22 02:06:23461 }
462 }
[email protected]4793c942010-09-21 23:17:17463
[email protected]4ccc05e2010-10-06 19:32:15464 // Init or update power manager config.
465 if (!pref_name || *pref_name == prefs::kEnableScreenLock) {
466 CrosLibrary::Get()->GetPowerLibrary()->EnableScreenLock(
467 enable_screen_lock_.GetValue());
468 }
[email protected]c0a2128d92011-07-20 15:04:46469
470 if (!pref_name || *pref_name == prefs::kUseSharedProxies) {
471 g_browser_process->chromeos_proxy_config_service_impl()->
472 UISetUseSharedProxies(use_shared_proxies_.GetValue());
473 }
[email protected]fecc1522009-10-15 21:08:29474}
475
[email protected]70aa5b32010-04-05 08:30:34476void Preferences::SetLanguageConfigBoolean(const char* section,
477 const char* name,
478 bool value) {
[email protected]dc7b0942011-06-15 06:45:53479 input_method::ImeConfigValue config;
480 config.type = input_method::ImeConfigValue::kValueTypeBool;
[email protected]70aa5b32010-04-05 08:30:34481 config.bool_value = value;
[email protected]c8d4e9462011-06-29 23:18:57482 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28483 SetImeConfig(section, name, config);
[email protected]70aa5b32010-04-05 08:30:34484}
485
[email protected]9040ad22010-04-22 04:29:28486void Preferences::SetLanguageConfigInteger(const char* section,
487 const char* name,
488 int value) {
[email protected]dc7b0942011-06-15 06:45:53489 input_method::ImeConfigValue config;
490 config.type = input_method::ImeConfigValue::kValueTypeInt;
[email protected]9040ad22010-04-22 04:29:28491 config.int_value = value;
[email protected]c8d4e9462011-06-29 23:18:57492 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28493 SetImeConfig(section, name, config);
[email protected]9040ad22010-04-22 04:29:28494}
495
[email protected]50951432010-03-31 12:12:42496void Preferences::SetLanguageConfigString(const char* section,
497 const char* name,
[email protected]ddd231e2010-06-29 20:35:19498 const std::string& value) {
[email protected]dc7b0942011-06-15 06:45:53499 input_method::ImeConfigValue config;
500 config.type = input_method::ImeConfigValue::kValueTypeString;
[email protected]ddd231e2010-06-29 20:35:19501 config.string_value = value;
[email protected]c8d4e9462011-06-29 23:18:57502 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28503 SetImeConfig(section, name, config);
[email protected]50951432010-03-31 12:12:42504}
505
[email protected]2c25ddfd2010-04-09 10:35:55506void Preferences::SetLanguageConfigStringList(
507 const char* section,
508 const char* name,
[email protected]ddd231e2010-06-29 20:35:19509 const std::vector<std::string>& values) {
[email protected]dc7b0942011-06-15 06:45:53510 input_method::ImeConfigValue config;
511 config.type = input_method::ImeConfigValue::kValueTypeStringList;
[email protected]ddd231e2010-06-29 20:35:19512 for (size_t i = 0; i < values.size(); ++i)
513 config.string_list_value.push_back(values[i]);
514
[email protected]c8d4e9462011-06-29 23:18:57515 input_method::InputMethodManager::GetInstance()->
[email protected]60b07682010-06-17 08:45:28516 SetImeConfig(section, name, config);
[email protected]2c25ddfd2010-04-09 10:35:55517}
518
[email protected]d01bb8072010-04-12 13:00:15519void Preferences::SetLanguageConfigStringListAsCSV(const char* section,
520 const char* name,
[email protected]ddd231e2010-06-29 20:35:19521 const std::string& value) {
[email protected]e24c2c92010-10-23 01:39:24522 VLOG(1) << "Setting " << name << " to '" << value << "'";
[email protected]d01bb8072010-04-12 13:00:15523
[email protected]ddd231e2010-06-29 20:35:19524 std::vector<std::string> split_values;
525 if (!value.empty())
[email protected]76eb0242010-10-14 00:35:36526 base::SplitString(value, ',', &split_values);
[email protected]ddd231e2010-06-29 20:35:19527
[email protected]2c25ddfd2010-04-09 10:35:55528 // We should call the cros API even when |value| is empty, to disable default
[email protected]d01bb8072010-04-12 13:00:15529 // config.
530 SetLanguageConfigStringList(section, name, split_values);
[email protected]70aa5b32010-04-05 08:30:34531}
532
[email protected]b5194dd32010-08-12 10:40:04533void Preferences::UpdateModifierKeyMapping() {
534 const int search_remap = language_xkb_remap_search_key_to_.GetValue();
535 const int control_remap = language_xkb_remap_control_key_to_.GetValue();
536 const int alt_remap = language_xkb_remap_alt_key_to_.GetValue();
[email protected]c010f632011-04-01 06:44:39537 if ((search_remap < input_method::kNumModifierKeys) && (search_remap >= 0) &&
538 (control_remap < input_method::kNumModifierKeys) &&
539 (control_remap >= 0) &&
540 (alt_remap < input_method::kNumModifierKeys) && (alt_remap >= 0)) {
541 input_method::ModifierMap modifier_map;
[email protected]b5194dd32010-08-12 10:40:04542 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39543 input_method::ModifierKeyPair(
544 input_method::kSearchKey,
545 input_method::ModifierKey(search_remap)));
[email protected]b5194dd32010-08-12 10:40:04546 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39547 input_method::ModifierKeyPair(
548 input_method::kLeftControlKey,
549 input_method::ModifierKey(control_remap)));
[email protected]b5194dd32010-08-12 10:40:04550 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39551 input_method::ModifierKeyPair(
552 input_method::kLeftAltKey,
553 input_method::ModifierKey(alt_remap)));
554 input_method::RemapModifierKeys(modifier_map);
[email protected]b5194dd32010-08-12 10:40:04555 } else {
556 LOG(ERROR) << "Failed to remap modifier keys. Unexpected value(s): "
557 << search_remap << ", " << control_remap << ", " << alt_remap;
558 }
559}
560
[email protected]a995b392010-08-11 04:38:59561void Preferences::UpdateAutoRepeatRate() {
[email protected]c010f632011-04-01 06:44:39562 input_method::AutoRepeatRate rate;
[email protected]a995b392010-08-11 04:38:59563 rate.initial_delay_in_ms = language_xkb_auto_repeat_delay_pref_.GetValue();
564 rate.repeat_interval_in_ms =
565 language_xkb_auto_repeat_interval_pref_.GetValue();
566 DCHECK(rate.initial_delay_in_ms > 0);
567 DCHECK(rate.repeat_interval_in_ms > 0);
[email protected]c010f632011-04-01 06:44:39568 input_method::SetAutoRepeatRate(rate);
[email protected]a995b392010-08-11 04:38:59569}
570
[email protected]f410d612011-08-05 04:32:24571void Preferences::UpdateVirturalKeyboardPreference(PrefService* prefs) {
572 const DictionaryValue* virtual_keyboard_pref =
573 prefs->GetDictionary(prefs::kLanguagePreferredVirtualKeyboard);
574 DCHECK(virtual_keyboard_pref);
575
576 input_method::InputMethodManager* input_method_manager =
577 input_method::InputMethodManager::GetInstance();
578 input_method_manager->ClearAllVirtualKeyboardPreferences();
579
580 std::string url;
[email protected]b3362572011-08-17 09:28:50581 std::vector<std::string> layouts_to_remove;
[email protected]f410d612011-08-05 04:32:24582 for (DictionaryValue::key_iterator iter = virtual_keyboard_pref->begin_keys();
583 iter != virtual_keyboard_pref->end_keys();
584 ++iter) {
[email protected]b3362572011-08-17 09:28:50585 const std::string& layout_id = *iter; // e.g. "us", "handwriting-vk"
586 if (!virtual_keyboard_pref->GetString(layout_id, &url))
[email protected]f410d612011-08-05 04:32:24587 continue;
[email protected]b3362572011-08-17 09:28:50588 if (!input_method_manager->SetVirtualKeyboardPreference(
589 layout_id, GURL(url))) {
590 // Either |layout_id| or |url| is invalid. Remove the key from |prefs|
591 // later.
592 layouts_to_remove.push_back(layout_id);
[email protected]148994e2011-08-17 10:01:48593 LOG(ERROR) << "Removing invalid virtual keyboard pref: layout="
594 << layout_id;
[email protected]b3362572011-08-17 09:28:50595 }
596 }
597
598 // Remove invalid prefs.
599 DictionaryPrefUpdate updater(prefs, prefs::kLanguagePreferredVirtualKeyboard);
600 DictionaryValue* pref_value = updater.Get();
601 for (size_t i = 0; i < layouts_to_remove.size(); ++i) {
602 pref_value->RemoveWithoutPathExpansion(layouts_to_remove[i], NULL);
[email protected]f410d612011-08-05 04:32:24603 }
604}
605
[email protected]fecc1522009-10-15 21:08:29606} // namespace chromeos