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

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 Created 6 years 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
« no previous file with comments | « chrome/browser/chromeos/preferences.h ('k') | chrome/browser/chromeos/preferences_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/shell.h" 10 #include "ash/shell.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/i18n/time_formatting.h" 12 #include "base/i18n/time_formatting.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/prefs/pref_member.h" 14 #include "base/prefs/pref_member.h"
15 #include "base/prefs/pref_registry_simple.h" 15 #include "base/prefs/pref_registry_simple.h"
16 #include "base/prefs/scoped_user_pref_update.h" 16 #include "base/prefs/scoped_user_pref_update.h"
17 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/sys_info.h" 20 #include "base/sys_info.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/chrome_notification_types.h" 22 #include "chrome/browser/chrome_notification_types.h"
23 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" 23 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
24 #include "chrome/browser/chromeos/drive/file_system_util.h" 24 #include "chrome/browser/chromeos/drive/file_system_util.h"
25 #include "chrome/browser/chromeos/input_method/input_method_util.h" 25 #include "chrome/browser/chromeos/input_method/input_method_syncer.h"
26 #include "chrome/browser/chromeos/login/session/user_session_manager.h" 26 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
27 #include "chrome/browser/chromeos/net/wake_on_wifi_manager.h" 27 #include "chrome/browser/chromeos/net/wake_on_wifi_manager.h"
28 #include "chrome/browser/chromeos/profiles/profile_helper.h"
29 #include "chrome/browser/chromeos/system/input_device_settings.h" 28 #include "chrome/browser/chromeos/system/input_device_settings.h"
30 #include "chrome/browser/download/download_prefs.h" 29 #include "chrome/browser/download/download_prefs.h"
31 #include "chrome/browser/prefs/pref_service_syncable.h" 30 #include "chrome/browser/prefs/pref_service_syncable.h"
32 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
34 #include "chromeos/chromeos_switches.h" 33 #include "chromeos/chromeos_switches.h"
35 #include "chromeos/system/statistics_provider.h" 34 #include "chromeos/system/statistics_provider.h"
36 #include "components/feedback/tracing_manager.h" 35 #include "components/feedback/tracing_manager.h"
37 #include "components/pref_registry/pref_registry_syncable.h" 36 #include "components/pref_registry/pref_registry_syncable.h"
38 #include "components/user_manager/user.h" 37 #include "components/user_manager/user.h"
38 #include "content/public/browser/browser_thread.h"
39 #include "third_party/icu/source/i18n/unicode/timezone.h" 39 #include "third_party/icu/source/i18n/unicode/timezone.h"
40 #include "ui/base/ime/chromeos/extension_ime_util.h" 40 #include "ui/base/ime/chromeos/extension_ime_util.h"
41 #include "ui/base/ime/chromeos/ime_keyboard.h" 41 #include "ui/base/ime/chromeos/ime_keyboard.h"
42 #include "ui/base/ime/chromeos/input_method_manager.h" 42 #include "ui/base/ime/chromeos/input_method_manager.h"
43 #include "ui/chromeos/accessibility_types.h" 43 #include "ui/chromeos/accessibility_types.h"
44 #include "ui/events/event_constants.h" 44 #include "ui/events/event_constants.h"
45 #include "ui/events/event_utils.h" 45 #include "ui/events/event_utils.h"
46 #include "url/gurl.h" 46 #include "url/gurl.h"
47 47
48 namespace chromeos { 48 namespace chromeos {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod 209 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod
210 // because they're just used to track the logout state of the device. 210 // because they're just used to track the logout state of the device.
211 registry->RegisterStringPref( 211 registry->RegisterStringPref(
212 prefs::kLanguageCurrentInputMethod, 212 prefs::kLanguageCurrentInputMethod,
213 "", 213 "",
214 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 214 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
215 registry->RegisterStringPref( 215 registry->RegisterStringPref(
216 prefs::kLanguagePreviousInputMethod, 216 prefs::kLanguagePreviousInputMethod,
217 "", 217 "",
218 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 218 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
219 // We don't sync the list of input methods and preferred languages since a
220 // user might use two or more devices with different hardware keyboards.
221 // crosbug.com/15181
222 registry->RegisterStringPref( 219 registry->RegisterStringPref(
223 prefs::kLanguagePreferredLanguages, 220 prefs::kLanguagePreferredLanguages,
224 kFallbackInputMethodLocale, 221 kFallbackInputMethodLocale,
225 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 222 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
226 registry->RegisterStringPref( 223 registry->RegisterStringPref(
227 prefs::kLanguagePreloadEngines, 224 prefs::kLanguagePreloadEngines,
228 hardware_keyboard_id, 225 hardware_keyboard_id,
229 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 226 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
230 registry->RegisterStringPref( 227 registry->RegisterStringPref(
231 prefs::kLanguageEnabledExtensionImes, 228 prefs::kLanguageEnabledExtensionImes,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 312
316 registry->RegisterBooleanPref( 313 registry->RegisterBooleanPref(
317 prefs::kTouchHudProjectionEnabled, 314 prefs::kTouchHudProjectionEnabled,
318 false, 315 false,
319 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 316 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
320 317
321 registry->RegisterBooleanPref( 318 registry->RegisterBooleanPref(
322 prefs::kTouchVirtualKeyboardEnabled, 319 prefs::kTouchVirtualKeyboardEnabled,
323 false, 320 false,
324 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 321 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
322
323 input_method::InputMethodSyncer::RegisterProfilePrefs(registry);
325 } 324 }
326 325
327 void Preferences::InitUserPrefs(PrefServiceSyncable* prefs) { 326 void Preferences::InitUserPrefs(PrefServiceSyncable* prefs) {
328 prefs_ = prefs; 327 prefs_ = prefs;
329 328
330 BooleanPrefMember::NamedChangeCallback callback = 329 BooleanPrefMember::NamedChangeCallback callback =
331 base::Bind(&Preferences::OnPreferenceChanged, base::Unretained(this)); 330 base::Bind(&Preferences::OnPreferenceChanged, base::Unretained(this));
332 331
333 performance_tracing_enabled_.Init(prefs::kPerformanceTracingEnabled, 332 performance_tracing_enabled_.Init(prefs::kPerformanceTracingEnabled,
334 prefs, callback); 333 prefs, callback);
(...skipping 25 matching lines...) Expand all
360 xkb_auto_repeat_interval_pref_.Init( 359 xkb_auto_repeat_interval_pref_.Init(
361 prefs::kLanguageXkbAutoRepeatInterval, prefs, callback); 360 prefs::kLanguageXkbAutoRepeatInterval, prefs, callback);
362 361
363 wake_on_wifi_enabled_.Init(prefs::kWakeOnWiFiEnabled, prefs, callback); 362 wake_on_wifi_enabled_.Init(prefs::kWakeOnWiFiEnabled, prefs, callback);
364 } 363 }
365 364
366 void Preferences::Init(Profile* profile, const user_manager::User* user) { 365 void Preferences::Init(Profile* profile, const user_manager::User* user) {
367 DCHECK(profile); 366 DCHECK(profile);
368 DCHECK(user); 367 DCHECK(user);
369 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile); 368 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile);
369 // This causes OnIsSyncingChanged to be called when the value of
370 // PrefService::IsSyncing() changes.
371 prefs->AddObserver(this);
370 user_ = user; 372 user_ = user;
371 user_is_primary_ = 373 user_is_primary_ =
372 user_manager::UserManager::Get()->GetPrimaryUser() == user_; 374 user_manager::UserManager::Get()->GetPrimaryUser() == user_;
373 InitUserPrefs(prefs); 375 InitUserPrefs(prefs);
374 376
375 user_manager::UserManager::Get()->AddSessionStateObserver(this); 377 user_manager::UserManager::Get()->AddSessionStateObserver(this);
376 378
377 // This causes OnIsSyncingChanged to be called when the value of
378 // PrefService::IsSyncing() changes.
379 prefs->AddObserver(this);
380
381 UserSessionManager* session_manager = UserSessionManager::GetInstance(); 379 UserSessionManager* session_manager = UserSessionManager::GetInstance();
382 DCHECK(session_manager); 380 DCHECK(session_manager);
383 ime_state_ = session_manager->GetDefaultIMEState(profile); 381 ime_state_ = session_manager->GetDefaultIMEState(profile);
384 input_method_manager_->SetState(ime_state_); 382 input_method_manager_->SetState(ime_state_);
385 383
386 // Initialize preferences to currently saved state. 384 // Initialize preferences to currently saved state.
387 ApplyPreferences(REASON_INITIALIZATION, ""); 385 ApplyPreferences(REASON_INITIALIZATION, "");
386 input_method_syncer_.reset(
387 new input_method::InputMethodSyncer(prefs, ime_state_));
388 input_method_syncer_->Initialize();
388 389
389 // If a guest is logged in, initialize the prefs as if this is the first 390 // If a guest is logged in, initialize the prefs as if this is the first
390 // login. For a regular user this is done in 391 // login. For a regular user this is done in
391 // UserSessionManager::InitProfilePreferences(). 392 // UserSessionManager::InitProfilePreferences().
392 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) 393 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession))
393 session_manager->SetFirstLoginPrefs(profile, std::string(), std::string()); 394 session_manager->SetFirstLoginPrefs(profile, std::string(), std::string());
394 } 395 }
395 396
396 void Preferences::InitUserPrefsForTesting( 397 void Preferences::InitUserPrefsForTesting(
397 PrefServiceSyncable* prefs, 398 PrefServiceSyncable* prefs,
398 const user_manager::User* user, 399 const user_manager::User* user,
399 scoped_refptr<input_method::InputMethodManager::State> ime_state) { 400 scoped_refptr<input_method::InputMethodManager::State> ime_state) {
400 user_ = user; 401 user_ = user;
401 ime_state_ = ime_state; 402 ime_state_ = ime_state;
402 403
403 if (ime_state.get()) 404 if (ime_state.get())
404 input_method_manager_->SetState(ime_state); 405 input_method_manager_->SetState(ime_state);
405 406
406 InitUserPrefs(prefs); 407 InitUserPrefs(prefs);
408
409 input_method_syncer_.reset(
410 new input_method::InputMethodSyncer(prefs, ime_state_));
411 input_method_syncer_->Initialize();
407 } 412 }
408 413
409 void Preferences::SetInputMethodListForTesting() { 414 void Preferences::SetInputMethodListForTesting() {
410 SetInputMethodList(); 415 SetInputMethodList();
411 } 416 }
412 417
413 void Preferences::OnPreferenceChanged(const std::string& pref_name) { 418 void Preferences::OnPreferenceChanged(const std::string& pref_name) {
414 ApplyPreferences(REASON_PREF_CHANGED, pref_name); 419 ApplyPreferences(REASON_PREF_CHANGED, pref_name);
415 } 420 }
416 421
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 else if (reason == REASON_INITIALIZATION) 543 else if (reason == REASON_INITIALIZATION)
539 UMA_HISTOGRAM_BOOLEAN( 544 UMA_HISTOGRAM_BOOLEAN(
540 "FileBrowser.DownloadDestination.IsGoogleDrive.Started", 545 "FileBrowser.DownloadDestination.IsGoogleDrive.Started",
541 default_download_to_drive); 546 default_download_to_drive);
542 } 547 }
543 if (reason != REASON_PREF_CHANGED || 548 if (reason != REASON_PREF_CHANGED ||
544 pref_name == prefs::kTouchHudProjectionEnabled) { 549 pref_name == prefs::kTouchHudProjectionEnabled) {
545 #if !defined(USE_ATHENA) 550 #if !defined(USE_ATHENA)
546 if (user_is_active) { 551 if (user_is_active) {
547 const bool enabled = touch_hud_projection_enabled_.GetValue(); 552 const bool enabled = touch_hud_projection_enabled_.GetValue();
548 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled); 553 // There may not be a shell, e.g., in some unit tests.
554 if (ash::Shell::HasInstance())
555 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled);
549 } 556 }
550 #endif 557 #endif
551 } 558 }
552 559
553 if (reason != REASON_PREF_CHANGED || 560 if (reason != REASON_PREF_CHANGED ||
554 pref_name == prefs::kLanguageXkbAutoRepeatEnabled) { 561 pref_name == prefs::kLanguageXkbAutoRepeatEnabled) {
555 if (user_is_active) { 562 if (user_is_active) {
556 const bool enabled = xkb_auto_repeat_enabled_.GetValue(); 563 const bool enabled = xkb_auto_repeat_enabled_.GetValue();
557 input_method::InputMethodManager::Get() 564 input_method::InputMethodManager::Get()
558 ->GetImeKeyboard() 565 ->GetImeKeyboard()
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 touch_hud_projection_enabled_.SetValue(enabled); 692 touch_hud_projection_enabled_.SetValue(enabled);
686 } 693 }
687 694
688 void Preferences::ActiveUserChanged(const user_manager::User* active_user) { 695 void Preferences::ActiveUserChanged(const user_manager::User* active_user) {
689 if (active_user != user_) 696 if (active_user != user_)
690 return; 697 return;
691 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, ""); 698 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, "");
692 } 699 }
693 700
694 } // namespace chromeos 701 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/preferences.h ('k') | chrome/browser/chromeos/preferences_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698