Skip to content

Commit

Permalink
Rename LRU Input Method to Last Input Method
Browse files Browse the repository at this point in the history
Change the naming of last input methods stored for users from LRU to
Last, because LRU is confusing in this context as it suggest that the
least recently used input method is stored.

BUG=697423
TEST=browser_tests --gtest_filter=LoginUIKeyboard*

Review-Url: https://codereview.chromium.org/2723083003
Cr-Commit-Position: refs/heads/master@{#454580}
  • Loading branch information
pmarko authored and Commit bot committed Mar 3, 2017
1 parent cec4510 commit 90fcce7
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 64 deletions.
53 changes: 27 additions & 26 deletions chrome/browser/chromeos/input_method/input_method_persistence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,44 @@ void PersistSystemInputMethod(const std::string& input_method) {
language_prefs::kPreferredKeyboardLayout, input_method);
}

static void SetUserLRUInputMethodPreference(const std::string& username,
const std::string& input_method,
PrefService* local_state) {
static void SetUserLastInputMethodPreference(const std::string& username,
const std::string& input_method,
PrefService* local_state) {
if (!username.empty() && !local_state->ReadOnly()) {
bool update_succeed = false;
{
// Updater may have side-effects, therefore we do not replace
// entry while updater exists.
DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod);
base::DictionaryValue* const users_lru_input_methods = updater.Get();
if (users_lru_input_methods) {
users_lru_input_methods->SetStringWithoutPathExpansion(username,
input_method);
DictionaryPrefUpdate updater(local_state, prefs::kUsersLastInputMethod);
base::DictionaryValue* const users_last_input_methods = updater.Get();
if (users_last_input_methods) {
users_last_input_methods->SetStringWithoutPathExpansion(username,
input_method);
update_succeed = true;
}
}
if (!update_succeed) {
// Somehow key kUsersLRUInputMethod has value of invalid type.
// Somehow key kUsersLastInputMethod has value of invalid type.
// Replace and retry.
local_state->Set(prefs::kUsersLRUInputMethod, base::DictionaryValue());
local_state->Set(prefs::kUsersLastInputMethod, base::DictionaryValue());

DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod);
base::DictionaryValue* const users_lru_input_methods = updater.Get();
if (users_lru_input_methods) {
users_lru_input_methods->SetStringWithoutPathExpansion(username,
input_method);
DictionaryPrefUpdate updater(local_state, prefs::kUsersLastInputMethod);
base::DictionaryValue* const users_last_input_methods = updater.Get();
if (users_last_input_methods) {
users_last_input_methods->SetStringWithoutPathExpansion(username,
input_method);
update_succeed = true;
}
}
if (!update_succeed) {
DVLOG(1) << "Failed to replace local_state.kUsersLRUInputMethod: '"
<< prefs::kUsersLRUInputMethod << "' for '" << username << "'";
DVLOG(1) << "Failed to replace local_state.kUsersLastInputMethod: '"
<< prefs::kUsersLastInputMethod << "' for '" << username << "'";
}
}
}

// Update user LRU keyboard layout for login screen
static void SetUserLRUInputMethod(
// Update user Last keyboard layout for login screen
static void SetUserLastInputMethod(
const std::string& input_method,
const chromeos::input_method::InputMethodManager* const manager,
Profile* profile) {
Expand All @@ -78,8 +78,8 @@ static void SetUserLRUInputMethod(

PrefService* const local_state = g_browser_process->local_state();

SetUserLRUInputMethodPreference(
profile->GetProfileUserName(), input_method, local_state);
SetUserLastInputMethodPreference(profile->GetProfileUserName(), input_method,
local_state);
}

void PersistUserInputMethod(const std::string& input_method,
Expand All @@ -93,7 +93,7 @@ void PersistUserInputMethod(const std::string& input_method,
user_prefs = profile->GetPrefs();
if (!user_prefs)
return;
SetUserLRUInputMethod(input_method, manager, profile);
SetUserLastInputMethod(input_method, manager, profile);

const std::string current_input_method_on_pref =
user_prefs->GetString(prefs::kLanguageCurrentInputMethod);
Expand Down Expand Up @@ -153,10 +153,11 @@ void InputMethodPersistence::OnSessionStateChange(
ui_session_ = new_ui_session;
}

void SetUserLRUInputMethodPreferenceForTesting(const std::string& username,
const std::string& input_method,
PrefService* const local_state) {
SetUserLRUInputMethodPreference(username, input_method, local_state);
void SetUserLastInputMethodPreferenceForTesting(
const std::string& username,
const std::string& input_method,
PrefService* const local_state) {
SetUserLastInputMethodPreference(username, input_method, local_state);
}

} // namespace input_method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class InputMethodPersistence : public InputMethodManager::Observer {
DISALLOW_COPY_AND_ASSIGN(InputMethodPersistence);
};

void SetUserLRUInputMethodPreferenceForTesting(const std::string& username,
const std::string& input_method,
PrefService* local_state);
void SetUserLastInputMethodPreferenceForTesting(const std::string& username,
const std::string& input_method,
PrefService* local_state);

} // namespace input_method
} // namespace chromeos
Expand Down
18 changes: 9 additions & 9 deletions chrome/browser/chromeos/login/login_ui_keyboard_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ class LoginUIKeyboardTest : public chromeos::LoginManagerTest {

// Should be called from PRE_ test so that local_state is saved to disk, and
// reloaded in the main test.
void InitUserLRUInputMethod() {
void InitUserLastInputMethod() {
PrefService* local_state = g_browser_process->local_state();

input_method::SetUserLRUInputMethodPreferenceForTesting(
input_method::SetUserLastInputMethodPreferenceForTesting(
kTestUser1, user_input_methods[0], local_state);
input_method::SetUserLRUInputMethodPreferenceForTesting(
input_method::SetUserLastInputMethodPreferenceForTesting(
kTestUser2, user_input_methods[1], local_state);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTest, PRE_CheckPODScreenWithUsers) {
RegisterUser(kTestUser1);
RegisterUser(kTestUser2);

InitUserLRUInputMethod();
InitUserLastInputMethod();

StartupUtils::MarkOobeCompleted();
}
Expand Down Expand Up @@ -204,14 +204,14 @@ class LoginUIKeyboardTestWithUsersAndOwner : public chromeos::LoginManagerTest {

// Should be called from PRE_ test so that local_state is saved to disk, and
// reloaded in the main test.
void InitUserLRUInputMethod() {
void InitUserLastInputMethod() {
PrefService* local_state = g_browser_process->local_state();

input_method::SetUserLRUInputMethodPreferenceForTesting(
input_method::SetUserLastInputMethodPreferenceForTesting(
kTestUser1, user_input_methods[0], local_state);
input_method::SetUserLRUInputMethodPreferenceForTesting(
input_method::SetUserLastInputMethodPreferenceForTesting(
kTestUser2, user_input_methods[1], local_state);
input_method::SetUserLRUInputMethodPreferenceForTesting(
input_method::SetUserLastInputMethodPreferenceForTesting(
kTestUser3, user_input_methods[2], local_state);

local_state->SetString(language_prefs::kPreferredKeyboardLayout,
Expand Down Expand Up @@ -243,7 +243,7 @@ IN_PROC_BROWSER_TEST_F(LoginUIKeyboardTestWithUsersAndOwner,
RegisterUser(kTestUser2);
RegisterUser(kTestUser3);

InitUserLRUInputMethod();
InitUserLastInputMethod();

StartupUtils::MarkOobeCompleted();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ void GaiaScreenHandler::ShowGaiaScreenIfReady() {
} else {
std::vector<std::string> input_methods =
imm->GetInputMethodUtil()->GetHardwareLoginInputMethodIds();
const std::string owner_im = SigninScreenHandler::GetUserLRUInputMethod(
const std::string owner_im = SigninScreenHandler::GetUserLastInputMethod(
user_manager::UserManager::Get()->GetOwnerAccountId().GetUserEmail());
const std::string system_im = g_browser_process->local_state()->GetString(
language_prefs::kPreferredKeyboardLayout);
Expand Down
36 changes: 18 additions & 18 deletions chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,16 @@ static bool SetUserInputMethodImpl(
if (!chromeos::input_method::InputMethodManager::Get()->IsLoginKeyboard(
user_input_method)) {
LOG(WARNING) << "SetUserInputMethod('" << username
<< "'): stored user LRU input method '" << user_input_method
<< "'): stored user last input method '" << user_input_method
<< "' is no longer Full Latin Keyboard Language"
<< " (entry dropped). Use hardware default instead.";

PrefService* const local_state = g_browser_process->local_state();
DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod);
DictionaryPrefUpdate updater(local_state, prefs::kUsersLastInputMethod);

base::DictionaryValue* const users_lru_input_methods = updater.Get();
if (users_lru_input_methods != nullptr) {
users_lru_input_methods->SetStringWithoutPathExpansion(username, "");
base::DictionaryValue* const users_last_input_methods = updater.Get();
if (users_last_input_methods != nullptr) {
users_last_input_methods->SetStringWithoutPathExpansion(username, "");
}
return false;
}
Expand Down Expand Up @@ -363,23 +363,23 @@ SigninScreenHandler::~SigninScreenHandler() {
}

// static
std::string SigninScreenHandler::GetUserLRUInputMethod(
std::string SigninScreenHandler::GetUserLastInputMethod(
const std::string& username) {
PrefService* const local_state = g_browser_process->local_state();
const base::DictionaryValue* users_lru_input_methods =
local_state->GetDictionary(prefs::kUsersLRUInputMethod);
const base::DictionaryValue* users_last_input_methods =
local_state->GetDictionary(prefs::kUsersLastInputMethod);

if (!users_lru_input_methods) {
DLOG(WARNING) << "GetUserLRUInputMethod('" << username
<< "'): no kUsersLRUInputMethod";
if (!users_last_input_methods) {
DLOG(WARNING) << "GetUserLastInputMethod('" << username
<< "'): no kUsersLastInputMethod";
return std::string();
}

std::string input_method;

if (!users_lru_input_methods->GetStringWithoutPathExpansion(username,
&input_method)) {
DVLOG(0) << "GetUserLRUInputMethod('" << username
if (!users_last_input_methods->GetStringWithoutPathExpansion(username,
&input_method)) {
DVLOG(0) << "GetUserLastInputMethod('" << username
<< "'): no input method for this user";
return std::string();
}
Expand All @@ -394,14 +394,14 @@ void SigninScreenHandler::SetUserInputMethod(
input_method::InputMethodManager::State* ime_state) {
bool succeed = false;

const std::string input_method = GetUserLRUInputMethod(username);
const std::string input_method = GetUserLastInputMethod(username);

EnforcePolicyInputMethods(input_method);

if (!input_method.empty())
succeed = SetUserInputMethodImpl(username, input_method, ime_state);

// This is also a case when LRU layout is set only for a few local users,
// This is also a case when last 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) {
Expand Down Expand Up @@ -982,7 +982,7 @@ gfx::NativeWindow SigninScreenHandler::GetNativeWindow() {
}

void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod);
registry->RegisterDictionaryPref(prefs::kUsersLastInputMethod);
}

void SigninScreenHandler::OnCurrentScreenChanged(OobeScreen current_screen,
Expand Down Expand Up @@ -1619,7 +1619,7 @@ void SigninScreenHandler::OnFeedbackFinished() {
void SigninScreenHandler::OnAllowedInputMethodsChanged() {
if (focused_pod_account_id_) {
std::string user_input_method =
GetUserLRUInputMethod(focused_pod_account_id_->GetUserEmail());
GetUserLastInputMethod(focused_pod_account_id_->GetUserEmail());
EnforcePolicyInputMethods(user_input_method);
} else {
EnforcePolicyInputMethods(std::string());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ class SigninScreenHandler
JSCallsContainer* js_calls_container);
~SigninScreenHandler() override;

static std::string GetUserLRUInputMethod(const std::string& username);
static std::string GetUserLastInputMethod(const std::string& username);

// Update current input method (namely keyboard layout) in the given IME state
// to LRU by this user.
// to last input method used by this user.
static void SetUserInputMethod(
const std::string& username,
input_method::InputMethodManager::State* ime_state);
Expand Down
7 changes: 4 additions & 3 deletions chrome/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1871,9 +1871,10 @@ const char kDeviceDMToken[] = "device_dm_token";
// How many times HID detection OOBE dialog was shown.
const char kTimesHIDDialogShown[] = "HIDDialog.shown_how_many_times";

// Dictionary of per-user Least Recently Used input method (used at login
// screen).
const char kUsersLRUInputMethod[] = "UsersLRUInputMethod";
// Dictionary of per-user last input method (used at login screen). Note that
// the pref name is UsersLRUInputMethods for compatibility with previous
// versions.
const char kUsersLastInputMethod[] = "UsersLRUInputMethod";

// A dictionary pref of the echo offer check flag. It sets offer info when
// an offer is checked.
Expand Down
2 changes: 1 addition & 1 deletion chrome/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ extern const char kDeviceEnrollmentAutoStart[];
extern const char kDeviceEnrollmentCanExit[];
extern const char kDeviceDMToken[];
extern const char kTimesHIDDialogShown[];
extern const char kUsersLRUInputMethod[];
extern const char kUsersLastInputMethod[];
extern const char kEchoCheckedOffers[];
extern const char kCachedMultiProfileUserBehavior[];
extern const char kInitialLocale[];
Expand Down
2 changes: 1 addition & 1 deletion components/policy/resources/policy_templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -9596,7 +9596,7 @@
'tags': [],
'desc': '''Configures which keyboard layouts are allowed on the <ph name="PRODUCT_OS_NAME">$2<ex>Google Chrome OS</ex></ph> sign-in screen.

If this policy is set to a list of input method identifiers, the given input methods will be available on the sign-in screen. The first given input method will be preselected. While a user pod is focused on the sign-in screen, the user's least recently used input method will be available in addition to the input methods given by this policy. If this policy is not set, the input methods on the sign-in screen will be derived from the locale in which the sign-in screen is displayed. Values which are not valid input method identifiers will be ignored.''',
If this policy is set to a list of input method identifiers, the given input methods will be available on the sign-in screen. The first given input method will be preselected. While a user pod is focused on the sign-in screen, the user's last used input method will be available in addition to the input methods given by this policy. If this policy is not set, the input methods on the sign-in screen will be derived from the locale in which the sign-in screen is displayed. Values which are not valid input method identifiers will be ignored.''',
},
],
'messages': {
Expand Down

0 comments on commit 90fcce7

Please sign in to comment.