Commit f05ad0af authored by khmel@google.com's avatar khmel@google.com Committed by Commit Bot

Fix wrong triggering Logout timer.

This fixes the issue when ARC++ window goes in/out full-screen or
minimized/restored. In this case a window is removed deep inside
the top ARC++ window and this triggers the wrong logout time
activation.
On removing l
This CL checks removing window that belongs to tracked top windows and
ignored hierarchy change events for other child windows.

Test: Manually + unit test
Bug: b/79169326
Change-Id: I825dd9d16d32ce305d43003fb2e77194cfc5ca7c
Reviewed-on: https://chromium-review.googlesource.com/1045827
Commit-Queue: Yury Khmel <khmel@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#559155}
parent 15a00d63
......@@ -71,20 +71,29 @@ class LogoutConfirmationController::LastWindowClosedObserver
// Shows the logout confirmation dialog if the last window is closing in the
// containers we are tracking. Called before closing instead of after closed
// because aura::WindowObserver only provides notifications to parent windows
// before a child is removed, not after.
void ShowDialogIfLastWindowClosing() {
size_t window_count = 0u;
// before a child is removed, not after. Note that removing window deep inside
// tracked container also causes OnWindowHierarchyChanging calls so we check
// here that removing window is the last window with parent of a tracked
// container.
void ShowDialogIfLastWindowClosing(const aura::Window* closing_window) {
// Enumerate all root windows.
for (aura::Window* root : Shell::GetAllRootWindows()) {
for (int id : kLastWindowClosedContainerIds)
window_count += root->GetChildById(id)->children().size();
// For each root window enumerate tracked containers.
for (int id : kLastWindowClosedContainerIds) {
// In each container try to find child window that is not equal to
// |closing_window| which would indicate that we have other top-level
// window and logout time does not apply.
for (const aura::Window* window : root->GetChildById(id)->children()) {
if (window != closing_window)
return;
}
}
}
// Prompt if the last window is closing.
if (window_count == 1) {
Shell::Get()->logout_confirmation_controller()->ConfirmLogout(
base::TimeTicks::Now() +
base::TimeDelta::FromSeconds(kLogoutConfirmationDelayInSeconds));
}
// No more windows except currently removing. Show logout time.
Shell::Get()->logout_confirmation_controller()->ConfirmLogout(
base::TimeTicks::Now() +
base::TimeDelta::FromSeconds(kLogoutConfirmationDelayInSeconds));
}
// ShellObserver:
......@@ -96,7 +105,7 @@ class LogoutConfirmationController::LastWindowClosedObserver
void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override {
if (!params.new_parent && params.old_parent) {
// A window is being removed (and not moved to another container).
ShowDialogIfLastWindowClosing();
ShowDialogIfLastWindowClosing(params.target);
}
}
......
......@@ -214,6 +214,30 @@ TEST_F(LastWindowClosedTest, PublicSession) {
EXPECT_TRUE(controller->dialog_for_testing());
}
// Test ARC++ window hierarchy where window minimize, restore and go in/out full
// screen causes a window removing deep inside the top window hierarchy. Actions
// above should no cause logout timer and only closing the last top window
// triggers the logout timer.
TEST_F(LastWindowClosedTest, PublicSessionComplexHierarchy) {
LogoutConfirmationController* controller =
Shell::Get()->logout_confirmation_controller();
StartPublicAccountSession();
EXPECT_FALSE(controller->dialog_for_testing());
std::unique_ptr<aura::Window> window = CreateToplevelTestWindow();
EXPECT_FALSE(controller->dialog_for_testing());
std::unique_ptr<aura::Window> window_child = CreateChildWindow(window.get());
EXPECT_FALSE(controller->dialog_for_testing());
window_child.reset();
EXPECT_FALSE(controller->dialog_for_testing());
window.reset();
EXPECT_TRUE(controller->dialog_for_testing());
}
TEST_F(LastWindowClosedTest, AlwaysOnTop) {
LogoutConfirmationController* controller =
Shell::Get()->logout_confirmation_controller();
......
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