Commit 3e698a6b authored by Karthikeyan Ramasubramanian's avatar Karthikeyan Ramasubramanian Committed by Commit Bot

Generate shutdown confirmation dialog

When the system firmware update includes MRC training update, it can
cause the system to boot slower after the update is applied. Currently a
user notification is generated regarding the slow boot. This CL
generates an additional shutdown confirmation dialog to the user
highlighting the same. Here is the screenshot capturing the confirmation
dialog:
https://screenshot.googleplex.com/8przUKEDrRz
Pressing "Continue" button in the screenshot will continue with the
restart. Pressing "Do it later" button will cancel the restart. Also
added a test case to UpdateNotificationControllerTest to verify the
same. Ensured that all the tests in that test suite ran successfully.

Bug: b/129056373
Change-Id: Iba3b53dffad9216e1e18a94fc80328d2cbdae4fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2001740
Commit-Queue: Karthikeyan Ramasubramanian <kramasub@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarJenny Zhang <jennyz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736678}
parent 4fd622f4
...@@ -426,6 +426,12 @@ This file contains the strings for ash. ...@@ -426,6 +426,12 @@ This file contains the strings for ash.
<message name="IDS_UPDATE_NOTIFICATION_MESSAGE_SLOW_BOOT" desc="The additional body of the notification to notify the user that the next reboot is slow."> <message name="IDS_UPDATE_NOTIFICATION_MESSAGE_SLOW_BOOT" desc="The additional body of the notification to notify the user that the next reboot is slow.">
<ph name="UPDATE_TEXT">$1<ex>Learn more about the latest Chromium OS update</ex></ph>. This Chromebook needs to restart to apply an update. This can take up to 1 minute. <ph name="UPDATE_TEXT">$1<ex>Learn more about the latest Chromium OS update</ex></ph>. This Chromebook needs to restart to apply an update. This can take up to 1 minute.
</message> </message>
<message name="IDS_DIALOG_TITLE_SLOW_BOOT" desc="The title of the Slow Boot Shutdown Confirmation Dialog.">
Restart may take awhile
</message>
<message name="IDS_DIALOG_MESSAGE_SLOW_BOOT" desc="The body of the Slow Boot Shutdown Confirmation Dialog.">
Your screen will go blank for longer than usual (up to a minute) during this update. Please don't press the power button while the update is in progress.
</message>
<message name="IDS_ASH_STATUS_TRAY_VOLUME" desc="The accessible text for the toggle volume muted button in the tray."> <message name="IDS_ASH_STATUS_TRAY_VOLUME" desc="The accessible text for the toggle volume muted button in the tray.">
Toggle Volume. <ph name="STATE_TEXT">$1<ex>Volume is muted</ex></ph> Toggle Volume. <ph name="STATE_TEXT">$1<ex>Volume is muted</ex></ph>
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/model/system_tray_model.h" #include "ash/system/model/system_tray_model.h"
#include "ash/system/session/shutdown_confirmation_dialog.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
...@@ -162,6 +163,19 @@ base::string16 UpdateNotificationController::GetNotificationTitle() const { ...@@ -162,6 +163,19 @@ base::string16 UpdateNotificationController::GetNotificationTitle() const {
: l10n_util::GetStringUTF16(IDS_UPDATE_NOTIFICATION_TITLE); : l10n_util::GetStringUTF16(IDS_UPDATE_NOTIFICATION_TITLE);
} }
void UpdateNotificationController::RestartForUpdate() {
confirmation_dialog_ = nullptr;
Shell::Get()->system_tray_model()->client()->RequestRestartForUpdate();
Shell::Get()->metrics()->RecordUserMetricsAction(
UMA_STATUS_AREA_OS_UPDATE_DEFAULT_SELECTED);
}
void UpdateNotificationController::RestartCancelled() {
confirmation_dialog_ = nullptr;
// Put the notification back.
GenerateUpdateNotification(base::nullopt);
}
void UpdateNotificationController::HandleNotificationClick( void UpdateNotificationController::HandleNotificationClick(
base::Optional<int> button_index) { base::Optional<int> button_index) {
DCHECK(ShouldShowUpdate()); DCHECK(ShouldShowUpdate());
...@@ -178,9 +192,20 @@ void UpdateNotificationController::HandleNotificationClick( ...@@ -178,9 +192,20 @@ void UpdateNotificationController::HandleNotificationClick(
false /* by_user */); false /* by_user */);
if (model_->update_required()) { if (model_->update_required()) {
Shell::Get()->system_tray_model()->client()->RequestRestartForUpdate(); if (slow_boot_file_path_exists_) {
Shell::Get()->metrics()->RecordUserMetricsAction( // An active dialog exists already.
UMA_STATUS_AREA_OS_UPDATE_DEFAULT_SELECTED); if (confirmation_dialog_)
return;
confirmation_dialog_ = new ShutdownConfirmationDialog(
IDS_DIALOG_TITLE_SLOW_BOOT, IDS_DIALOG_MESSAGE_SLOW_BOOT,
base::BindOnce(&UpdateNotificationController::RestartForUpdate,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&UpdateNotificationController::RestartCancelled,
weak_ptr_factory_.GetWeakPtr()));
} else {
RestartForUpdate();
}
} else { } else {
// Shows the about chrome OS page and checks for update after the page is // Shows the about chrome OS page and checks for update after the page is
// loaded. // loaded.
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
namespace ash { namespace ash {
class ShutdownConfirmationDialog;
// Controller class to manage update notification. // Controller class to manage update notification.
class ASH_EXPORT UpdateNotificationController : public UpdateObserver { class ASH_EXPORT UpdateNotificationController : public UpdateObserver {
public: public:
...@@ -21,6 +23,12 @@ class ASH_EXPORT UpdateNotificationController : public UpdateObserver { ...@@ -21,6 +23,12 @@ class ASH_EXPORT UpdateNotificationController : public UpdateObserver {
// UpdateObserver: // UpdateObserver:
void OnUpdateAvailable() override; void OnUpdateAvailable() override;
// Callback functions for Shutdown Confirmation Dialog which is generated
// when the device bootup process is occasionally slow - eg. memory training
// during the bootup due to a system firmware update.
void RestartForUpdate();
void RestartCancelled();
private: private:
friend class UpdateNotificationControllerTest; friend class UpdateNotificationControllerTest;
...@@ -37,6 +45,7 @@ class ASH_EXPORT UpdateNotificationController : public UpdateObserver { ...@@ -37,6 +45,7 @@ class ASH_EXPORT UpdateNotificationController : public UpdateObserver {
base::FilePath slow_boot_file_path_; base::FilePath slow_boot_file_path_;
bool slow_boot_file_path_exists_ = false; bool slow_boot_file_path_exists_ = false;
ShutdownConfirmationDialog* confirmation_dialog_ = nullptr;
base::WeakPtrFactory<UpdateNotificationController> weak_ptr_factory_{this}; base::WeakPtrFactory<UpdateNotificationController> weak_ptr_factory_{this};
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/ash_features.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/model/system_tray_model.h" #include "ash/system/model/system_tray_model.h"
#include "ash/system/session/shutdown_confirmation_dialog.h"
#include "ash/system/system_notification_controller.h" #include "ash/system/system_notification_controller.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
...@@ -84,6 +85,16 @@ class UpdateNotificationControllerTest : public AshTestBase { ...@@ -84,6 +85,16 @@ class UpdateNotificationControllerTest : public AshTestBase {
->update_->slow_boot_file_path_ = file_path; ->update_->slow_boot_file_path_ = file_path;
} }
const char* GetUpdateNotificationId() {
return UpdateNotificationController::kNotificationId;
}
ShutdownConfirmationDialog* GetSlowBootConfirmationDialog() {
return Shell::Get()
->system_notification_controller()
->update_->confirmation_dialog_;
}
private: private:
DISALLOW_COPY_AND_ASSIGN(UpdateNotificationControllerTest); DISALLOW_COPY_AND_ASSIGN(UpdateNotificationControllerTest);
}; };
...@@ -141,6 +152,24 @@ TEST_F(UpdateNotificationControllerTest, VisibilityAfterUpdateWithSlowReboot) { ...@@ -141,6 +152,24 @@ TEST_F(UpdateNotificationControllerTest, VisibilityAfterUpdateWithSlowReboot) {
"This can take up to 1 minute.", "This can take up to 1 minute.",
GetNotificationMessage()); GetNotificationMessage());
EXPECT_EQ("Restart to update", GetNotificationButton(0)); EXPECT_EQ("Restart to update", GetNotificationButton(0));
// Ensure Slow Boot Dialog is not open.
EXPECT_FALSE(GetSlowBootConfirmationDialog());
// Trigger Click on "Restart to Update" button in Notification.
message_center::MessageCenter::Get()->ClickOnNotificationButton(
GetUpdateNotificationId(), 0);
// Ensure Slow Boot Dialog is open and notification is removed.
ASSERT_TRUE(GetSlowBootConfirmationDialog());
EXPECT_FALSE(HasNotification());
// Click the cancel button on Slow Boot Confirmation Dialog.
GetSlowBootConfirmationDialog()->CancelDialog();
// Ensure that the Slow Boot Dialog is closed and notification is visible.
EXPECT_FALSE(GetSlowBootConfirmationDialog());
EXPECT_TRUE(HasNotification());
} }
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
......
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