Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/preferences.h" | 5 #include "chrome/browser/chromeos/preferences.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/autoclick/autoclick_controller.h" | 9 #include "ash/autoclick/autoclick_controller.h" |
| 10 #include "ash/magnifier/magnifier_constants.h" | 10 #include "ash/magnifier/magnifier_constants.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/i18n/time_formatting.h" | 13 #include "base/i18n/time_formatting.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/prefs/pref_member.h" | 15 #include "base/prefs/pref_member.h" |
| 16 #include "base/prefs/pref_registry_simple.h" | 16 #include "base/prefs/pref_registry_simple.h" |
| 17 #include "base/prefs/scoped_user_pref_update.h" | 17 #include "base/prefs/scoped_user_pref_update.h" |
| 18 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
| 22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/chrome_notification_types.h" | 23 #include "chrome/browser/chrome_notification_types.h" |
| 24 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | 24 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
| 25 #include "chrome/browser/chromeos/drive/file_system_util.h" | 25 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 26 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 26 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 27 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 27 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| 28 #include "chrome/browser/chromeos/login/users/user.h" | 28 #include "chrome/browser/chromeos/login/users/user.h" |
| 29 #include "chrome/browser/chromeos/system/input_device_settings.h" | 29 #include "chrome/browser/chromeos/system/input_device_settings.h" |
| 30 #include "chrome/browser/download/download_prefs.h" | 30 #include "chrome/browser/download/download_prefs.h" |
| 31 #include "chrome/browser/prefs/pref_service_syncable.h" | 31 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 34 #include "chromeos/chromeos_switches.h" | 34 #include "chromeos/chromeos_switches.h" |
| 35 #include "chromeos/ime/component_extension_ime_manager.h" | |
| 35 #include "chromeos/ime/extension_ime_util.h" | 36 #include "chromeos/ime/extension_ime_util.h" |
| 36 #include "chromeos/ime/ime_keyboard.h" | 37 #include "chromeos/ime/ime_keyboard.h" |
| 37 #include "chromeos/ime/input_method_manager.h" | 38 #include "chromeos/ime/input_method_manager.h" |
| 38 #include "chromeos/system/statistics_provider.h" | 39 #include "chromeos/system/statistics_provider.h" |
| 39 #include "components/feedback/tracing_manager.h" | 40 #include "components/feedback/tracing_manager.h" |
| 40 #include "components/pref_registry/pref_registry_syncable.h" | 41 #include "components/pref_registry/pref_registry_syncable.h" |
| 42 #include "content/public/browser/browser_thread.h" | |
| 41 #include "third_party/icu/source/i18n/unicode/timezone.h" | 43 #include "third_party/icu/source/i18n/unicode/timezone.h" |
| 44 #include "ui/base/l10n/l10n_util.h" | |
| 42 #include "ui/events/event_constants.h" | 45 #include "ui/events/event_constants.h" |
| 43 #include "ui/events/event_utils.h" | 46 #include "ui/events/event_utils.h" |
| 44 #include "url/gurl.h" | 47 #include "url/gurl.h" |
| 45 | 48 |
| 46 namespace chromeos { | 49 namespace chromeos { |
| 50 namespace { | |
| 47 | 51 |
| 48 static const char kFallbackInputMethodLocale[] = "en-US"; | 52 static const char kFallbackInputMethodLocale[] = "en-US"; |
| 49 | 53 |
| 54 // Checks input method IDs, converting engine IDs to input method IDs and | |
| 55 // removing unsupported IDs from |values|. | |
| 56 void CheckAndResolveInputMethodIDs( | |
| 57 std::vector<std::string>* values, | |
| 58 const input_method::InputMethodDescriptors& supported_descriptors) { | |
| 59 // Extract the supported input method IDs into a set. | |
| 60 std::set<std::string> supported_input_method_ids; | |
| 61 for (size_t i = 0; i < supported_descriptors.size(); i++) | |
| 62 supported_input_method_ids.insert(supported_descriptors[i].id()); | |
| 63 | |
| 64 // Convert engine IDs to input method extension IDs. | |
| 65 std::transform(values->begin(), values->end(), values->begin(), | |
| 66 extension_ime_util::GetInputMethodIDByEngineID); | |
| 67 | |
| 68 // Remove values that aren't found in the set of supported input method IDs. | |
| 69 std::vector<std::string>::iterator it = values->begin(); | |
| 70 while (it != values->end()) { | |
| 71 if (it->size() && std::find(supported_input_method_ids.begin(), | |
| 72 supported_input_method_ids.end(), | |
| 73 *it) != supported_input_method_ids.end()) { | |
| 74 ++it; | |
| 75 } else { | |
| 76 it = values->erase(it); | |
| 77 } | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 // Checks whether each language is supported, replacing locales with variants | |
| 82 // if they are available. Must be called on a thread that allows IO. | |
| 83 void CheckAndResolveLocales(std::string* languages) { | |
| 84 if (languages->empty()) | |
| 85 return; | |
| 86 std::vector<std::string> values; | |
| 87 base::SplitString(*languages, ',', &values); | |
| 88 | |
| 89 // Remove unsupported language values and set the resolved locales. | |
| 90 std::vector<std::string>::iterator value_iter = values.begin(); | |
| 91 while (value_iter != values.end()) { | |
| 92 std::string resolved_locale; | |
| 93 if (l10n_util::CheckAndResolveLocale(*value_iter, &resolved_locale)) { | |
| 94 *value_iter = resolved_locale; | |
| 95 ++value_iter; | |
| 96 } else { | |
| 97 value_iter = values.erase(value_iter); | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 *languages = JoinString(values, ','); | |
| 102 } | |
| 103 | |
| 104 // Appends tokens from |src| that are not in |dest| to |dest|. Quadratic | |
| 105 // runtime; use only for small lists. | |
| 106 void MergeLists(std::vector<std::string>* dest, | |
| 107 const std::vector<std::string>& src) { | |
| 108 for (size_t i = 0; i < src.size(); i++) { | |
| 109 // Skip token if it's already in |dest|. | |
| 110 if (std::find(dest->begin(), dest->end(), src[i]) == dest->end()) | |
| 111 dest->push_back(src[i]); | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 // For the given input method pref, adds unique values from |synced_pref| to | |
| 116 // values in |pref|. The new values are converted from legacy engine IDs to | |
| 117 // input method IDs if necessary. | |
| 118 std::string AddSupportedInputMethodValues(const std::string& pref, | |
| 119 const std::string& synced_pref, | |
| 120 const char* pref_name) { | |
| 121 std::vector<std::string> old_tokens; | |
| 122 std::vector<std::string> new_tokens; | |
| 123 base::SplitString(pref, ',', &old_tokens); | |
| 124 base::SplitString(synced_pref, ',', &new_tokens); | |
| 125 | |
| 126 // Check and convert the new tokens. | |
| 127 if (pref_name == prefs::kLanguagePreloadEngines || | |
| 128 pref_name == prefs::kLanguageEnabledExtensionImes) { | |
| 129 input_method::InputMethodManager* manager = | |
| 130 input_method::InputMethodManager::Get(); | |
| 131 scoped_ptr<input_method::InputMethodDescriptors> supported_descriptors; | |
| 132 | |
| 133 if (pref_name == prefs::kLanguagePreloadEngines) { | |
| 134 // Set the known input methods. | |
| 135 supported_descriptors = manager->GetSupportedInputMethods(); | |
| 136 // Add the available component extension IMEs. | |
| 137 ComponentExtensionIMEManager* component_extension_manager = | |
| 138 manager->GetComponentExtensionIMEManager(); | |
| 139 if (component_extension_manager->IsInitialized()) { | |
| 140 input_method::InputMethodDescriptors component_descriptors = | |
| 141 component_extension_manager->GetAllIMEAsInputMethodDescriptor(); | |
| 142 supported_descriptors->insert(supported_descriptors->end(), | |
| 143 component_descriptors.begin(), | |
| 144 component_descriptors.end()); | |
| 145 } | |
| 146 } else { | |
| 147 supported_descriptors.reset(new input_method::InputMethodDescriptors); | |
| 148 manager->GetInputMethodExtensions(supported_descriptors.get()); | |
| 149 } | |
| 150 CheckAndResolveInputMethodIDs(&new_tokens, *supported_descriptors); | |
| 151 } else if (pref_name != prefs::kLanguagePreferredLanguages) { | |
| 152 NOTREACHED() << "Attempting to merge an invalid preference."; | |
| 153 } | |
| 154 | |
| 155 // Do the actual merging. | |
| 156 MergeLists(&old_tokens, new_tokens); | |
| 157 return JoinString(old_tokens, ','); | |
| 158 } | |
| 159 | |
| 160 } // anonymous namespace | |
| 161 | |
| 50 Preferences::Preferences() | 162 Preferences::Preferences() |
| 51 : prefs_(NULL), | 163 : prefs_(NULL), |
| 52 input_method_manager_(input_method::InputMethodManager::Get()), | 164 input_method_manager_(input_method::InputMethodManager::Get()), |
| 53 user_(NULL), | 165 user_(NULL), |
| 54 user_is_primary_(false) { | 166 user_is_primary_(false), |
| 167 weak_factory_(this) { | |
| 55 // Do not observe shell, if there is no shell instance; e.g., in some unit | 168 // Do not observe shell, if there is no shell instance; e.g., in some unit |
| 56 // tests. | 169 // tests. |
| 57 if (ash::Shell::HasInstance()) | 170 if (ash::Shell::HasInstance()) |
| 58 ash::Shell::GetInstance()->AddShellObserver(this); | 171 ash::Shell::GetInstance()->AddShellObserver(this); |
| 59 } | 172 } |
| 60 | 173 |
| 61 Preferences::Preferences(input_method::InputMethodManager* input_method_manager) | 174 Preferences::Preferences(input_method::InputMethodManager* input_method_manager) |
| 62 : prefs_(NULL), | 175 : prefs_(NULL), |
| 63 input_method_manager_(input_method_manager), | 176 input_method_manager_(input_method_manager), |
| 64 user_(NULL), | 177 user_(NULL), |
| 65 user_is_primary_(false) { | 178 user_is_primary_(false), |
| 179 weak_factory_(this) { | |
| 66 // Do not observe shell, if there is no shell instance; e.g., in some unit | 180 // Do not observe shell, if there is no shell instance; e.g., in some unit |
| 67 // tests. | 181 // tests. |
| 68 if (ash::Shell::HasInstance()) | 182 if (ash::Shell::HasInstance()) |
| 69 ash::Shell::GetInstance()->AddShellObserver(this); | 183 ash::Shell::GetInstance()->AddShellObserver(this); |
| 70 } | 184 } |
| 71 | 185 |
| 72 Preferences::~Preferences() { | 186 Preferences::~Preferences() { |
| 73 prefs_->RemoveObserver(this); | 187 prefs_->RemoveObserver(this); |
| 74 UserManager::Get()->RemoveSessionStateObserver(this); | 188 UserManager::Get()->RemoveSessionStateObserver(this); |
| 75 // If shell instance is destoryed before this preferences instance, there is | 189 // If shell instance is destoryed before this preferences instance, there is |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod | 321 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod |
| 208 // because they're just used to track the logout state of the device. | 322 // because they're just used to track the logout state of the device. |
| 209 registry->RegisterStringPref( | 323 registry->RegisterStringPref( |
| 210 prefs::kLanguageCurrentInputMethod, | 324 prefs::kLanguageCurrentInputMethod, |
| 211 "", | 325 "", |
| 212 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 326 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 213 registry->RegisterStringPref( | 327 registry->RegisterStringPref( |
| 214 prefs::kLanguagePreviousInputMethod, | 328 prefs::kLanguagePreviousInputMethod, |
| 215 "", | 329 "", |
| 216 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 330 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 217 // We don't sync the list of input methods and preferred languages since a | |
| 218 // user might use two or more devices with different hardware keyboards. | |
| 219 // crosbug.com/15181 | |
| 220 registry->RegisterStringPref( | 331 registry->RegisterStringPref( |
| 221 prefs::kLanguagePreferredLanguages, | 332 prefs::kLanguagePreferredLanguages, |
| 222 kFallbackInputMethodLocale, | 333 kFallbackInputMethodLocale, |
| 223 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 334 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 224 registry->RegisterStringPref( | 335 registry->RegisterStringPref( |
| 336 prefs::kLanguagePreferredLanguagesSyncable, | |
| 337 "", | |
| 338 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | |
| 339 registry->RegisterStringPref( | |
| 225 prefs::kLanguagePreloadEngines, | 340 prefs::kLanguagePreloadEngines, |
| 226 hardware_keyboard_id, | 341 hardware_keyboard_id, |
| 227 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 342 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 228 registry->RegisterStringPref( | 343 registry->RegisterStringPref( |
| 344 prefs::kLanguagePreloadEnginesSyncable, | |
| 345 "", | |
| 346 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | |
| 347 registry->RegisterStringPref( | |
| 229 prefs::kLanguageEnabledExtensionImes, | 348 prefs::kLanguageEnabledExtensionImes, |
| 230 "", | 349 "", |
| 231 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 350 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 351 registry->RegisterStringPref( | |
| 352 prefs::kLanguageEnabledExtensionImesSyncable, | |
| 353 "", | |
| 354 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | |
| 355 registry->RegisterBooleanPref( | |
| 356 prefs::kLanguageShouldMergeInputMethods, | |
| 357 false, | |
| 358 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 232 | 359 |
| 233 registry->RegisterIntegerPref( | 360 registry->RegisterIntegerPref( |
| 234 prefs::kLanguageRemapSearchKeyTo, | 361 prefs::kLanguageRemapSearchKeyTo, |
| 235 input_method::kSearchKey, | 362 input_method::kSearchKey, |
| 236 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); | 363 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); |
| 237 registry->RegisterIntegerPref( | 364 registry->RegisterIntegerPref( |
| 238 prefs::kLanguageRemapControlKeyTo, | 365 prefs::kLanguageRemapControlKeyTo, |
| 239 input_method::kControlKey, | 366 input_method::kControlKey, |
| 240 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); | 367 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); |
| 241 registry->RegisterIntegerPref( | 368 registry->RegisterIntegerPref( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 prefs, callback); | 455 prefs, callback); |
| 329 natural_scroll_.Init(prefs::kNaturalScroll, prefs, callback); | 456 natural_scroll_.Init(prefs::kNaturalScroll, prefs, callback); |
| 330 mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, callback); | 457 mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, callback); |
| 331 touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, callback); | 458 touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, callback); |
| 332 primary_mouse_button_right_.Init(prefs::kPrimaryMouseButtonRight, | 459 primary_mouse_button_right_.Init(prefs::kPrimaryMouseButtonRight, |
| 333 prefs, callback); | 460 prefs, callback); |
| 334 download_default_directory_.Init(prefs::kDownloadDefaultDirectory, | 461 download_default_directory_.Init(prefs::kDownloadDefaultDirectory, |
| 335 prefs, callback); | 462 prefs, callback); |
| 336 touch_hud_projection_enabled_.Init(prefs::kTouchHudProjectionEnabled, | 463 touch_hud_projection_enabled_.Init(prefs::kTouchHudProjectionEnabled, |
| 337 prefs, callback); | 464 prefs, callback); |
| 465 preferred_languages_.Init(prefs::kLanguagePreferredLanguages, | |
| 466 prefs, callback); | |
| 338 preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, callback); | 467 preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, callback); |
| 339 enabled_extension_imes_.Init(prefs::kLanguageEnabledExtensionImes, | 468 enabled_extension_imes_.Init(prefs::kLanguageEnabledExtensionImes, |
| 340 prefs, callback); | 469 prefs, callback); |
| 470 preferred_languages_syncable_.Init(prefs::kLanguagePreferredLanguagesSyncable, | |
| 471 prefs, callback); | |
| 472 preload_engines_syncable_.Init(prefs::kLanguagePreloadEnginesSyncable, | |
| 473 prefs, callback); | |
| 474 enabled_extension_imes_syncable_.Init( | |
| 475 prefs::kLanguageEnabledExtensionImesSyncable, prefs, callback); | |
| 341 current_input_method_.Init(prefs::kLanguageCurrentInputMethod, | 476 current_input_method_.Init(prefs::kLanguageCurrentInputMethod, |
| 342 prefs, callback); | 477 prefs, callback); |
| 343 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod, | 478 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod, |
| 344 prefs, callback); | 479 prefs, callback); |
| 345 | 480 |
| 346 xkb_auto_repeat_enabled_.Init( | 481 xkb_auto_repeat_enabled_.Init( |
| 347 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback); | 482 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback); |
| 348 xkb_auto_repeat_delay_pref_.Init( | 483 xkb_auto_repeat_delay_pref_.Init( |
| 349 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback); | 484 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback); |
| 350 xkb_auto_repeat_interval_pref_.Init( | 485 xkb_auto_repeat_interval_pref_.Init( |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 default_download_to_drive); | 645 default_download_to_drive); |
| 511 else if (reason == REASON_INITIALIZATION) | 646 else if (reason == REASON_INITIALIZATION) |
| 512 UMA_HISTOGRAM_BOOLEAN( | 647 UMA_HISTOGRAM_BOOLEAN( |
| 513 "FileBrowser.DownloadDestination.IsGoogleDrive.Started", | 648 "FileBrowser.DownloadDestination.IsGoogleDrive.Started", |
| 514 default_download_to_drive); | 649 default_download_to_drive); |
| 515 } | 650 } |
| 516 if (reason != REASON_PREF_CHANGED || | 651 if (reason != REASON_PREF_CHANGED || |
| 517 pref_name == prefs::kTouchHudProjectionEnabled) { | 652 pref_name == prefs::kTouchHudProjectionEnabled) { |
| 518 if (user_is_active) { | 653 if (user_is_active) { |
| 519 const bool enabled = touch_hud_projection_enabled_.GetValue(); | 654 const bool enabled = touch_hud_projection_enabled_.GetValue(); |
| 520 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled); | 655 // There may not be a shell, e.g., in some unit tests. |
| 656 if (ash::Shell::HasInstance()) | |
| 657 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled); | |
| 521 } | 658 } |
| 522 } | 659 } |
| 523 | 660 |
| 524 if (reason != REASON_PREF_CHANGED || | 661 if (reason != REASON_PREF_CHANGED || |
| 525 pref_name == prefs::kLanguageXkbAutoRepeatEnabled) { | 662 pref_name == prefs::kLanguageXkbAutoRepeatEnabled) { |
| 526 if (user_is_active) { | 663 if (user_is_active) { |
| 527 const bool enabled = xkb_auto_repeat_enabled_.GetValue(); | 664 const bool enabled = xkb_auto_repeat_enabled_.GetValue(); |
| 528 input_method::InputMethodManager::Get() | 665 input_method::InputMethodManager::Get() |
| 529 ->GetImeKeyboard() | 666 ->GetImeKeyboard() |
| 530 ->SetAutoRepeatEnabled(enabled); | 667 ->SetAutoRepeatEnabled(enabled); |
| 531 } | 668 } |
| 532 } | 669 } |
| 533 if (reason != REASON_PREF_CHANGED || | 670 if (reason != REASON_PREF_CHANGED || |
| 534 pref_name == prefs::kLanguageXkbAutoRepeatDelay || | 671 pref_name == prefs::kLanguageXkbAutoRepeatDelay || |
| 535 pref_name == prefs::kLanguageXkbAutoRepeatInterval) { | 672 pref_name == prefs::kLanguageXkbAutoRepeatInterval) { |
| 536 if (user_is_active) | 673 if (user_is_active) |
| 537 UpdateAutoRepeatRate(); | 674 UpdateAutoRepeatRate(); |
| 538 } | 675 } |
| 539 | 676 |
| 677 if (reason == REASON_PREF_CHANGED && | |
| 678 pref_name == prefs::kLanguagePreferredLanguages) | |
| 679 SetSyncableInputMethodPrefs(); | |
| 680 | |
| 540 if (reason != REASON_PREF_CHANGED && user_is_active) { | 681 if (reason != REASON_PREF_CHANGED && user_is_active) { |
| 541 SetInputMethodList(); | 682 SetInputMethodList(); |
| 542 } else if (pref_name == prefs::kLanguagePreloadEngines && user_is_active) { | 683 } else if (pref_name == prefs::kLanguagePreloadEngines) { |
| 543 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, | 684 if (user_is_active) { |
| 544 language_prefs::kPreloadEnginesConfigName, | 685 SetLanguageConfigStringListAsCSV( |
| 545 preload_engines_.GetValue()); | 686 language_prefs::kGeneralSectionName, |
| 687 language_prefs::kPreloadEnginesConfigName, | |
| 688 preload_engines_.GetValue()); | |
| 689 } | |
| 690 SetSyncableInputMethodPrefs(); | |
| 546 } | 691 } |
| 547 | 692 |
| 548 if (reason != REASON_PREF_CHANGED || | 693 if (reason != REASON_PREF_CHANGED || |
| 549 pref_name == prefs::kLanguageEnabledExtensionImes) { | 694 pref_name == prefs::kLanguageEnabledExtensionImes) { |
| 550 if (user_is_active) { | 695 if (user_is_active) |
| 551 std::string value(enabled_extension_imes_.GetValue()); | 696 SetEnabledExtensionImes(); |
| 552 | 697 if (reason == REASON_PREF_CHANGED) |
| 553 std::vector<std::string> split_values; | 698 SetSyncableInputMethodPrefs(); |
| 554 if (!value.empty()) | |
| 555 base::SplitString(value, ',', &split_values); | |
| 556 | |
| 557 input_method_manager_->SetEnabledExtensionImes(&split_values); | |
| 558 } | |
| 559 } | 699 } |
| 560 | 700 |
| 561 if (user_is_active) { | 701 if (user_is_active) { |
| 562 system::InputDeviceSettings::Get()->UpdateTouchpadSettings( | 702 system::InputDeviceSettings::Get()->UpdateTouchpadSettings( |
| 563 touchpad_settings); | 703 touchpad_settings); |
| 564 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings); | 704 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings); |
| 565 } | 705 } |
| 566 } | 706 } |
| 567 | 707 |
| 568 void Preferences::OnIsSyncingChanged() { | 708 void Preferences::OnIsSyncingChanged() { |
| 569 DVLOG(1) << "OnIsSyncingChanged"; | 709 DVLOG(1) << "OnIsSyncingChanged"; |
| 570 ForceNaturalScrollDefault(); | 710 ForceNaturalScrollDefault(); |
| 711 if (prefs_->GetBoolean(prefs::kLanguageShouldMergeInputMethods) && | |
| 712 prefs_->IsSyncing()) { | |
| 713 MergeSyncedInputMethods(); | |
| 714 } | |
| 571 } | 715 } |
| 572 | 716 |
| 573 void Preferences::ForceNaturalScrollDefault() { | 717 void Preferences::ForceNaturalScrollDefault() { |
| 574 DVLOG(1) << "ForceNaturalScrollDefault"; | 718 DVLOG(1) << "ForceNaturalScrollDefault"; |
| 575 if (CommandLine::ForCurrentProcess()->HasSwitch( | 719 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 576 switches::kNaturalScrollDefault) && | 720 switches::kNaturalScrollDefault) && |
| 577 prefs_->IsSyncing() && | 721 prefs_->IsSyncing() && |
| 578 !prefs_->GetUserPrefValue(prefs::kNaturalScroll)) { | 722 !prefs_->GetUserPrefValue(prefs::kNaturalScroll)) { |
| 579 DVLOG(1) << "Natural scroll forced to true"; | 723 DVLOG(1) << "Natural scroll forced to true"; |
| 580 natural_scroll_.SetValue(true); | 724 natural_scroll_.SetValue(true); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 595 if (input_method_manager_->MigrateInputMethods(&split_values)) | 739 if (input_method_manager_->MigrateInputMethods(&split_values)) |
| 596 preload_engines_.SetValue(JoinString(split_values, ',')); | 740 preload_engines_.SetValue(JoinString(split_values, ',')); |
| 597 | 741 |
| 598 if (section == std::string(language_prefs::kGeneralSectionName) && | 742 if (section == std::string(language_prefs::kGeneralSectionName) && |
| 599 name == std::string(language_prefs::kPreloadEnginesConfigName)) { | 743 name == std::string(language_prefs::kPreloadEnginesConfigName)) { |
| 600 input_method_manager_->ReplaceEnabledInputMethods(split_values); | 744 input_method_manager_->ReplaceEnabledInputMethods(split_values); |
| 601 return; | 745 return; |
| 602 } | 746 } |
| 603 } | 747 } |
| 604 | 748 |
| 749 void Preferences::SetPreferredLanguages(scoped_ptr<std::string> languages) { | |
| 750 // Since this only removes locales that are unsupported on this system, we | |
| 751 // don't need to update the syncable prefs. If the local preference changes | |
| 752 // later, the sync server will lose the values we dropped, but that's okay | |
| 753 // since the values from this device would become the new defaults anyway. | |
| 754 if (*languages != preferred_languages_.GetValue()) | |
| 755 preferred_languages_.SetValue(*languages); | |
| 756 } | |
| 757 | |
| 605 void Preferences::SetInputMethodList() { | 758 void Preferences::SetInputMethodList() { |
| 606 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod() | 759 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod() |
| 607 // might be called to change the current input method to the first one in the | 760 // might be called to change the current input method to the first one in the |
| 608 // |preload_engines_| list. This also updates previous/current input method | 761 // |preload_engines_| list. This also updates previous/current input method |
| 609 // prefs. That's why GetValue() calls are placed before the | 762 // prefs. That's why GetValue() calls are placed before the |
| 610 // SetLanguageConfigStringListAsCSV() call below. | 763 // SetLanguageConfigStringListAsCSV() call below. |
| 611 const std::string previous_input_method_id = | 764 const std::string previous_input_method_id = |
| 612 previous_input_method_.GetValue(); | 765 previous_input_method_.GetValue(); |
| 613 const std::string current_input_method_id = current_input_method_.GetValue(); | 766 const std::string current_input_method_id = current_input_method_.GetValue(); |
| 614 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, | 767 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, |
| 615 language_prefs::kPreloadEnginesConfigName, | 768 language_prefs::kPreloadEnginesConfigName, |
| 616 preload_engines_.GetValue()); | 769 preload_engines_.GetValue()); |
| 617 | 770 |
| 618 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_| | 771 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_| |
| 619 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request | 772 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request |
| 620 // might be ignored as an invalid input method ID. The ChangeInputMethod() | 773 // might be ignored as an invalid input method ID. The ChangeInputMethod() |
| 621 // calls are also necessary to restore the previous/current input method prefs | 774 // calls are also necessary to restore the previous/current input method prefs |
| 622 // which could have been modified by the SetLanguageConfigStringListAsCSV call | 775 // which could have been modified by the SetLanguageConfigStringListAsCSV call |
| 623 // above to the original state. | 776 // above to the original state. |
| 624 if (!previous_input_method_id.empty()) | 777 if (!previous_input_method_id.empty()) |
| 625 input_method_manager_->ChangeInputMethod(previous_input_method_id); | 778 input_method_manager_->ChangeInputMethod(previous_input_method_id); |
| 626 if (!current_input_method_id.empty()) | 779 if (!current_input_method_id.empty()) |
| 627 input_method_manager_->ChangeInputMethod(current_input_method_id); | 780 input_method_manager_->ChangeInputMethod(current_input_method_id); |
| 628 } | 781 } |
| 629 | 782 |
| 783 void Preferences::SetEnabledExtensionImes() { | |
| 784 std::string value(enabled_extension_imes_.GetValue()); | |
| 785 std::vector<std::string> split_values; | |
| 786 if (!value.empty()) | |
| 787 base::SplitString(value, ',', &split_values); | |
| 788 input_method_manager_->SetEnabledExtensionImes(&split_values); | |
| 789 } | |
| 790 | |
| 791 void Preferences::SetSyncableInputMethodPrefs() { | |
| 792 // Set the language and input prefs at the same time. Otherwise, we may, | |
| 793 // e.g., use a stale languages setting but push a new preload engines setting. | |
| 794 preferred_languages_syncable_.SetValue(preferred_languages_.GetValue()); | |
| 795 enabled_extension_imes_syncable_.SetValue( | |
| 796 enabled_extension_imes_.GetValue()); | |
| 797 | |
| 798 // For preload engines, use legacy xkb IDs so the preference can sync | |
| 799 // across Chrome OS and Chromium OS. | |
| 800 std::vector<std::string> engines; | |
| 801 base::SplitString(preload_engines_.GetValue(), ',', &engines); | |
| 802 std::transform(engines.begin(), engines.end(), engines.begin(), | |
| 803 extension_ime_util::GetEngineIDByInputMethodID); | |
| 804 preload_engines_syncable_.SetValue(JoinString(engines, ',')); | |
| 805 } | |
| 806 | |
| 807 void Preferences::MergeSyncedInputMethods() { | |
| 808 // This should only be done on the first ever sync. | |
| 809 DCHECK(prefs_->GetBoolean(prefs::kLanguageShouldMergeInputMethods)); | |
| 810 prefs_->SetBoolean(prefs::kLanguageShouldMergeInputMethods, false); | |
| 811 | |
| 812 // Merge the values from the sync server into the local values. | |
| 813 preferred_languages_.SetValue( | |
|
dzhioev (left Google)
2014/07/24 20:31:34
I can't understand why do you set preferred langua
michaelpg
2014/07/25 23:49:08
The check is asynchronous. So this way, the change
dzhioev (left Google)
2014/08/01 15:30:41
I understand part about checking. But still I don'
| |
| 814 AddSupportedInputMethodValues(preferred_languages_.GetValue(), | |
| 815 preferred_languages_syncable_.GetValue(), | |
| 816 prefs::kLanguagePreferredLanguages)); | |
| 817 preload_engines_.SetValue( | |
| 818 AddSupportedInputMethodValues(preload_engines_.GetValue(), | |
| 819 preload_engines_syncable_.GetValue(), | |
| 820 prefs::kLanguagePreloadEngines)); | |
| 821 enabled_extension_imes_.SetValue( | |
|
dzhioev (left Google)
2014/07/24 20:31:34
I think the better idea is to set prefs directly t
michaelpg
2014/07/25 23:49:08
Does this look better?
When any of these prefs ar
dzhioev (left Google)
2014/08/01 15:30:41
Yes, it's better.
| |
| 822 AddSupportedInputMethodValues(enabled_extension_imes_.GetValue(), | |
| 823 enabled_extension_imes_syncable_.GetValue(), | |
| 824 prefs::kLanguageEnabledExtensionImes)); | |
| 825 | |
| 826 // Apply the new values. | |
| 827 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, | |
| 828 language_prefs::kPreloadEnginesConfigName, | |
| 829 preload_engines_.GetValue()); | |
| 830 SetEnabledExtensionImes(); | |
| 831 SetSyncableInputMethodPrefs(); | |
| 832 | |
| 833 // Check the new list of preferred languages to remove unsupported locales. | |
| 834 scoped_ptr<std::string> languages( | |
| 835 new std::string(preferred_languages_.GetValue())); | |
| 836 content::BrowserThread::PostTaskAndReply( | |
| 837 content::BrowserThread::FILE, | |
| 838 FROM_HERE, | |
| 839 base::Bind(&CheckAndResolveLocales, languages.get()), | |
| 840 base::Bind(&Preferences::SetPreferredLanguages, | |
| 841 weak_factory_.GetWeakPtr(), | |
| 842 base::Passed(&languages))); | |
| 843 } | |
| 844 | |
| 630 void Preferences::UpdateAutoRepeatRate() { | 845 void Preferences::UpdateAutoRepeatRate() { |
| 631 input_method::AutoRepeatRate rate; | 846 input_method::AutoRepeatRate rate; |
| 632 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue(); | 847 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue(); |
| 633 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue(); | 848 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue(); |
| 634 DCHECK(rate.initial_delay_in_ms > 0); | 849 DCHECK(rate.initial_delay_in_ms > 0); |
| 635 DCHECK(rate.repeat_interval_in_ms > 0); | 850 DCHECK(rate.repeat_interval_in_ms > 0); |
| 636 input_method::InputMethodManager::Get() | 851 input_method::InputMethodManager::Get() |
| 637 ->GetImeKeyboard() | 852 ->GetImeKeyboard() |
| 638 ->SetAutoRepeatRate(rate); | 853 ->SetAutoRepeatRate(rate); |
| 639 } | 854 } |
| 640 | 855 |
| 641 void Preferences::OnTouchHudProjectionToggled(bool enabled) { | 856 void Preferences::OnTouchHudProjectionToggled(bool enabled) { |
| 642 if (touch_hud_projection_enabled_.GetValue() == enabled) | 857 if (touch_hud_projection_enabled_.GetValue() == enabled) |
| 643 return; | 858 return; |
| 644 if (!user_->is_active()) | 859 if (!user_->is_active()) |
| 645 return; | 860 return; |
| 646 touch_hud_projection_enabled_.SetValue(enabled); | 861 touch_hud_projection_enabled_.SetValue(enabled); |
| 647 } | 862 } |
| 648 | 863 |
| 649 void Preferences::ActiveUserChanged(const User* active_user) { | 864 void Preferences::ActiveUserChanged(const User* active_user) { |
| 650 if (active_user != user_) | 865 if (active_user != user_) |
| 651 return; | 866 return; |
| 652 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, ""); | 867 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, ""); |
| 653 } | 868 } |
| 654 | 869 |
| 655 } // namespace chromeos | 870 } // namespace chromeos |
| OLD | NEW |