Commit 44f5e9c2 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[VK] Change to INITIAL state when keyboard is being disabled.

Currently, when we disable the keyboard, we directly reset the state
back to UNKNOWN without logging or validation. This means that in the
UMA metrics for state transitions, the transitions going into a state
does not add up to the transitions going out of a state.

This patch explicitly changes the state back to INITIAL when the
keyboard is disabled. When the keyboard is about to be disabled,
the only valid states are INITIAL, LOADING and HIDDEN. We don't
change if the current state is INITIAL to avoid self-transitions.

Bug: 775354
Change-Id: Idab146e017d179a9086808481f3ed65b6f0dfbcf
Reviewed-on: https://chromium-review.googlesource.com/1163346Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580815}
parent c415acc1
......@@ -305,3 +305,17 @@ IN_PROC_BROWSER_TEST_F(VirtualKeyboardStateTest, OpenAndCloseAndOpen) {
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::SHOWN);
}
// See crbug.com/755354.
IN_PROC_BROWSER_TEST_F(VirtualKeyboardStateTest,
DisablingKeyboardGoesToInitialState) {
auto* controller = keyboard::KeyboardController::Get();
controller->LoadKeyboardWindowInBackground();
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::LOADING_EXTENSION);
controller->DisableKeyboard();
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::INITIAL);
}
......@@ -96,6 +96,12 @@ bool isAllowedStateTransition(keyboard::KeyboardControllerState from,
// HideKeyboard can be called at anytime for example on shutdown.
{keyboard::KeyboardControllerState::SHOWN,
keyboard::KeyboardControllerState::HIDDEN},
// Return to INITIAL when keyboard is disabled.
{keyboard::KeyboardControllerState::LOADING_EXTENSION,
keyboard::KeyboardControllerState::INITIAL},
{keyboard::KeyboardControllerState::HIDDEN,
keyboard::KeyboardControllerState::INITIAL},
};
return kAllowedStateTransition.count(std::make_pair(from, to)) == 1;
};
......@@ -204,6 +210,11 @@ void KeyboardController::DisableKeyboard() {
if (parent_container_)
DeactivateKeyboard();
// Return to the INITIAL state to ensure that transitions entering a state
// is equal to transitions leaving the state.
if (state_ != KeyboardControllerState::INITIAL)
ChangeState(KeyboardControllerState::INITIAL);
// TODO(https://crbug.com/731537): Move KeyboardController members into a
// subobject so we can just put this code into the subobject destructor.
queued_display_change_.reset();
......
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