Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: chrome/browser/chromeos/preferences.cc

Issue 312023002: Sync starting language and input method preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase and dzhioev's comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/system/input_device_settings.h" 28 #include "chrome/browser/chromeos/system/input_device_settings.h"
29 #include "chrome/browser/download/download_prefs.h" 29 #include "chrome/browser/download/download_prefs.h"
30 #include "chrome/browser/prefs/pref_service_syncable.h" 30 #include "chrome/browser/prefs/pref_service_syncable.h"
31 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
33 #include "chromeos/chromeos_switches.h" 33 #include "chromeos/chromeos_switches.h"
34 #include "chromeos/ime/component_extension_ime_manager.h"
34 #include "chromeos/ime/extension_ime_util.h" 35 #include "chromeos/ime/extension_ime_util.h"
35 #include "chromeos/ime/ime_keyboard.h" 36 #include "chromeos/ime/ime_keyboard.h"
36 #include "chromeos/ime/input_method_manager.h" 37 #include "chromeos/ime/input_method_manager.h"
37 #include "chromeos/system/statistics_provider.h" 38 #include "chromeos/system/statistics_provider.h"
38 #include "components/feedback/tracing_manager.h" 39 #include "components/feedback/tracing_manager.h"
39 #include "components/pref_registry/pref_registry_syncable.h" 40 #include "components/pref_registry/pref_registry_syncable.h"
40 #include "components/user_manager/user.h" 41 #include "components/user_manager/user.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
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 prefs, callback); 453 prefs, callback);
327 natural_scroll_.Init(prefs::kNaturalScroll, prefs, callback); 454 natural_scroll_.Init(prefs::kNaturalScroll, prefs, callback);
328 mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, callback); 455 mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, callback);
329 touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, callback); 456 touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, callback);
330 primary_mouse_button_right_.Init(prefs::kPrimaryMouseButtonRight, 457 primary_mouse_button_right_.Init(prefs::kPrimaryMouseButtonRight,
331 prefs, callback); 458 prefs, callback);
332 download_default_directory_.Init(prefs::kDownloadDefaultDirectory, 459 download_default_directory_.Init(prefs::kDownloadDefaultDirectory,
333 prefs, callback); 460 prefs, callback);
334 touch_hud_projection_enabled_.Init(prefs::kTouchHudProjectionEnabled, 461 touch_hud_projection_enabled_.Init(prefs::kTouchHudProjectionEnabled,
335 prefs, callback); 462 prefs, callback);
463 preferred_languages_.Init(prefs::kLanguagePreferredLanguages,
464 prefs, callback);
336 preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, callback); 465 preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, callback);
337 enabled_extension_imes_.Init(prefs::kLanguageEnabledExtensionImes, 466 enabled_extension_imes_.Init(prefs::kLanguageEnabledExtensionImes,
338 prefs, callback); 467 prefs, callback);
468 preferred_languages_syncable_.Init(prefs::kLanguagePreferredLanguagesSyncable,
469 prefs, callback);
470 preload_engines_syncable_.Init(prefs::kLanguagePreloadEnginesSyncable,
471 prefs, callback);
472 enabled_extension_imes_syncable_.Init(
473 prefs::kLanguageEnabledExtensionImesSyncable, prefs, callback);
339 current_input_method_.Init(prefs::kLanguageCurrentInputMethod, 474 current_input_method_.Init(prefs::kLanguageCurrentInputMethod,
340 prefs, callback); 475 prefs, callback);
341 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod, 476 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod,
342 prefs, callback); 477 prefs, callback);
343 478
344 xkb_auto_repeat_enabled_.Init( 479 xkb_auto_repeat_enabled_.Init(
345 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback); 480 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback);
346 xkb_auto_repeat_delay_pref_.Init( 481 xkb_auto_repeat_delay_pref_.Init(
347 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback); 482 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback);
348 xkb_auto_repeat_interval_pref_.Init( 483 xkb_auto_repeat_interval_pref_.Init(
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 default_download_to_drive); 644 default_download_to_drive);
510 else if (reason == REASON_INITIALIZATION) 645 else if (reason == REASON_INITIALIZATION)
511 UMA_HISTOGRAM_BOOLEAN( 646 UMA_HISTOGRAM_BOOLEAN(
512 "FileBrowser.DownloadDestination.IsGoogleDrive.Started", 647 "FileBrowser.DownloadDestination.IsGoogleDrive.Started",
513 default_download_to_drive); 648 default_download_to_drive);
514 } 649 }
515 if (reason != REASON_PREF_CHANGED || 650 if (reason != REASON_PREF_CHANGED ||
516 pref_name == prefs::kTouchHudProjectionEnabled) { 651 pref_name == prefs::kTouchHudProjectionEnabled) {
517 if (user_is_active) { 652 if (user_is_active) {
518 const bool enabled = touch_hud_projection_enabled_.GetValue(); 653 const bool enabled = touch_hud_projection_enabled_.GetValue();
519 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled); 654 // There may not be a shell, e.g., in some unit tests.
655 if (ash::Shell::HasInstance())
656 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled);
520 } 657 }
521 } 658 }
522 659
523 if (reason != REASON_PREF_CHANGED || 660 if (reason != REASON_PREF_CHANGED ||
524 pref_name == prefs::kLanguageXkbAutoRepeatEnabled) { 661 pref_name == prefs::kLanguageXkbAutoRepeatEnabled) {
525 if (user_is_active) { 662 if (user_is_active) {
526 const bool enabled = xkb_auto_repeat_enabled_.GetValue(); 663 const bool enabled = xkb_auto_repeat_enabled_.GetValue();
527 input_method::InputMethodManager::Get() 664 input_method::InputMethodManager::Get()
528 ->GetImeKeyboard() 665 ->GetImeKeyboard()
529 ->SetAutoRepeatEnabled(enabled); 666 ->SetAutoRepeatEnabled(enabled);
530 } 667 }
531 } 668 }
532 if (reason != REASON_PREF_CHANGED || 669 if (reason != REASON_PREF_CHANGED ||
533 pref_name == prefs::kLanguageXkbAutoRepeatDelay || 670 pref_name == prefs::kLanguageXkbAutoRepeatDelay ||
534 pref_name == prefs::kLanguageXkbAutoRepeatInterval) { 671 pref_name == prefs::kLanguageXkbAutoRepeatInterval) {
535 if (user_is_active) 672 if (user_is_active)
536 UpdateAutoRepeatRate(); 673 UpdateAutoRepeatRate();
537 } 674 }
538 675
676 if (reason == REASON_PREF_CHANGED &&
677 pref_name == prefs::kLanguagePreferredLanguages)
678 SetSyncableInputMethodPrefs();
679
539 if (reason != REASON_PREF_CHANGED && user_is_active) { 680 if (reason != REASON_PREF_CHANGED && user_is_active) {
540 SetInputMethodList(); 681 SetInputMethodList();
541 } else if (pref_name == prefs::kLanguagePreloadEngines && user_is_active) { 682 } else if (pref_name == prefs::kLanguagePreloadEngines) {
542 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, 683 if (user_is_active) {
543 language_prefs::kPreloadEnginesConfigName, 684 SetLanguageConfigStringListAsCSV(
544 preload_engines_.GetValue()); 685 language_prefs::kGeneralSectionName,
686 language_prefs::kPreloadEnginesConfigName,
687 preload_engines_.GetValue());
688 }
689 SetSyncableInputMethodPrefs();
545 } 690 }
546 691
547 if (reason != REASON_PREF_CHANGED || 692 if (reason != REASON_PREF_CHANGED ||
548 pref_name == prefs::kLanguageEnabledExtensionImes) { 693 pref_name == prefs::kLanguageEnabledExtensionImes) {
549 if (user_is_active) { 694 if (user_is_active)
550 std::string value(enabled_extension_imes_.GetValue()); 695 SetEnabledExtensionImes();
551 696 if (reason == REASON_PREF_CHANGED)
552 std::vector<std::string> split_values; 697 SetSyncableInputMethodPrefs();
553 if (!value.empty())
554 base::SplitString(value, ',', &split_values);
555
556 input_method_manager_->SetEnabledExtensionImes(&split_values);
557 }
558 } 698 }
559 699
560 if (user_is_active) { 700 if (user_is_active) {
561 system::InputDeviceSettings::Get()->UpdateTouchpadSettings( 701 system::InputDeviceSettings::Get()->UpdateTouchpadSettings(
562 touchpad_settings); 702 touchpad_settings);
563 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings); 703 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings);
564 } 704 }
565 } 705 }
566 706
567 void Preferences::OnIsSyncingChanged() { 707 void Preferences::OnIsSyncingChanged() {
568 DVLOG(1) << "OnIsSyncingChanged"; 708 DVLOG(1) << "OnIsSyncingChanged";
569 ForceNaturalScrollDefault(); 709 ForceNaturalScrollDefault();
710 if (prefs_->GetBoolean(prefs::kLanguageShouldMergeInputMethods) &&
711 prefs_->IsSyncing()) {
712 MergeSyncedInputMethods();
713 }
570 } 714 }
571 715
572 void Preferences::ForceNaturalScrollDefault() { 716 void Preferences::ForceNaturalScrollDefault() {
573 DVLOG(1) << "ForceNaturalScrollDefault"; 717 DVLOG(1) << "ForceNaturalScrollDefault";
574 if (CommandLine::ForCurrentProcess()->HasSwitch( 718 if (CommandLine::ForCurrentProcess()->HasSwitch(
575 switches::kNaturalScrollDefault) && 719 switches::kNaturalScrollDefault) &&
576 prefs_->IsSyncing() && 720 prefs_->IsSyncing() &&
577 !prefs_->GetUserPrefValue(prefs::kNaturalScroll)) { 721 !prefs_->GetUserPrefValue(prefs::kNaturalScroll)) {
578 DVLOG(1) << "Natural scroll forced to true"; 722 DVLOG(1) << "Natural scroll forced to true";
579 natural_scroll_.SetValue(true); 723 natural_scroll_.SetValue(true);
(...skipping 14 matching lines...) Expand all
594 if (input_method_manager_->MigrateInputMethods(&split_values)) 738 if (input_method_manager_->MigrateInputMethods(&split_values))
595 preload_engines_.SetValue(JoinString(split_values, ',')); 739 preload_engines_.SetValue(JoinString(split_values, ','));
596 740
597 if (section == std::string(language_prefs::kGeneralSectionName) && 741 if (section == std::string(language_prefs::kGeneralSectionName) &&
598 name == std::string(language_prefs::kPreloadEnginesConfigName)) { 742 name == std::string(language_prefs::kPreloadEnginesConfigName)) {
599 input_method_manager_->ReplaceEnabledInputMethods(split_values); 743 input_method_manager_->ReplaceEnabledInputMethods(split_values);
600 return; 744 return;
601 } 745 }
602 } 746 }
603 747
748 void Preferences::SetPreferredLanguages(scoped_ptr<std::string> languages) {
749 // Since this only removes locales that are unsupported on this system, we
750 // don't need to update the syncable prefs. If the local preference changes
751 // later, the sync server will lose the values we dropped, but that's okay
752 // since the values from this device would become the new defaults anyway.
753 if (*languages != preferred_languages_.GetValue())
754 preferred_languages_.SetValue(*languages);
755 }
756
604 void Preferences::SetInputMethodList() { 757 void Preferences::SetInputMethodList() {
605 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod() 758 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod()
606 // might be called to change the current input method to the first one in the 759 // might be called to change the current input method to the first one in the
607 // |preload_engines_| list. This also updates previous/current input method 760 // |preload_engines_| list. This also updates previous/current input method
608 // prefs. That's why GetValue() calls are placed before the 761 // prefs. That's why GetValue() calls are placed before the
609 // SetLanguageConfigStringListAsCSV() call below. 762 // SetLanguageConfigStringListAsCSV() call below.
610 const std::string previous_input_method_id = 763 const std::string previous_input_method_id =
611 previous_input_method_.GetValue(); 764 previous_input_method_.GetValue();
612 const std::string current_input_method_id = current_input_method_.GetValue(); 765 const std::string current_input_method_id = current_input_method_.GetValue();
613 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, 766 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
614 language_prefs::kPreloadEnginesConfigName, 767 language_prefs::kPreloadEnginesConfigName,
615 preload_engines_.GetValue()); 768 preload_engines_.GetValue());
616 769
617 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_| 770 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_|
618 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request 771 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request
619 // might be ignored as an invalid input method ID. The ChangeInputMethod() 772 // might be ignored as an invalid input method ID. The ChangeInputMethod()
620 // calls are also necessary to restore the previous/current input method prefs 773 // calls are also necessary to restore the previous/current input method prefs
621 // which could have been modified by the SetLanguageConfigStringListAsCSV call 774 // which could have been modified by the SetLanguageConfigStringListAsCSV call
622 // above to the original state. 775 // above to the original state.
623 if (!previous_input_method_id.empty()) 776 if (!previous_input_method_id.empty())
624 input_method_manager_->ChangeInputMethod(previous_input_method_id); 777 input_method_manager_->ChangeInputMethod(previous_input_method_id);
625 if (!current_input_method_id.empty()) 778 if (!current_input_method_id.empty())
626 input_method_manager_->ChangeInputMethod(current_input_method_id); 779 input_method_manager_->ChangeInputMethod(current_input_method_id);
627 } 780 }
628 781
782 void Preferences::SetEnabledExtensionImes() {
783 std::string value(enabled_extension_imes_.GetValue());
784 std::vector<std::string> split_values;
785 if (!value.empty())
786 base::SplitString(value, ',', &split_values);
787 input_method_manager_->SetEnabledExtensionImes(&split_values);
788 }
789
790 void Preferences::SetSyncableInputMethodPrefs() {
791 // Set the language and input prefs at the same time. Otherwise, we may,
792 // e.g., use a stale languages setting but push a new preload engines setting.
793 preferred_languages_syncable_.SetValue(preferred_languages_.GetValue());
794 enabled_extension_imes_syncable_.SetValue(
795 enabled_extension_imes_.GetValue());
796
797 // For preload engines, use legacy xkb IDs so the preference can sync
798 // across Chrome OS and Chromium OS.
799 std::vector<std::string> engines;
800 base::SplitString(preload_engines_.GetValue(), ',', &engines);
801 std::transform(engines.begin(), engines.end(), engines.begin(),
802 extension_ime_util::GetEngineIDByInputMethodID);
803 preload_engines_syncable_.SetValue(JoinString(engines, ','));
804 }
805
806 void Preferences::MergeSyncedInputMethods() {
807 // This should only be done on the first ever sync.
808 DCHECK(prefs_->GetBoolean(prefs::kLanguageShouldMergeInputMethods));
809 prefs_->SetBoolean(prefs::kLanguageShouldMergeInputMethods, false);
810
811 // Get the syncable values, because they will be overwritten once the local
812 // preferences are set.
813 std::string preferred_languages_syncable =
814 preferred_languages_syncable_.GetValue();
815 std::string preload_engines_syncable =
816 preload_engines_syncable_.GetValue();
817 std::string enabled_extension_imes_syncable =
818 enabled_extension_imes_syncable_.GetValue();
819
820 // Merge the values from the sync server into the local values.
821 prefs_->SetString(prefs::kLanguagePreferredLanguages,
822 AddSupportedInputMethodValues(preferred_languages_.GetValue(),
823 preferred_languages_syncable,
824 prefs::kLanguagePreferredLanguages));
825 prefs_->SetString(prefs::kLanguagePreloadEngines,
826 AddSupportedInputMethodValues(preload_engines_.GetValue(),
827 preload_engines_syncable,
828 prefs::kLanguagePreloadEngines));
829 prefs_->SetString(prefs::kLanguageEnabledExtensionImes,
830 AddSupportedInputMethodValues(enabled_extension_imes_.GetValue(),
831 enabled_extension_imes_syncable,
832 prefs::kLanguageEnabledExtensionImes));
833
834 // Check the new list of preferred languages to remove unsupported locales.
835 scoped_ptr<std::string> languages(
836 new std::string(preferred_languages_.GetValue()));
837 content::BrowserThread::PostTaskAndReply(
838 content::BrowserThread::FILE,
839 FROM_HERE,
840 base::Bind(&CheckAndResolveLocales, languages.get()),
841 base::Bind(&Preferences::SetPreferredLanguages,
842 weak_factory_.GetWeakPtr(),
843 base::Passed(&languages)));
844 }
845
629 void Preferences::UpdateAutoRepeatRate() { 846 void Preferences::UpdateAutoRepeatRate() {
630 input_method::AutoRepeatRate rate; 847 input_method::AutoRepeatRate rate;
631 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue(); 848 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue();
632 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue(); 849 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue();
633 DCHECK(rate.initial_delay_in_ms > 0); 850 DCHECK(rate.initial_delay_in_ms > 0);
634 DCHECK(rate.repeat_interval_in_ms > 0); 851 DCHECK(rate.repeat_interval_in_ms > 0);
635 input_method::InputMethodManager::Get() 852 input_method::InputMethodManager::Get()
636 ->GetImeKeyboard() 853 ->GetImeKeyboard()
637 ->SetAutoRepeatRate(rate); 854 ->SetAutoRepeatRate(rate);
638 } 855 }
639 856
640 void Preferences::OnTouchHudProjectionToggled(bool enabled) { 857 void Preferences::OnTouchHudProjectionToggled(bool enabled) {
641 if (touch_hud_projection_enabled_.GetValue() == enabled) 858 if (touch_hud_projection_enabled_.GetValue() == enabled)
642 return; 859 return;
643 if (!user_->is_active()) 860 if (!user_->is_active())
644 return; 861 return;
645 touch_hud_projection_enabled_.SetValue(enabled); 862 touch_hud_projection_enabled_.SetValue(enabled);
646 } 863 }
647 864
648 void Preferences::ActiveUserChanged(const user_manager::User* active_user) { 865 void Preferences::ActiveUserChanged(const user_manager::User* active_user) {
649 if (active_user != user_) 866 if (active_user != user_)
650 return; 867 return;
651 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, ""); 868 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, "");
652 } 869 }
653 870
654 } // namespace chromeos 871 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698