| 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 "base/chromeos/chromeos_version.h" | 7 #include "base/chromeos/chromeos_version.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/i18n/time_formatting.h" | 9 #include "base/i18n/time_formatting.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 false, | 127 false, |
| 128 PrefService::SYNCABLE_PREF); | 128 PrefService::SYNCABLE_PREF); |
| 129 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod | 129 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod |
| 130 // because they're just used to track the logout state of the device. | 130 // because they're just used to track the logout state of the device. |
| 131 prefs->RegisterStringPref(prefs::kLanguageCurrentInputMethod, | 131 prefs->RegisterStringPref(prefs::kLanguageCurrentInputMethod, |
| 132 "", | 132 "", |
| 133 PrefService::UNSYNCABLE_PREF); | 133 PrefService::UNSYNCABLE_PREF); |
| 134 prefs->RegisterStringPref(prefs::kLanguagePreviousInputMethod, | 134 prefs->RegisterStringPref(prefs::kLanguagePreviousInputMethod, |
| 135 "", | 135 "", |
| 136 PrefService::UNSYNCABLE_PREF); | 136 PrefService::UNSYNCABLE_PREF); |
| 137 // We don't sync input method hotkeys since they're not configurable. | |
| 138 prefs->RegisterStringPref(prefs::kLanguageHotkeyNextEngineInMenu, | |
| 139 language_prefs::kHotkeyNextEngineInMenu, | |
| 140 PrefService::UNSYNCABLE_PREF); | |
| 141 prefs->RegisterStringPref(prefs::kLanguageHotkeyPreviousEngine, | |
| 142 language_prefs::kHotkeyPreviousEngine, | |
| 143 PrefService::UNSYNCABLE_PREF); | |
| 144 // We don't sync the list of input methods and preferred languages since a | 137 // We don't sync the list of input methods and preferred languages since a |
| 145 // user might use two or more devices with different hardware keyboards. | 138 // user might use two or more devices with different hardware keyboards. |
| 146 // crosbug.com/15181 | 139 // crosbug.com/15181 |
| 147 prefs->RegisterStringPref(prefs::kLanguagePreferredLanguages, | 140 prefs->RegisterStringPref(prefs::kLanguagePreferredLanguages, |
| 148 kFallbackInputMethodLocale, | 141 kFallbackInputMethodLocale, |
| 149 PrefService::UNSYNCABLE_PREF); | 142 PrefService::UNSYNCABLE_PREF); |
| 150 prefs->RegisterStringPref(prefs::kLanguagePreloadEngines, | 143 prefs->RegisterStringPref(prefs::kLanguagePreloadEngines, |
| 151 hardware_keyboard_id, | 144 hardware_keyboard_id, |
| 152 PrefService::UNSYNCABLE_PREF); | 145 PrefService::UNSYNCABLE_PREF); |
| 153 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { | 146 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, this); | 264 mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, this); |
| 272 touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, this); | 265 touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, this); |
| 273 use_24hour_clock_.Init(prefs::kUse24HourClock, prefs, this); | 266 use_24hour_clock_.Init(prefs::kUse24HourClock, prefs, this); |
| 274 disable_gdata_.Init(prefs::kDisableGData, prefs, this); | 267 disable_gdata_.Init(prefs::kDisableGData, prefs, this); |
| 275 disable_gdata_over_cellular_.Init(prefs::kDisableGDataOverCellular, | 268 disable_gdata_over_cellular_.Init(prefs::kDisableGDataOverCellular, |
| 276 prefs, this); | 269 prefs, this); |
| 277 disable_gdata_hosted_files_.Init(prefs::kDisableGDataHostedFiles, | 270 disable_gdata_hosted_files_.Init(prefs::kDisableGDataHostedFiles, |
| 278 prefs, this); | 271 prefs, this); |
| 279 primary_mouse_button_right_.Init(prefs::kPrimaryMouseButtonRight, | 272 primary_mouse_button_right_.Init(prefs::kPrimaryMouseButtonRight, |
| 280 prefs, this); | 273 prefs, this); |
| 281 hotkey_next_engine_in_menu_.Init( | |
| 282 prefs::kLanguageHotkeyNextEngineInMenu, prefs, this); | |
| 283 hotkey_previous_engine_.Init( | |
| 284 prefs::kLanguageHotkeyPreviousEngine, prefs, this); | |
| 285 preferred_languages_.Init(prefs::kLanguagePreferredLanguages, | 274 preferred_languages_.Init(prefs::kLanguagePreferredLanguages, |
| 286 prefs, this); | 275 prefs, this); |
| 287 preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, this); | 276 preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, this); |
| 288 current_input_method_.Init(prefs::kLanguageCurrentInputMethod, prefs, this); | 277 current_input_method_.Init(prefs::kLanguageCurrentInputMethod, prefs, this); |
| 289 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod, prefs, this); | 278 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod, prefs, this); |
| 290 | 279 |
| 291 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { | 280 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { |
| 292 chewing_boolean_prefs_[i].Init( | 281 chewing_boolean_prefs_[i].Init( |
| 293 language_prefs::kChewingBooleanPrefs[i].pref_name, prefs, this); | 282 language_prefs::kChewingBooleanPrefs[i].pref_name, prefs, this); |
| 294 } | 283 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 } | 404 } |
| 416 if (!pref_name || *pref_name == prefs::kPrimaryMouseButtonRight) { | 405 if (!pref_name || *pref_name == prefs::kPrimaryMouseButtonRight) { |
| 417 const bool right = primary_mouse_button_right_.GetValue(); | 406 const bool right = primary_mouse_button_right_.GetValue(); |
| 418 system::mouse_settings::SetPrimaryButtonRight(right); | 407 system::mouse_settings::SetPrimaryButtonRight(right); |
| 419 if (pref_name) | 408 if (pref_name) |
| 420 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Changed", right); | 409 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Changed", right); |
| 421 else | 410 else |
| 422 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Started", right); | 411 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Started", right); |
| 423 } | 412 } |
| 424 | 413 |
| 425 if (!pref_name || *pref_name == prefs::kLanguageHotkeyNextEngineInMenu) { | |
| 426 SetLanguageConfigStringListAsCSV( | |
| 427 language_prefs::kHotKeySectionName, | |
| 428 language_prefs::kNextEngineInMenuConfigName, | |
| 429 hotkey_next_engine_in_menu_.GetValue()); | |
| 430 } | |
| 431 if (!pref_name || *pref_name == prefs::kLanguageHotkeyPreviousEngine) { | |
| 432 SetLanguageConfigStringListAsCSV( | |
| 433 language_prefs::kHotKeySectionName, | |
| 434 language_prefs::kPreviousEngineConfigName, | |
| 435 hotkey_previous_engine_.GetValue()); | |
| 436 } | |
| 437 if (!pref_name || *pref_name == prefs::kLanguagePreferredLanguages) { | 414 if (!pref_name || *pref_name == prefs::kLanguagePreferredLanguages) { |
| 438 // Unlike kLanguagePreloadEngines and some other input method | 415 // Unlike kLanguagePreloadEngines and some other input method |
| 439 // preferencs, we don't need to send this to ibus-daemon. | 416 // preferencs, we don't need to send this to ibus-daemon. |
| 440 } | 417 } |
| 441 | 418 |
| 442 // Here, we set up the the modifier key mapping. This has to be done | 419 // Here, we set up the the modifier key mapping. This has to be done |
| 443 // before changing the current keyboard layout, so that the modifier key | 420 // before changing the current keyboard layout, so that the modifier key |
| 444 // preference is properly preserved. For this reason, we should do this | 421 // preference is properly preserved. For this reason, we should do this |
| 445 // before setting preload engines, that could change the current | 422 // before setting preload engines, that could change the current |
| 446 // keyboard layout as needed. | 423 // keyboard layout as needed. |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 | 593 |
| 617 void Preferences::SetLanguageConfigStringListAsCSV(const char* section, | 594 void Preferences::SetLanguageConfigStringListAsCSV(const char* section, |
| 618 const char* name, | 595 const char* name, |
| 619 const std::string& value) { | 596 const std::string& value) { |
| 620 VLOG(1) << "Setting " << name << " to '" << value << "'"; | 597 VLOG(1) << "Setting " << name << " to '" << value << "'"; |
| 621 | 598 |
| 622 std::vector<std::string> split_values; | 599 std::vector<std::string> split_values; |
| 623 if (!value.empty()) | 600 if (!value.empty()) |
| 624 base::SplitString(value, ',', &split_values); | 601 base::SplitString(value, ',', &split_values); |
| 625 | 602 |
| 603 if (section == std::string(language_prefs::kGeneralSectionName) && |
| 604 name == std::string(language_prefs::kPreloadEnginesConfigName)) { |
| 605 input_method_manager_->EnableInputMethods(split_values); |
| 606 return; |
| 607 } |
| 608 |
| 626 // We should call the cros API even when |value| is empty, to disable default | 609 // We should call the cros API even when |value| is empty, to disable default |
| 627 // config. | 610 // config. |
| 628 SetLanguageConfigStringList(section, name, split_values); | 611 SetLanguageConfigStringList(section, name, split_values); |
| 629 } | 612 } |
| 630 | 613 |
| 631 void Preferences::SetInputMethodList() { | 614 void Preferences::SetInputMethodList() { |
| 632 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod() | 615 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod() |
| 633 // might be called to change the current input method to the first one in the | 616 // might be called to change the current input method to the first one in the |
| 634 // |preload_engines_| list. This also updates previous/current input method | 617 // |preload_engines_| list. This also updates previous/current input method |
| 635 // prefs. That's why GetValue() calls are placed before the | 618 // prefs. That's why GetValue() calls are placed before the |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 DCHECK(rate.initial_delay_in_ms > 0); | 675 DCHECK(rate.initial_delay_in_ms > 0); |
| 693 DCHECK(rate.repeat_interval_in_ms > 0); | 676 DCHECK(rate.repeat_interval_in_ms > 0); |
| 694 input_method::XKeyboard::SetAutoRepeatRate(rate); | 677 input_method::XKeyboard::SetAutoRepeatRate(rate); |
| 695 } | 678 } |
| 696 | 679 |
| 697 void Preferences::UpdateVirturalKeyboardPreference(PrefService* prefs) { | 680 void Preferences::UpdateVirturalKeyboardPreference(PrefService* prefs) { |
| 698 const DictionaryValue* virtual_keyboard_pref = | 681 const DictionaryValue* virtual_keyboard_pref = |
| 699 prefs->GetDictionary(prefs::kLanguagePreferredVirtualKeyboard); | 682 prefs->GetDictionary(prefs::kLanguagePreferredVirtualKeyboard); |
| 700 DCHECK(virtual_keyboard_pref); | 683 DCHECK(virtual_keyboard_pref); |
| 701 | 684 |
| 702 input_method::InputMethodManager* input_method_manager = | 685 // TODO(yusukes): Clear all virtual keyboard preferences here. |
| 703 input_method::InputMethodManager::GetInstance(); | |
| 704 input_method_manager->ClearAllVirtualKeyboardPreferences(); | |
| 705 | |
| 706 std::string url; | 686 std::string url; |
| 707 std::vector<std::string> layouts_to_remove; | 687 std::vector<std::string> layouts_to_remove; |
| 708 for (DictionaryValue::key_iterator iter = virtual_keyboard_pref->begin_keys(); | 688 for (DictionaryValue::key_iterator iter = virtual_keyboard_pref->begin_keys(); |
| 709 iter != virtual_keyboard_pref->end_keys(); | 689 iter != virtual_keyboard_pref->end_keys(); |
| 710 ++iter) { | 690 ++iter) { |
| 711 const std::string& layout_id = *iter; // e.g. "us", "handwriting-vk" | 691 const std::string& layout_id = *iter; // e.g. "us", "handwriting-vk" |
| 712 if (!virtual_keyboard_pref->GetString(layout_id, &url)) | 692 if (!virtual_keyboard_pref->GetString(layout_id, &url)) |
| 713 continue; | 693 continue; |
| 714 if (!input_method_manager->SetVirtualKeyboardPreference( | 694 // TODO(yusukes): add the virtual keyboard preferences here. |
| 715 layout_id, GURL(url))) { | |
| 716 // Either |layout_id| or |url| is invalid. Remove the key from |prefs| | |
| 717 // later. | |
| 718 layouts_to_remove.push_back(layout_id); | |
| 719 LOG(ERROR) << "Removing invalid virtual keyboard pref: layout=" | |
| 720 << layout_id; | |
| 721 } | |
| 722 } | 695 } |
| 723 | 696 |
| 724 // Remove invalid prefs. | 697 // Remove invalid prefs. |
| 725 DictionaryPrefUpdate updater(prefs, prefs::kLanguagePreferredVirtualKeyboard); | 698 DictionaryPrefUpdate updater(prefs, prefs::kLanguagePreferredVirtualKeyboard); |
| 726 DictionaryValue* pref_value = updater.Get(); | 699 DictionaryValue* pref_value = updater.Get(); |
| 727 for (size_t i = 0; i < layouts_to_remove.size(); ++i) { | 700 for (size_t i = 0; i < layouts_to_remove.size(); ++i) { |
| 728 pref_value->RemoveWithoutPathExpansion(layouts_to_remove[i], NULL); | 701 pref_value->RemoveWithoutPathExpansion(layouts_to_remove[i], NULL); |
| 729 } | 702 } |
| 730 } | 703 } |
| 731 | 704 |
| 732 } // namespace chromeos | 705 } // namespace chromeos |
| OLD | NEW |