Commit b7c2ea2a authored by Quan Nguyen's avatar Quan Nguyen Committed by Commit Bot

cros: Display kiosk app launch errors as a toast in login screen

This CL adds a button to the login-dev-overlay to pop up a fake kiosk
error message.

We also update the ToastManager to allow showing toasts on the Login
screen (which also uses LockSystemModalContainer). This involves
consolidating the toast requeueing logic into OnSessionStateChanged.

Bug: 879117
Change-Id: I557f0444a2368d1bf460d5db0a41f893ce0e69ea
Reviewed-on: https://chromium-review.googlesource.com/1211969Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Commit-Queue: Quan Nguyen <qnnguyen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589968}
parent 687bee3c
......@@ -17,6 +17,8 @@
#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_delegate.h"
#include "ash/system/toast/toast_data.h"
#include "ash/system/toast/toast_manager.h"
#include "base/debug/alias.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
......@@ -418,6 +420,14 @@ void LoginScreenController::SetKioskApps(
->SetKioskApps(std::move(kiosk_apps));
}
void LoginScreenController::ShowKioskAppError(const std::string& message) {
ToastData toast_data(
"KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
base::Optional<base::string16>(base::string16()) /*dismiss_text*/,
true /*visible_on_lock_screen*/);
Shell::Get()->toast_manager()->Show(toast_data);
}
void LoginScreenController::NotifyOobeDialogState(
mojom::OobeDialogState state) {
for (auto& observer : observers_)
......
......@@ -142,6 +142,7 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen {
void SetFingerprintUnlockState(const AccountId& account_id,
mojom::FingerprintUnlockState state) override;
void SetKioskApps(std::vector<mojom::KioskAppInfoPtr> kiosk_apps) override;
void ShowKioskAppError(const std::string& message) override;
void NotifyOobeDialogState(mojom::OobeDialogState state) override;
void SetAddUserButtonEnabled(bool enable) override;
void SetAllowLoginAsGuest(bool allow_guest) override;
......
......@@ -48,6 +48,7 @@ enum {
kGlobalToggleAuth,
kGlobalAddKioskApp,
kGlobalRemoveKioskApp,
kGlobalShowKioskError,
kGlobalToggleDebugDetachableBase,
kGlobalCycleDetachableBaseStatus,
kGlobalCycleDetachableBaseId,
......@@ -691,6 +692,8 @@ LockDebugView::LockDebugView(mojom::TrayActionState initial_note_action_state,
AddButton("Add kiosk app", ButtonId::kGlobalAddKioskApp, kiosk_container);
AddButton("Remove kiosk app", ButtonId::kGlobalRemoveKioskApp,
kiosk_container);
AddButton("Show kiosk error", ButtonId::kGlobalShowKioskError,
kiosk_container);
global_action_detachable_base_group_ = add_horizontal_container();
UpdateDetachableBaseColumn();
......@@ -881,6 +884,11 @@ void LockDebugView::ButtonPressed(views::Button* sender,
Shelf::ForWindow(GetWidget()->GetNativeWindow())->shelf_widget());
}
if (sender->id() == ButtonId::kGlobalShowKioskError) {
Shell::Get()->login_screen_controller()->ShowKioskAppError(
"Test error message.");
}
if (sender->id() == ButtonId::kGlobalToggleDebugDetachableBase) {
if (debug_detachable_base_model_->debugging_pairing_state()) {
debug_detachable_base_model_->ClearDebugPairingState();
......
......@@ -175,6 +175,9 @@ interface LoginScreen {
// Update the kiosk app data for the login screen.
SetKioskApps(array<KioskAppInfo> kiosk_apps);
// Display a toast describing the latest kiosk app launch error.
ShowKioskAppError(string message);
// Called when the dialog hosting oobe has changed state. The oobe dialog
// provides support for any part of login that is implemented in JS/HTML, such
// as add user or powerwash.
......
......@@ -113,10 +113,7 @@ void ToastManager::OnDurationPassed(int toast_number) {
}
void ToastManager::OnSessionStateChanged(session_manager::SessionState state) {
// Note that this method is called before the lock state is changed and
// OnLockStateChanged is called.
const bool locked = state == session_manager::SessionState::LOCKED;
const bool locked = state != session_manager::SessionState::ACTIVE;
if ((locked != locked_) && current_toast_data_) {
// Re-queue the currently visible toast which is not for lock screen.
......@@ -125,18 +122,10 @@ void ToastManager::OnSessionStateChanged(session_manager::SessionState state) {
// Hide the currently visible toast without any animation.
overlay_.reset();
}
}
void ToastManager::OnLockStateChanged(bool locked) {
if (locked_ == locked)
return;
locked_ = locked;
DCHECK(!overlay_);
if (!overlay_ && !queue_.empty()) {
// Try to (re-)show a queued toast, which may be the queued one in
// OnSessionStateChanged..
if (!queue_.empty()) {
// Try to reshow a queued toast from a previous OnSessionStateChanged.
ShowLatest();
}
}
......
......@@ -35,7 +35,6 @@ class ASH_EXPORT ToastManager : public ToastOverlay::Delegate,
// SessionObserver:
void OnSessionStateChanged(session_manager::SessionState state) override;
void OnLockStateChanged(bool locked) override;
private:
friend class ToastManagerTest;
......
......@@ -40,6 +40,9 @@ class ToastManagerTest : public AshTestBase {
manager_->ResetSerialForTesting();
EXPECT_EQ(0, GetToastSerial());
// Start in the ACTIVE (logged-in) state.
ChangeLockState(false);
}
protected:
......@@ -106,7 +109,7 @@ class ToastManagerTest : public AshTestBase {
void ChangeLockState(bool lock) {
mojom::SessionInfoPtr info_ptr = mojom::SessionInfo::New();
info_ptr->state = lock ? session_manager::SessionState::LOCKED
: session_manager::SessionState::LOGIN_PRIMARY;
: session_manager::SessionState::ACTIVE;
Shell::Get()->session_controller()->SetSessionInfo(std::move(info_ptr));
}
......
......@@ -355,6 +355,10 @@ void AppLaunchController::CleanUp() {
splash_wait_timer_.Stop();
host_->Finalize(base::OnceClosure());
// Make sure that any kiosk launch errors get written to disk before we kill
// the browser.
g_browser_process->local_state()->CommitPendingWrite();
}
void AppLaunchController::OnNetworkWaitTimedout() {
......
......@@ -84,8 +84,15 @@ void KioskAppMenuUpdater::SendKioskApps() {
LoginScreenClient::Get()->login_screen()->SetKioskApps(std::move(output));
KioskAppLaunchError::Error error = KioskAppLaunchError::Get();
if (error == KioskAppLaunchError::NONE)
return;
// Clear any old pending Kiosk launch errors
KioskAppLaunchError::RecordMetricAndClear();
LoginScreenClient::Get()->login_screen()->ShowKioskAppError(
KioskAppLaunchError::GetErrorMessage(error));
}
} // namespace chromeos
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