Skip to content

Commit

Permalink
cros: Do not show logout confirmation dialog in demo sessions
Browse files Browse the repository at this point in the history
In public sessions, a log-out confirmation is shown whenever all the
windows are closed. Demo mode is implemented as public session but this
particular behavior is not ideal for a smooth user experience.

Bug: 883498
Change-Id: I2bf8ccd27041dc4ffa864c5b2690749a62b4dbc5
Reviewed-on: https://chromium-review.googlesource.com/1228948
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591865}
  • Loading branch information
Wenzhao Zang authored and Commit Bot committed Sep 17, 2018
1 parent 2e8f430 commit 84c3b8e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ash/session/session_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ bool SessionController::IsRunningInAppMode() const {
return is_running_in_app_mode_;
}

bool SessionController::IsDemoSession() const {
return is_demo_session_;
}

bool SessionController::IsUserSessionBlocked() const {
// User sessions are blocked when session state is not ACTIVE, with two
// exceptions:
Expand Down
3 changes: 3 additions & 0 deletions ash/session/session_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class ASH_EXPORT SessionController : public mojom::SessionController {
// Returns true if the session is in a kiosk-like mode running a single app.
bool IsRunningInAppMode() const;

// Returns true if the current session is a demo session for Demo Mode.
bool IsDemoSession() const;

// Returns true if user session blocked by some overlying UI. It can be
// login screen, lock screen or screen for adding users into multi-profile
// session.
Expand Down
5 changes: 5 additions & 0 deletions ash/session/test_session_controller_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ void TestSessionControllerClient::SetIsRunningInAppMode(bool app_mode) {
controller_->SetSessionInfo(session_info_->Clone());
}

void TestSessionControllerClient::SetIsDemoSession() {
session_info_->is_demo_session = true;
controller_->SetSessionInfo(session_info_->Clone());
}

void TestSessionControllerClient::CreatePredefinedUserSessions(int count) {
DCHECK_GT(count, 0);

Expand Down
1 change: 1 addition & 0 deletions ash/session/test_session_controller_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TestSessionControllerClient : public ash::mojom::SessionControllerClient {
void SetAddUserSessionPolicy(AddUserSessionPolicy policy);
void SetSessionState(session_manager::SessionState state);
void SetIsRunningInAppMode(bool app_mode);
void SetIsDemoSession();

// Creates the |count| pre-defined user sessions. The users are named by
// numbers using "user%d@tray" template. The first user is set as active user
Expand Down
7 changes: 5 additions & 2 deletions ash/system/session/logout_confirmation_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class LogoutConfirmationController::LastWindowClosedObserver
LastWindowClosedObserver() {
DCHECK_EQ(Shell::Get()->session_controller()->login_status(),
LoginStatus::PUBLIC);
DCHECK(!Shell::Get()->session_controller()->IsDemoSession());
Shell::Get()->AddShellObserver(this);

// Observe all displays.
Expand Down Expand Up @@ -155,10 +156,12 @@ void LogoutConfirmationController::ConfirmLogout(base::TimeTicks logout_time) {

void LogoutConfirmationController::OnLoginStatusChanged(
LoginStatus login_status) {
if (login_status == LoginStatus::PUBLIC)
if (login_status == LoginStatus::PUBLIC &&
!Shell::Get()->session_controller()->IsDemoSession()) {
last_window_closed_observer_ = std::make_unique<LastWindowClosedObserver>();
else
} else {
last_window_closed_observer_.reset();
}
}

void LogoutConfirmationController::OnLockStateChanged(bool locked) {
Expand Down
26 changes: 25 additions & 1 deletion ash/system/session/logout_confirmation_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class LastWindowClosedTest : public NoSessionAshTestBase {
LastWindowClosedTest() = default;
~LastWindowClosedTest() override = default;

// Simulate a public account signing in.
// Simulate a public account (non-demo session) signing in.
void StartPublicAccountSession() {
TestSessionControllerClient* session = GetSessionControllerClient();
session->Reset();
Expand All @@ -172,6 +172,13 @@ class LastWindowClosedTest : public NoSessionAshTestBase {
session->SetSessionState(session_manager::SessionState::ACTIVE);
}

// Simulate a demo session signing in.
void StartDemoSession() {
GetSessionControllerClient()->SetIsDemoSession();
// Demo session is implemented as a public session.
StartPublicAccountSession();
}

private:
DISALLOW_COPY_AND_ASSIGN(LastWindowClosedTest);
};
Expand All @@ -194,6 +201,23 @@ TEST_F(LastWindowClosedTest, RegularSession) {
EXPECT_FALSE(controller->dialog_for_testing());
}

TEST_F(LastWindowClosedTest, DemoSession) {
// Dialog is not visible at startup.
LogoutConfirmationController* controller =
Shell::Get()->logout_confirmation_controller();
EXPECT_FALSE(controller->dialog_for_testing());

// Dialog is not visible after demo session starts.
StartDemoSession();
EXPECT_FALSE(controller->dialog_for_testing());

// Creating and closing a window does not show the dialog.
std::unique_ptr<aura::Window> window = CreateToplevelTestWindow();
EXPECT_FALSE(controller->dialog_for_testing());
window.reset();
EXPECT_FALSE(controller->dialog_for_testing());
}

TEST_F(LastWindowClosedTest, PublicSession) {
LogoutConfirmationController* controller =
Shell::Get()->logout_confirmation_controller();
Expand Down

0 comments on commit 84c3b8e

Please sign in to comment.