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

Unified Diff: chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc

Issue 18856014: We should switch the keyboard layout to the layout the user set according to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix MockInputMethodManager build. Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc
diff --git a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc
index 449b5eeb5400aa3a01190ef1375b150dd5435fc0..2a1bea3a6957fa693b0f5b658de6c0bdb3cd2133 100644
--- a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc
+++ b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc
@@ -5,11 +5,13 @@
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "base/callback.h"
+#include "base/chromeos/chromeos_version.h"
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
+#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
@@ -19,6 +21,7 @@
#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
+#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
#include "chrome/browser/chromeos/login/hwid_checker.h"
#include "chrome/browser/chromeos/login/login_display_host_impl.h"
@@ -103,6 +106,12 @@ void ClearDnsCache(IOThread* io_thread) {
io_thread->ClearHostCache();
}
+static bool Contains(const std::vector<std::string>& container,
+ const std::string& value) {
+ return std::find(container.begin(), container.end(), value) !=
+ container.end();
+}
+
} // namespace
namespace chromeos {
@@ -812,6 +821,10 @@ void SigninScreenHandler::RegisterMessages() {
&SigninScreenHandler::HandleUpdateOfflineLogin);
}
+void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) {
+ registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod);
+}
+
void SigninScreenHandler::HandleGetUsers() {
SendUserList(false);
}
@@ -968,6 +981,109 @@ void SigninScreenHandler::OnDnsCleared() {
ShowSigninScreenIfReady();
}
+void SigninScreenHandler::SetUserInputMethodHWDefault() {
+#if defined(OS_CHROMEOS)
Nikita (slow) 2013/07/11 09:13:54 No need for OS_CHROMEOS here as this class is alre
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ chromeos::input_method::InputMethodManager* manager =
+ chromeos::input_method::InputMethodManager::Get();
+ manager->ChangeInputMethod(
+ manager->GetInputMethodUtil()->GetHardwareInputMethodId());
+#endif
+}
+
+void SigninScreenHandler::SetUserInputMethod(const std::string& username) {
+#if defined(OS_CHROMEOS)
Nikita (slow) 2013/07/11 09:13:54 nit: same here.
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ // Update keyboard layout to least recently used by the user
+ if (g_browser_process == NULL)
Nikita (slow) 2013/07/11 09:13:54 nit: drop this check.
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ return;
+
+ if (!base::chromeos::IsRunningOnChromeOS())
Nikita (slow) 2013/07/11 09:13:54 What about relying on stubs instead when not runni
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ return;
+
+ PrefService* local_state = g_browser_process->local_state();
+ DCHECK(local_state);
Nikita (slow) 2013/07/11 09:13:54 nit: Drop this DCHECK.
Alexander Alekseev 2013/07/12 20:10:49 Done.
+
+ if (local_state == NULL)
Nikita (slow) 2013/07/11 09:13:54 nit: Drop this.
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ return;
+
+ chromeos::input_method::InputMethodManager* manager =
+ chromeos::input_method::InputMethodManager::Get();
+ DCHECK(manager);
Nikita (slow) 2013/07/11 09:13:54 nit: Drop this DCHECK.
Alexander Alekseev 2013/07/12 20:10:49 Done.
+
+ bool succeed = false;
+ do {
Nikita (slow) 2013/07/11 09:13:54 You should delete this loop it is not really neede
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ const base::DictionaryValue* users_lru_input_methods =
+ local_state->GetDictionary(prefs::kUsersLRUInputMethod);
+
+ if (users_lru_input_methods == NULL) {
+ DLOG(WARNING) << "SetUserInputMethod('" << username
Nikita (slow) 2013/07/11 09:13:54 nit: I guess it is perfectly normal situation till
Alexander Alekseev 2013/07/12 20:10:49 Do all our users always have some latin input meth
+ << "'): no kUsersLRUInputMethod";
+ break;
+ }
+
+ std::string input_method;
+
+ if (!users_lru_input_methods->GetStringWithoutPathExpansion(
+ username, &input_method)) {
+ DLOG(WARNING) << "SetUserInputMethod('" << username
Nikita (slow) 2013/07/11 09:13:54 nit: Same here. This looks like a perfectly normal
Alexander Alekseev 2013/07/12 20:10:49 But it's debug log, isn't it? I think I'd better h
+ << "'): no input method for this user";
+ break;
+ }
+
+ if (manager == NULL)
Nikita (slow) 2013/07/11 09:13:54 You don't have to check for manager not being NULL
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ break;
+
+ const chromeos::input_method::InputMethodUtil* ime_util =
+ manager->GetInputMethodUtil();
+ DCHECK(ime_util);
Nikita (slow) 2013/07/11 09:13:54 nit: Drop DCHECK
Alexander Alekseev 2013/07/12 20:10:49 Done.
+
+ if (ime_util == NULL)
Nikita (slow) 2013/07/11 09:13:54 Same here.
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ return;
+
+ if (input_method.empty())
+ break;
+
+ if (!manager->IsLanguageFullLatinKeyboard(
+ ime_util->GetLanguageCodeFromInputMethodId(input_method))) {
+ LOG(WARNING) << "SetUserInputMethod('" << username
Nikita (slow) 2013/07/11 09:13:54 nit: I propose dropping log message as well and ju
Alexander Alekseev 2013/07/12 20:10:49 It is probably dangerous to silently drop user pre
+ << "'): stored user LRU input method '" << input_method
+ << "' is no longer Full Latin Keyboard Language."
+ << " Use hardware default instead.";
+
+ break;
+ }
+
+ if (!Contains(chromeos::input_method::InputMethodManager::Get()
+ ->GetActiveInputMethodIds(),
Nikita (slow) 2013/07/11 09:13:54 nit: -> should be on the previous line
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ input_method)) {
+ if (!chromeos::input_method::InputMethodManager::Get()->EnableInputMethod(
Nikita (slow) 2013/07/11 09:13:54 nit: if (!chromeos::input_method::InputMethodMana
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ input_method)) {
+ DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username
+ << "'): user input method '" << input_method
+ << "' is not enabled and enabling failed (ignored!).";
+ }
+ }
+ chromeos::input_method::InputMethodManager::Get()->ChangeInputMethod(
Nikita (slow) 2013/07/11 09:13:54 nit: this looks more readable: chromeos::input_me
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ input_method);
+
+ succeed = true;
+ } while (false);
+
+ // This is also a case when LRU layout is set only for a few local users,
+ // thus others need to be switched to default locale.
+ // Otherwise they will end up using another user's locale to log in.
+ if (!succeed) {
+ DLOG(WARNING)
Nikita (slow) 2013/07/11 09:13:54 nit: No need for DLOG(WARNING), perfectly normal s
Alexander Alekseev 2013/07/12 20:10:49 But it's debug log. Let's leave traces of rare eve
+ << "SetUserInputMethod('" << username
+ << "'): failed to set user layout. Switching to default '"
+ << (manager != NULL
+ ? manager->GetInputMethodUtil()->GetHardwareInputMethodId()
+ : "NULL") << "'";
+
+ SetUserInputMethodHWDefault();
+ }
+#endif
+}
+
void SigninScreenHandler::ShowSigninScreenIfReady() {
if (!dns_cleared_ || !cookies_cleared_ || !delegate_)
return;
@@ -989,6 +1105,10 @@ void SigninScreenHandler::ShowSigninScreenIfReady() {
else
delegate_->LoadWallpaper(email_);
+ // Set Least Recently used input method for the user
Mattias Nissler (ping if slow) 2013/07/11 10:05:49 nit: missing period.
Alexander Alekseev 2013/07/12 20:10:49 Done.
+ if (!email_.empty())
+ SetUserInputMethod(email_);
+
LoadAuthExtension(!gaia_silent_load_, false, false);
UpdateUIState(UI_STATE_GAIA_SIGNIN, NULL);
@@ -1201,6 +1321,7 @@ void SigninScreenHandler::HandleShowAddUser(const base::ListValue* args) {
&SigninScreenHandler::ShowSigninScreenIfReady,
weak_factory_.GetWeakPtr()));
}
+ SetUserInputMethodHWDefault();
}
void SigninScreenHandler::HandleToggleEnrollmentScreen() {

Powered by Google App Engine
This is Rietveld 408576698