Commit c258ab08 authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

login: Store last login input method in the profile prefs.

This CL is a quick-fix for the ephemeral use-case. known_user does not
persist the data for the ephemeral user. As a result on the lock screen
users can't get their last login input method.

Change-Id: I0722c741906ecfd35cb031ca6db337c3302e1b3d
Bug: 1092884
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2429067
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Auto-Submit: Roman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810481}
parent 43b32e77
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/language_preferences.h" #include "chrome/browser/chromeos/language_preferences.h"
#include "chrome/browser/chromeos/login/lock/screen_locker.h" #include "chrome/browser/chromeos/login/lock/screen_locker.h"
#include "chrome/browser/chromeos/login/login_pref_names.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
...@@ -60,6 +61,9 @@ static void SetUserLastInputMethod( ...@@ -60,6 +61,9 @@ static void SetUserLastInputMethod(
if (profile == NULL) if (profile == NULL)
return; return;
// TODO(https://crbug.com/1121565): Create more general fix for all the data
// that is required on the lock screen.
profile->GetPrefs()->SetString(prefs::kLastLoginInputMethod, input_method);
SetUserLastInputMethodPreference(GetUserAccount(profile), input_method); SetUserLastInputMethodPreference(GetUserAccount(profile), input_method);
} }
...@@ -77,14 +81,13 @@ void PersistUserInputMethod(const std::string& input_method, ...@@ -77,14 +81,13 @@ void PersistUserInputMethod(const std::string& input_method,
SetUserLastInputMethod(input_method, manager, profile); SetUserLastInputMethod(input_method, manager, profile);
const std::string current_input_method_on_pref = const std::string current_input_method_on_pref =
user_prefs->GetString(prefs::kLanguageCurrentInputMethod); user_prefs->GetString(::prefs::kLanguageCurrentInputMethod);
if (current_input_method_on_pref == input_method) if (current_input_method_on_pref == input_method)
return; return;
user_prefs->SetString(prefs::kLanguagePreviousInputMethod, user_prefs->SetString(::prefs::kLanguagePreviousInputMethod,
current_input_method_on_pref); current_input_method_on_pref);
user_prefs->SetString(prefs::kLanguageCurrentInputMethod, user_prefs->SetString(::prefs::kLanguageCurrentInputMethod, input_method);
input_method);
} }
} // namespace } // namespace
......
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
#include "ash/public/cpp/ash_constants.h" #include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/ash_pref_names.h" #include "ash/public/cpp/ash_pref_names.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/login_pref_names.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/ime_controller_client.h" #include "chrome/browser/ui/ash/ime_controller_client.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
...@@ -80,10 +83,20 @@ std::string GetUserLastInputMethod(const AccountId& account_id) { ...@@ -80,10 +83,20 @@ std::string GetUserLastInputMethod(const AccountId& account_id) {
return input_method; return input_method;
} }
// Try profile prefs. For the ephemeral case known_user does not persist the
// data.
Profile* profile =
chromeos::ProfileHelper::Get()->GetProfileByAccountId(account_id);
if (profile && profile->GetPrefs()) {
input_method = profile->GetPrefs()->GetString(prefs::kLastLoginInputMethod);
if (!input_method.empty())
return input_method;
}
// Try to use old values. // Try to use old values.
PrefService* const local_state = g_browser_process->local_state(); PrefService* const local_state = g_browser_process->local_state();
const base::DictionaryValue* users_last_input_methods = const base::DictionaryValue* users_last_input_methods =
local_state->GetDictionary(prefs::kUsersLastInputMethod); local_state->GetDictionary(::prefs::kUsersLastInputMethod);
if (!users_last_input_methods) { if (!users_last_input_methods) {
DLOG(WARNING) << "GetUserLastInputMethod: no kUsersLastInputMethod"; DLOG(WARNING) << "GetUserLastInputMethod: no kUsersLastInputMethod";
......
...@@ -12,6 +12,9 @@ namespace prefs { ...@@ -12,6 +12,9 @@ namespace prefs {
// These are attached to the user profile. Here only login/oobe specific prefs // These are attached to the user profile. Here only login/oobe specific prefs
// are presented. // are presented.
// Last input user method which could be used on the login/lock screens.
const char kLastLoginInputMethod[] = "login.last_input_method";
// Time when new user has finished onboarding. // Time when new user has finished onboarding.
const char kOobeOnboardingTime[] = "oobe.onboarding_time"; const char kOobeOnboardingTime[] = "oobe.onboarding_time";
......
...@@ -9,6 +9,7 @@ namespace chromeos { ...@@ -9,6 +9,7 @@ namespace chromeos {
namespace prefs { namespace prefs {
extern const char kLastLoginInputMethod[];
extern const char kOobeOnboardingTime[]; extern const char kOobeOnboardingTime[];
extern const char kSAMLOfflineSigninTimeLimit[]; extern const char kSAMLOfflineSigninTimeLimit[];
extern const char kSAMLLastGAIASignInTime[]; extern const char kSAMLLastGAIASignInTime[];
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
#include "chromeos/login/auth/user_context.h" #include "chromeos/login/auth/user_context.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/user_manager/known_user.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
...@@ -473,4 +474,41 @@ IN_PROC_BROWSER_TEST_F(FirstLoginKeyboardTest, ...@@ -473,4 +474,41 @@ IN_PROC_BROWSER_TEST_F(FirstLoginKeyboardTest,
EXPECT_FALSE(lock_screen_utils::GetUserLastInputMethod(test_user_).empty()); EXPECT_FALSE(lock_screen_utils::GetUserLastInputMethod(test_user_).empty());
} }
class EphemeralUserKeyboardTest : public LoginManagerTest {
protected:
// LoginManagerTest:
void SetUpInProcessBrowserTestFixture() override {
std::unique_ptr<ScopedDevicePolicyUpdate> update =
device_state_.RequestDevicePolicyUpdate();
update->policy_payload()
->mutable_ephemeral_users_enabled()
->set_ephemeral_users_enabled(true);
update.reset();
LoginManagerTest::SetUpInProcessBrowserTestFixture();
}
LoginManagerMixin login_manager_{&mixin_host_};
DeviceStateMixin device_state_{
&mixin_host_, DeviceStateMixin::State::OOBE_COMPLETED_CLOUD_ENROLLED};
};
// Check that ephemeral users have last input method set.
IN_PROC_BROWSER_TEST_F(EphemeralUserKeyboardTest, PersistToProfile) {
WizardController::SkipPostLoginScreensForTesting();
login_manager_.LoginAsNewRegularUser();
login_manager_.WaitForActiveSession();
const AccountId& account_id =
user_manager::UserManager::Get()->GetActiveUser()->GetAccountId();
// Should be empty because known_user does not persist data for ephemeral
// users.
EXPECT_FALSE(
user_manager::known_user::GetUserLastInputMethod(account_id, nullptr));
std::vector<std::string> expected_input_method;
Append_en_US_InputMethod(&expected_input_method);
EXPECT_EQ(lock_screen_utils::GetUserLastInputMethod(account_id),
expected_input_method[0]);
}
} // namespace chromeos } // namespace chromeos
...@@ -439,6 +439,9 @@ void Preferences::RegisterProfilePrefs( ...@@ -439,6 +439,9 @@ void Preferences::RegisterProfilePrefs(
false); false);
// OOBE and login related prefs. // OOBE and login related prefs.
registry->RegisterStringPref(chromeos::prefs::kLastLoginInputMethod,
std::string(),
PrefRegistry::NO_REGISTRATION_FLAGS);
registry->RegisterTimePref(chromeos::prefs::kOobeOnboardingTime, registry->RegisterTimePref(chromeos::prefs::kOobeOnboardingTime,
base::Time()); base::Time());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment