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

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: Created 6 years, 6 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 <vector>
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"
(...skipping 27 matching lines...) Expand all
38 #include "chromeos/system/statistics_provider.h" 38 #include "chromeos/system/statistics_provider.h"
39 #include "components/feedback/tracing_manager.h" 39 #include "components/feedback/tracing_manager.h"
40 #include "components/pref_registry/pref_registry_syncable.h" 40 #include "components/pref_registry/pref_registry_syncable.h"
41 #include "third_party/icu/source/i18n/unicode/timezone.h" 41 #include "third_party/icu/source/i18n/unicode/timezone.h"
42 #include "ui/events/event_constants.h" 42 #include "ui/events/event_constants.h"
43 #include "ui/events/event_utils.h" 43 #include "ui/events/event_utils.h"
44 #include "url/gurl.h" 44 #include "url/gurl.h"
45 45
46 namespace chromeos { 46 namespace chromeos {
47 47
48 namespace {
49
48 static const char kFallbackInputMethodLocale[] = "en-US"; 50 static const char kFallbackInputMethodLocale[] = "en-US";
49 51
52 // Returns a copy of |old_value| with any unique CSVs from |new_value|
53 // appended, a logical union that retains order. Quadratic runtime; use only
54 // for small lists.
michaelpg 2014/06/04 01:12:02 Why not use ListValues instead of StringValues for
55 std::string MergeCSVs(const std::string& old_value,
56 const std::string& new_value) {
57 std::string merged;
58 std::vector<std::string> old_tokens;
59 std::vector<std::string> new_tokens;
60
61 base::SplitString(old_value, ',', &old_tokens);
62 base::SplitString(new_value, ',', &new_tokens);
63
64 for (size_t i = 0; i < new_tokens.size(); i++) {
65 // Skip token if it's already in |old_tokens|.
66 if (std::find(old_tokens.begin(), old_tokens.end(), new_tokens[i]) ==
67 old_tokens.end())
68 old_tokens.push_back(new_tokens[i]);
69 }
70 return JoinString(old_tokens, ',');
71 }
72
73 // Merges one CSV pref into another using MergeCSVs.
74 void MergeStringPrefs(StringPrefMember& to_pref,
75 StringPrefMember& from_pref,
76 const std::string& pref_name) {
77 std::string to_value = to_pref.GetValue();
78 std::string from_value = from_pref.GetValue();
79
80 std::string merged_value = MergeCSVs(to_value, from_value);
81 if (merged_value != to_value)
82 to_pref.SetValue(merged_value);
83 }
84
85 } // anonymous namespace
86
50 Preferences::Preferences() 87 Preferences::Preferences()
51 : prefs_(NULL), 88 : prefs_(NULL),
52 input_method_manager_(input_method::InputMethodManager::Get()), 89 input_method_manager_(input_method::InputMethodManager::Get()),
90 should_merge_locale_prefs_(false),
53 user_(NULL), 91 user_(NULL),
54 user_is_primary_(false) { 92 user_is_primary_(false) {
55 // Do not observe shell, if there is no shell instance; e.g., in some unit 93 // Do not observe shell, if there is no shell instance; e.g., in some unit
56 // tests. 94 // tests.
57 if (ash::Shell::HasInstance()) 95 if (ash::Shell::HasInstance())
58 ash::Shell::GetInstance()->AddShellObserver(this); 96 ash::Shell::GetInstance()->AddShellObserver(this);
59 } 97 }
60 98
61 Preferences::Preferences(input_method::InputMethodManager* input_method_manager) 99 Preferences::Preferences(input_method::InputMethodManager* input_method_manager)
62 : prefs_(NULL), 100 : prefs_(NULL),
63 input_method_manager_(input_method_manager), 101 input_method_manager_(input_method_manager),
102 should_merge_locale_prefs_(false),
64 user_(NULL), 103 user_(NULL),
65 user_is_primary_(false) { 104 user_is_primary_(false) {
66 // Do not observe shell, if there is no shell instance; e.g., in some unit 105 // Do not observe shell, if there is no shell instance; e.g., in some unit
67 // tests. 106 // tests.
68 if (ash::Shell::HasInstance()) 107 if (ash::Shell::HasInstance())
69 ash::Shell::GetInstance()->AddShellObserver(this); 108 ash::Shell::GetInstance()->AddShellObserver(this);
70 } 109 }
71 110
72 Preferences::~Preferences() { 111 Preferences::~Preferences() {
73 prefs_->RemoveObserver(this); 112 prefs_->RemoveObserver(this);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod 245 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod
207 // because they're just used to track the logout state of the device. 246 // because they're just used to track the logout state of the device.
208 registry->RegisterStringPref( 247 registry->RegisterStringPref(
209 prefs::kLanguageCurrentInputMethod, 248 prefs::kLanguageCurrentInputMethod,
210 "", 249 "",
211 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 250 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
212 registry->RegisterStringPref( 251 registry->RegisterStringPref(
213 prefs::kLanguagePreviousInputMethod, 252 prefs::kLanguagePreviousInputMethod,
214 "", 253 "",
215 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 254 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
216 // We don't sync the list of input methods and preferred languages since a
217 // user might use two or more devices with different hardware keyboards.
218 // crosbug.com/15181
219 registry->RegisterStringPref( 255 registry->RegisterStringPref(
220 prefs::kLanguagePreferredLanguages, 256 prefs::kLanguagePreferredLanguages,
257 "",
258 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
259 registry->RegisterStringPref(
260 prefs::kLanguagePreferredLanguagesLocal,
Alexander Alekseev 2014/06/04 14:20:57 I think it is dangerous to change meaning of exist
221 kFallbackInputMethodLocale, 261 kFallbackInputMethodLocale,
222 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 262 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
223 registry->RegisterStringPref( 263 registry->RegisterStringPref(
224 prefs::kLanguagePreloadEngines, 264 prefs::kLanguagePreloadEngines,
265 "",
266 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
267 registry->RegisterStringPref(
268 prefs::kLanguagePreloadEnginesLocal,
Alexander Alekseev 2014/06/04 14:20:57 The same for engines.
225 hardware_keyboard_id, 269 hardware_keyboard_id,
226 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 270 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
227 registry->RegisterStringPref( 271 registry->RegisterStringPref(
228 prefs::kLanguageEnabledExtensionImes, 272 prefs::kLanguageEnabledExtensionImes,
229 "", 273 "",
274 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
275 registry->RegisterStringPref(
276 prefs::kLanguageEnabledExtensionImesLocal,
277 "",
Alexander Alekseev 2014/06/04 14:20:57 The same for EnabledExtensionsImes
230 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 278 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
231 279
232 registry->RegisterIntegerPref( 280 registry->RegisterIntegerPref(
233 prefs::kLanguageRemapSearchKeyTo, 281 prefs::kLanguageRemapSearchKeyTo,
234 input_method::kSearchKey, 282 input_method::kSearchKey,
235 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); 283 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
236 registry->RegisterIntegerPref( 284 registry->RegisterIntegerPref(
237 prefs::kLanguageRemapControlKeyTo, 285 prefs::kLanguageRemapControlKeyTo,
238 input_method::kControlKey, 286 input_method::kControlKey,
239 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); 287 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 prefs, callback); 370 prefs, callback);
323 natural_scroll_.Init(prefs::kNaturalScroll, prefs, callback); 371 natural_scroll_.Init(prefs::kNaturalScroll, prefs, callback);
324 mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, callback); 372 mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, callback);
325 touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, callback); 373 touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, callback);
326 primary_mouse_button_right_.Init(prefs::kPrimaryMouseButtonRight, 374 primary_mouse_button_right_.Init(prefs::kPrimaryMouseButtonRight,
327 prefs, callback); 375 prefs, callback);
328 download_default_directory_.Init(prefs::kDownloadDefaultDirectory, 376 download_default_directory_.Init(prefs::kDownloadDefaultDirectory,
329 prefs, callback); 377 prefs, callback);
330 touch_hud_projection_enabled_.Init(prefs::kTouchHudProjectionEnabled, 378 touch_hud_projection_enabled_.Init(prefs::kTouchHudProjectionEnabled,
331 prefs, callback); 379 prefs, callback);
380 preferred_languages_.Init(prefs::kLanguagePreferredLanguages,
381 prefs, callback);
382 preferred_languages_local_.Init(prefs::kLanguagePreferredLanguagesLocal,
383 prefs, callback);
332 preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, callback); 384 preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, callback);
385 preload_engines_local_.Init(prefs::kLanguagePreloadEnginesLocal,
386 prefs, callback);
333 enabled_extension_imes_.Init(prefs::kLanguageEnabledExtensionImes, 387 enabled_extension_imes_.Init(prefs::kLanguageEnabledExtensionImes,
334 prefs, callback); 388 prefs, callback);
389 enabled_extension_imes_local_.Init(prefs::kLanguageEnabledExtensionImesLocal,
390 prefs, callback);
335 current_input_method_.Init(prefs::kLanguageCurrentInputMethod, 391 current_input_method_.Init(prefs::kLanguageCurrentInputMethod,
336 prefs, callback); 392 prefs, callback);
337 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod, 393 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod,
338 prefs, callback); 394 prefs, callback);
339 395
340 xkb_auto_repeat_enabled_.Init( 396 xkb_auto_repeat_enabled_.Init(
341 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback); 397 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback);
342 xkb_auto_repeat_delay_pref_.Init( 398 xkb_auto_repeat_delay_pref_.Init(
343 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback); 399 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback);
344 xkb_auto_repeat_interval_pref_.Init( 400 xkb_auto_repeat_interval_pref_.Init(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 ApplyPreferences(REASON_PREF_CHANGED, pref_name); 437 ApplyPreferences(REASON_PREF_CHANGED, pref_name);
382 } 438 }
383 439
384 void Preferences::ApplyPreferences(ApplyReason reason, 440 void Preferences::ApplyPreferences(ApplyReason reason,
385 const std::string& pref_name) { 441 const std::string& pref_name) {
386 DCHECK(reason != REASON_PREF_CHANGED || !pref_name.empty()); 442 DCHECK(reason != REASON_PREF_CHANGED || !pref_name.empty());
387 const bool user_is_owner = 443 const bool user_is_owner =
388 UserManager::Get()->GetOwnerEmail() == user_->email(); 444 UserManager::Get()->GetOwnerEmail() == user_->email();
389 const bool user_is_active = user_->is_active(); 445 const bool user_is_active = user_->is_active();
390 446
447 if (reason == REASON_INITIALIZATION) {
448 // Check that the global language/input preferences have been set.
449 if (prefs_->FindPreference(prefs::kLanguagePreferredLanguages)->
450 HasUserSetting()) {
451 // If no local value has been set, this is a pre-existing profile.
452 if (!prefs_->FindPreference(prefs::kLanguagePreferredLanguagesLocal)->
453 HasUserSetting()) {
454 // Migrate to using local values by copying the global values.
455 preferred_languages_local_.SetValue(preferred_languages_.GetValue());
456 preload_engines_local_.SetValue(preload_engines_.GetValue());
Alexander Alekseev 2014/06/04 14:23:56 The same as my comment below: the list of supporte
457 enabled_extension_imes_local_.SetValue(
458 enabled_extension_imes_.GetValue());
Alexander Alekseev 2014/06/04 14:20:57 This is dangerous, as you do not check that remote
459 } else {
460 should_merge_locale_prefs_ = false;
461 }
462 } else {
463 // The global preference hasn't been set, so we need to sync and merge it.
464 should_merge_locale_prefs_ = true;
465 }
466 }
467
391 system::TouchpadSettings touchpad_settings; 468 system::TouchpadSettings touchpad_settings;
392 system::MouseSettings mouse_settings; 469 system::MouseSettings mouse_settings;
393 470
394 if (user_is_primary_ && (reason == REASON_INITIALIZATION || 471 if (user_is_primary_ && (reason == REASON_INITIALIZATION ||
395 pref_name == prefs::kPerformanceTracingEnabled)) { 472 pref_name == prefs::kPerformanceTracingEnabled)) {
396 const bool enabled = performance_tracing_enabled_.GetValue(); 473 const bool enabled = performance_tracing_enabled_.GetValue();
397 if (enabled) 474 if (enabled)
398 tracing_manager_ = TracingManager::Create(); 475 tracing_manager_ = TracingManager::Create();
399 else 476 else
400 tracing_manager_.reset(); 477 tracing_manager_.reset();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 default_download_to_drive); 581 default_download_to_drive);
505 else if (reason == REASON_INITIALIZATION) 582 else if (reason == REASON_INITIALIZATION)
506 UMA_HISTOGRAM_BOOLEAN( 583 UMA_HISTOGRAM_BOOLEAN(
507 "FileBrowser.DownloadDestination.IsGoogleDrive.Started", 584 "FileBrowser.DownloadDestination.IsGoogleDrive.Started",
508 default_download_to_drive); 585 default_download_to_drive);
509 } 586 }
510 if (reason != REASON_PREF_CHANGED || 587 if (reason != REASON_PREF_CHANGED ||
511 pref_name == prefs::kTouchHudProjectionEnabled) { 588 pref_name == prefs::kTouchHudProjectionEnabled) {
512 if (user_is_active) { 589 if (user_is_active) {
513 const bool enabled = touch_hud_projection_enabled_.GetValue(); 590 const bool enabled = touch_hud_projection_enabled_.GetValue();
514 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled); 591 // There may not be a shell, e.g., in some unit tests.
592 if (ash::Shell::HasInstance())
593 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled);
515 } 594 }
516 } 595 }
517 596
518 if (reason != REASON_PREF_CHANGED || 597 if (reason != REASON_PREF_CHANGED ||
519 pref_name == prefs::kLanguageXkbAutoRepeatEnabled) { 598 pref_name == prefs::kLanguageXkbAutoRepeatEnabled) {
520 if (user_is_active) { 599 if (user_is_active) {
521 const bool enabled = xkb_auto_repeat_enabled_.GetValue(); 600 const bool enabled = xkb_auto_repeat_enabled_.GetValue();
522 input_method::InputMethodManager::Get() 601 input_method::InputMethodManager::Get()
523 ->GetImeKeyboard() 602 ->GetImeKeyboard()
524 ->SetAutoRepeatEnabled(enabled); 603 ->SetAutoRepeatEnabled(enabled);
525 } 604 }
526 } 605 }
527 if (reason != REASON_PREF_CHANGED || 606 if (reason != REASON_PREF_CHANGED ||
528 pref_name == prefs::kLanguageXkbAutoRepeatDelay || 607 pref_name == prefs::kLanguageXkbAutoRepeatDelay ||
529 pref_name == prefs::kLanguageXkbAutoRepeatInterval) { 608 pref_name == prefs::kLanguageXkbAutoRepeatInterval) {
530 if (user_is_active) 609 if (user_is_active)
531 UpdateAutoRepeatRate(); 610 UpdateAutoRepeatRate();
532 } 611 }
533 612
613 if (reason == REASON_PREF_CHANGED &&
614 pref_name == prefs::kLanguagePreferredLanguagesLocal)
615 SetSyncedLocalePrefs();
616
534 if (reason != REASON_PREF_CHANGED && user_is_active) { 617 if (reason != REASON_PREF_CHANGED && user_is_active) {
535 SetInputMethodList(); 618 SetInputMethodList();
536 } else if (pref_name == prefs::kLanguagePreloadEngines && user_is_active) { 619 } else if (pref_name == prefs::kLanguagePreloadEnginesLocal) {
537 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, 620 if (user_is_active) {
538 language_prefs::kPreloadEnginesConfigName, 621 SetLanguageConfigStringListAsCSV(
539 preload_engines_.GetValue()); 622 language_prefs::kGeneralSectionName,
623 language_prefs::kPreloadEnginesConfigName,
624 preload_engines_local_.GetValue());
625 }
626 SetSyncedLocalePrefs();
540 } 627 }
541 628
542 if (reason != REASON_PREF_CHANGED || 629 if (reason != REASON_PREF_CHANGED ||
543 pref_name == prefs::kLanguageEnabledExtensionImes) { 630 pref_name == prefs::kLanguageEnabledExtensionImesLocal) {
544 if (user_is_active) { 631 if (user_is_active)
545 std::string value(enabled_extension_imes_.GetValue()); 632 SetEnabledExtensionImes();
546 633 if (reason == REASON_PREF_CHANGED)
547 std::vector<std::string> split_values; 634 SetSyncedLocalePrefs();
548 if (!value.empty())
549 base::SplitString(value, ',', &split_values);
550
551 input_method_manager_->SetEnabledExtensionImes(&split_values);
552 }
553 } 635 }
554 636
555 if (user_is_active) { 637 if (user_is_active) {
556 system::InputDeviceSettings::Get()->UpdateTouchpadSettings( 638 system::InputDeviceSettings::Get()->UpdateTouchpadSettings(
557 touchpad_settings); 639 touchpad_settings);
558 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings); 640 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings);
559 } 641 }
560 } 642 }
561 643
562 void Preferences::OnIsSyncingChanged() { 644 void Preferences::OnIsSyncingChanged() {
563 DVLOG(1) << "OnIsSyncingChanged"; 645 DVLOG(1) << "OnIsSyncingChanged";
564 ForceNaturalScrollDefault(); 646 ForceNaturalScrollDefault();
647
648 if (should_merge_locale_prefs_ && prefs_->IsSyncing()) {
649 should_merge_locale_prefs_ = false;
650 MergeStringPrefs(preferred_languages_local_,
651 preferred_languages_,
652 prefs::kLanguagePreferredLanguagesLocal);
653 MergeStringPrefs(preload_engines_local_,
654 preload_engines_,
655 prefs::kLanguagePreloadEnginesLocal);
656 MergeStringPrefs(enabled_extension_imes_local_,
657 enabled_extension_imes_,
658 prefs::kLanguageEnabledExtensionImesLocal);
659
660 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
661 language_prefs::kPreloadEnginesConfigName,
662 preload_engines_local_.GetValue());
663 SetEnabledExtensionImes();
664 SetSyncedLocalePrefs();
665 }
565 } 666 }
566 667
567 void Preferences::ForceNaturalScrollDefault() { 668 void Preferences::ForceNaturalScrollDefault() {
568 DVLOG(1) << "ForceNaturalScrollDefault"; 669 DVLOG(1) << "ForceNaturalScrollDefault";
569 if (CommandLine::ForCurrentProcess()->HasSwitch( 670 if (CommandLine::ForCurrentProcess()->HasSwitch(
570 switches::kNaturalScrollDefault) && 671 switches::kNaturalScrollDefault) &&
571 prefs_->IsSyncing() && 672 prefs_->IsSyncing() &&
572 !prefs_->GetUserPrefValue(prefs::kNaturalScroll)) { 673 !prefs_->GetUserPrefValue(prefs::kNaturalScroll)) {
573 DVLOG(1) << "Natural scroll forced to true"; 674 DVLOG(1) << "Natural scroll forced to true";
574 natural_scroll_.SetValue(true); 675 natural_scroll_.SetValue(true);
575 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Forced", true); 676 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Forced", true);
576 } 677 }
577 } 678 }
578 679
579 void Preferences::SetLanguageConfigStringListAsCSV(const char* section, 680 void Preferences::SetLanguageConfigStringListAsCSV(const char* section,
580 const char* name, 681 const char* name,
581 const std::string& value) { 682 const std::string& value) {
582 VLOG(1) << "Setting " << name << " to '" << value << "'"; 683 VLOG(1) << "Setting " << name << " to '" << value << "'";
583 684
584 std::vector<std::string> split_values; 685 std::vector<std::string> split_values;
585 if (!value.empty()) 686 if (!value.empty())
586 base::SplitString(value, ',', &split_values); 687 base::SplitString(value, ',', &split_values);
587 688
588 // Transfers the xkb id to extension-xkb id. 689 // Transfers the xkb id to extension-xkb id.
589 if (input_method_manager_->MigrateInputMethods(&split_values)) 690 if (input_method_manager_->MigrateInputMethods(&split_values))
590 preload_engines_.SetValue(JoinString(split_values, ',')); 691 preload_engines_local_.SetValue(JoinString(split_values, ','));
591 692
592 if (section == std::string(language_prefs::kGeneralSectionName) && 693 if (section == std::string(language_prefs::kGeneralSectionName) &&
593 name == std::string(language_prefs::kPreloadEnginesConfigName)) { 694 name == std::string(language_prefs::kPreloadEnginesConfigName)) {
594 input_method_manager_->ReplaceEnabledInputMethods(split_values); 695 input_method_manager_->ReplaceEnabledInputMethods(split_values);
595 return; 696 return;
596 } 697 }
597 } 698 }
598 699
599 void Preferences::SetInputMethodList() { 700 void Preferences::SetInputMethodList() {
600 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod() 701 // When |preload_engines_local_| are set,
601 // might be called to change the current input method to the first one in the 702 // InputMethodManager::ChangeInputMethod() might be called to change the
602 // |preload_engines_| list. This also updates previous/current input method 703 // current input method to the first one in the |preload_engines_local_| list.
603 // prefs. That's why GetValue() calls are placed before the 704 // This also updates previous/current input method prefs. That's why
604 // SetLanguageConfigStringListAsCSV() call below. 705 // GetValue() calls are placed before the SetLanguageConfigStringListAsCSV()
706 // call below.
605 const std::string previous_input_method_id = 707 const std::string previous_input_method_id =
606 previous_input_method_.GetValue(); 708 previous_input_method_.GetValue();
607 const std::string current_input_method_id = current_input_method_.GetValue(); 709 const std::string current_input_method_id = current_input_method_.GetValue();
608 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, 710 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
609 language_prefs::kPreloadEnginesConfigName, 711 language_prefs::kPreloadEnginesConfigName,
610 preload_engines_.GetValue()); 712 preload_engines_local_.GetValue());
611 713
612 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_| 714 // ChangeInputMethod() has to be called AFTER the value of
613 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request 715 // |preload_engines_local_| is sent to the InputMethodManager. Otherwise, the
614 // might be ignored as an invalid input method ID. The ChangeInputMethod() 716 // ChangeInputMethod request might be ignored as an invalid input method ID.
615 // calls are also necessary to restore the previous/current input method prefs 717 // The ChangeInputMethod() calls are also necessary to restore the
616 // which could have been modified by the SetLanguageConfigStringListAsCSV call 718 // previous/current input method prefs which could have been modified by the
617 // above to the original state. 719 // SetLanguageConfigStringListAsCSV call above to the original state.
618 if (!previous_input_method_id.empty()) 720 if (!previous_input_method_id.empty())
619 input_method_manager_->ChangeInputMethod(previous_input_method_id); 721 input_method_manager_->ChangeInputMethod(previous_input_method_id);
620 if (!current_input_method_id.empty()) 722 if (!current_input_method_id.empty())
621 input_method_manager_->ChangeInputMethod(current_input_method_id); 723 input_method_manager_->ChangeInputMethod(current_input_method_id);
622 } 724 }
623 725
726 void Preferences::SetEnabledExtensionImes() {
727 std::string value(enabled_extension_imes_local_.GetValue());
728 std::vector<std::string> split_values;
729 if (!value.empty())
730 base::SplitString(value, ',', &split_values);
731 input_method_manager_->SetEnabledExtensionImes(&split_values);
732 }
733
734 void Preferences::SetSyncedLocalePrefs() {
735 // Set the language and input prefs at the same time. Otherwise, we may,
736 // e.g., use a stale languages setting but push a new preload engines setting.
737 if (!should_merge_locale_prefs_) {
738 preferred_languages_.SetValue(preferred_languages_local_.GetValue());
739 preload_engines_.SetValue(preload_engines_local_.GetValue());
740 enabled_extension_imes_.SetValue(enabled_extension_imes_local_.GetValue());
741 }
742 }
743
624 void Preferences::UpdateAutoRepeatRate() { 744 void Preferences::UpdateAutoRepeatRate() {
625 input_method::AutoRepeatRate rate; 745 input_method::AutoRepeatRate rate;
626 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue(); 746 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue();
627 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue(); 747 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue();
628 DCHECK(rate.initial_delay_in_ms > 0); 748 DCHECK(rate.initial_delay_in_ms > 0);
629 DCHECK(rate.repeat_interval_in_ms > 0); 749 DCHECK(rate.repeat_interval_in_ms > 0);
630 input_method::InputMethodManager::Get() 750 input_method::InputMethodManager::Get()
631 ->GetImeKeyboard() 751 ->GetImeKeyboard()
632 ->SetAutoRepeatRate(rate); 752 ->SetAutoRepeatRate(rate);
633 } 753 }
634 754
635 void Preferences::OnTouchHudProjectionToggled(bool enabled) { 755 void Preferences::OnTouchHudProjectionToggled(bool enabled) {
636 if (touch_hud_projection_enabled_.GetValue() == enabled) 756 if (touch_hud_projection_enabled_.GetValue() == enabled)
637 return; 757 return;
638 if (!user_->is_active()) 758 if (!user_->is_active())
639 return; 759 return;
640 touch_hud_projection_enabled_.SetValue(enabled); 760 touch_hud_projection_enabled_.SetValue(enabled);
641 } 761 }
642 762
643 void Preferences::ActiveUserChanged(const User* active_user) { 763 void Preferences::ActiveUserChanged(const User* active_user) {
644 if (active_user != user_) 764 if (active_user != user_)
645 return; 765 return;
646 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, ""); 766 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, "");
647 } 767 }
648 768
649 } // namespace chromeos 769 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698