[go: nahoru, domu]

kiosk: Dismiss the "launch cancelled" toast after sign in

The "Kiosk application launch cancelled" toast is shown by the
kiosk_apps_menu_controller.cc in the lock screen after the user cancels
Kiosk launch. Currently the toast remains open until the user manually
clicks "dismiss". This leads to a dangling pointer once the lock screen
is destroyed.

This change makes sure the toast is dismissed when destroying the lock
screen.

Fixed: b:316344752
Test: testing/xvfb.py tools/autotest.py -C out/Default --run-all ash/login/login_screen_controller_unittest.cc
Change-Id: I674fb4b91713b3a94ea03c8a945aa60ead4425b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5150803
Reviewed-by: Toni Barzic <tbarzic@chromium.org>
Reviewed-by: Alex Newcomer <newcomer@chromium.org>
Commit-Queue: Edman Anjos <edman@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1242837}
diff --git a/ash/login/login_screen_controller.cc b/ash/login/login_screen_controller.cc
index 1e01577..f11ae46 100644
--- a/ash/login/login_screen_controller.cc
+++ b/ash/login/login_screen_controller.cc
@@ -41,6 +41,8 @@
 
 namespace {
 
+constexpr std::string_view kKioskToastId = "KioskAppError";
+
 enum class SystemTrayVisibility {
   kNone,     // Tray not visible anywhere.
   kPrimary,  // Tray visible only on primary display.
@@ -301,7 +303,8 @@
 }
 
 void LoginScreenController::ShowKioskAppError(const std::string& message) {
-  ToastData toast_data("KioskAppError", ToastCatalogName::kKioskAppError,
+  ToastData toast_data(std::string(kKioskToastId),
+                       ToastCatalogName::kKioskAppError,
                        base::UTF8ToUTF16(message), ToastData::kInfiniteDuration,
                        /*visible_on_lock_screen=*/true,
                        /*has_dismiss_button=*/true);
@@ -531,6 +534,9 @@
                  << authentication_stage_;
   }
 
+  // Dimiss the toast created by `ShowKioskAppError`, if any.
+  Shell::Get()->toast_manager()->Cancel(kKioskToastId);
+
   // Still handle it to avoid crashes during Login/Lock/Unlock flows.
   SetAuthenticationStage(AuthenticationStage::kIdle);
   SetSystemTrayVisibility(SystemTrayVisibility::kAll);