0

post-login: Add update string for the dialog

We do this by storing the last seen software version and checking if the
new one is greater.

And some more renaming of pine.

Test: manual
Test: browser_tests InformedRestoreTest.Update
Change-Id: Ib15801e2beb6b81106e60fbc0f4ad3786c2a83ac
Fixed: b/328807089
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5703238
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1328401}
This commit is contained in:
Sammie Quon
2024-07-16 20:16:37 +00:00
committed by Chromium LUCI CQ
parent 052866afeb
commit cc0fb5dcde
19 changed files with 156 additions and 77 deletions

@@ -8294,6 +8294,9 @@ To shut down the device, press and hold the power button on the device again.
<message name="IDS_ASH_INFORMED_RESTORE_DIALOG_CRASH_DESCRIPTION" desc="Label of the description for the informed restore dialog, if the previous session ended with a crash. Gives a little more information than the title."> <message name="IDS_ASH_INFORMED_RESTORE_DIALOG_CRASH_DESCRIPTION" desc="Label of the description for the informed restore dialog, if the previous session ended with a crash. Gives a little more information than the title.">
Your Chromebook restarted unexpectedly. Open your previous windows and apps. Your Chromebook restarted unexpectedly. Open your previous windows and apps.
</message> </message>
<message name="IDS_ASH_INFORMED_RESTORE_DIALOG_UPDATE_DESCRIPTION" desc="Label of the description for the informed restore dialog, if the previous session was on a earlier version.">
Your Chromebook has been updated. Open your previous windows and apps.
</message>
<message name="IDS_ASH_INFORMED_RESTORE_DIALOG_NO_THANKS_BUTTON" desc="Label of the no thanks button for the informed restore dialog, which users can click if they choose not to restore."> <message name="IDS_ASH_INFORMED_RESTORE_DIALOG_NO_THANKS_BUTTON" desc="Label of the no thanks button for the informed restore dialog, which users can click if they choose not to restore.">
No thanks No thanks
</message> </message>

@@ -0,0 +1 @@
39ae79f4aaa91cee6b699179686b5c38f84610fd

@@ -284,14 +284,6 @@ inline constexpr char kMultitaskMenuNudgeClamshellLastShown[] =
inline constexpr char kMultitaskMenuNudgeTabletLastShown[] = inline constexpr char kMultitaskMenuNudgeTabletLastShown[] =
"cros.wm_nudge.tablet_multitask_nudge_last_shown"; "cros.wm_nudge.tablet_multitask_nudge_last_shown";
// The number of times we have shown the informed restore education nudge.
inline constexpr char kInformedRestoreNudgeShownCount[] =
"ash.wm.informed_restore_nudge_shown_count";
// The last time we showed the informed restore education nudge.
inline constexpr char kInformedRestoreNudgeLastShown[] =
"ash.wm.informed_restore_nudge_last_shown";
// The following SAML-related prefs are not settings that the domain admin can // The following SAML-related prefs are not settings that the domain admin can
// set, but information that the SAML Identity Provider can send us: // set, but information that the SAML Identity Provider can send us:
@@ -1035,21 +1027,35 @@ inline constexpr char kLocalStateDevicePeripheralDataAccessEnabled[] =
inline constexpr char kLoginShutdownTimestampPrefName[] = inline constexpr char kLoginShutdownTimestampPrefName[] =
"ash.shelf.login_shutdown_timestamp"; "ash.shelf.login_shutdown_timestamp";
// A `TimeDelta` pref indicates the length of time for taking the pine // The number of times we have shown the informed restore education nudge.
// screenshot on shutdown. inline constexpr char kInformedRestoreNudgeShownCount[] =
inline constexpr char kPineScreenshotTakenDuration[] = "ash.wm.informed_restore_nudge_shown_count";
// The last time we showed the informed restore education nudge.
inline constexpr char kInformedRestoreNudgeLastShown[] =
"ash.wm.informed_restore_nudge_last_shown";
// A `TimeDelta` pref indicates the length of time for taking the informed
// restore screenshot on shutdown. Pine is the old name for informed restore.
inline constexpr char kInformedRestoreScreenshotTakenDuration[] =
"ash.pine.screenshot_taken_duration"; "ash.pine.screenshot_taken_duration";
// A `TimeDelta` pref indicates the length of time for encoding and writing the // A `TimeDelta` pref indicates the length of time for encoding and writing the
// pine screenshot to the disk. // informed restore screenshot to the disk. Pine is the old name for informed
inline constexpr char kPineScreenshotEncodeAndSaveDuration[] = // restore.
inline constexpr char kInformedRestoreScreenshotEncodeAndSaveDuration[] =
"ash.pine.sreenshot_encode_and_save_duration"; "ash.pine.sreenshot_encode_and_save_duration";
// A boolean pref indicating whether the informed restore onboarding dialog // A boolean pref indicating whether the informed restore onboarding dialog
// should be shown. // should be shown. Pine is the old name for informed restore.
inline constexpr char kShowInformedRestoreOnboarding[] = inline constexpr char kShowInformedRestoreOnboarding[] =
"ash.pine.should_show_informed_restore_onboarding"; "ash.pine.should_show_informed_restore_onboarding";
// A string pref that stores the last software version. Used to notify users if
// there has been an update.
inline constexpr char kInformedRestoreLastVersion[] =
"ash.wm.informed_restore_last_version";
// A boolean pref that specifies if the cellular setup notification can be // A boolean pref that specifies if the cellular setup notification can be
// shown or not. This notification should be shown post-OOBE if the user has a // shown or not. This notification should be shown post-OOBE if the user has a
// cellular-capable device but no available cellular networks. It should only be // cellular-capable device but no available cellular networks. It should only be

@@ -297,10 +297,11 @@ LockStateController::~LockStateController() {
void LockStateController::RegisterPrefs(PrefRegistrySimple* registry) { void LockStateController::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterTimePref(prefs::kLoginShutdownTimestampPrefName, registry->RegisterTimePref(prefs::kLoginShutdownTimestampPrefName,
base::Time()); base::Time());
registry->RegisterTimeDeltaPref(prefs::kPineScreenshotTakenDuration, registry->RegisterTimeDeltaPref(
base::TimeDelta()); prefs::kInformedRestoreScreenshotTakenDuration, base::TimeDelta());
registry->RegisterTimeDeltaPref(prefs::kPineScreenshotEncodeAndSaveDuration, registry->RegisterTimeDeltaPref(
base::TimeDelta()); prefs::kInformedRestoreScreenshotEncodeAndSaveDuration,
base::TimeDelta());
} }
void LockStateController::AddObserver(LockStateObserver* observer) { void LockStateController::AddObserver(LockStateObserver* observer) {
@@ -969,9 +970,9 @@ void LockStateController::StartSessionStateChange(
void LockStateController::OnTakeScreenshotFailTimeout( void LockStateController::OnTakeScreenshotFailTimeout(
RequestedSessionState requested_session_state) { RequestedSessionState requested_session_state) {
SaveInformedRestoreScreenshotDuration(local_state_, SaveInformedRestoreScreenshotDuration(
prefs::kPineScreenshotTakenDuration, local_state_, prefs::kInformedRestoreScreenshotTakenDuration,
kTakeScreenshotFailTimeout); kTakeScreenshotFailTimeout);
RecordScreenshotOnShutdownStatus( RecordScreenshotOnShutdownStatus(
ScreenshotOnShutdownStatus::kFailedOnTakingScreenshotTimeout); ScreenshotOnShutdownStatus::kFailedOnTakingScreenshotTimeout);
mirror_wallpaper_layer_.reset(); mirror_wallpaper_layer_.reset();
@@ -994,9 +995,9 @@ void LockStateController::OnInformedRestoreImageTaken(
} }
take_screenshot_fail_timer_.Stop(); take_screenshot_fail_timer_.Stop();
SaveInformedRestoreScreenshotDuration(local_state_, SaveInformedRestoreScreenshotDuration(
prefs::kPineScreenshotTakenDuration, local_state_, prefs::kInformedRestoreScreenshotTakenDuration,
base::TimeTicks::Now() - start_time); base::TimeTicks::Now() - start_time);
mirror_wallpaper_layer_.reset(); mirror_wallpaper_layer_.reset();
@@ -1017,11 +1018,10 @@ void LockStateController::OnInformedRestoreImageSaved(
base::TimeTicks start_time, base::TimeTicks start_time,
const base::FilePath& file_path) { const base::FilePath& file_path) {
SaveInformedRestoreScreenshotDuration( SaveInformedRestoreScreenshotDuration(
local_state_, prefs::kPineScreenshotEncodeAndSaveDuration, local_state_, prefs::kInformedRestoreScreenshotEncodeAndSaveDuration,
// This duration includes the time waiting for the // This duration includes the time waiting for the `ThreadPool` to start
// `ThreadPool` to start running the task, also the // running the task, also the time that the UI thread waits to get the
// time that the UI thread waits to get the reply // reply from the `ThreadPool`.
// from the `ThreadPool`.
base::TimeTicks::Now() - start_time); base::TimeTicks::Now() - start_time);
RecordScreenshotOnShutdownStatus(ScreenshotOnShutdownStatus::kSucceeded); RecordScreenshotOnShutdownStatus(ScreenshotOnShutdownStatus::kSucceeded);
if (shutdown_canceled_) { if (shutdown_canceled_) {

@@ -1105,10 +1105,11 @@ TEST_F(LockStateControllerInformedRestoreTest, ShutdownWithWindows) {
auto* local_state = Shell::Get()->local_state(); auto* local_state = Shell::Get()->local_state();
// Informed restore screenshot related durations were recorded. // Informed restore screenshot related durations were recorded.
const base::TimeDelta screenshot_taken_duration = const base::TimeDelta screenshot_taken_duration =
local_state->GetTimeDelta(prefs::kPineScreenshotTakenDuration); local_state->GetTimeDelta(prefs::kInformedRestoreScreenshotTakenDuration);
EXPECT_FALSE(screenshot_taken_duration.is_zero()); EXPECT_FALSE(screenshot_taken_duration.is_zero());
const base::TimeDelta screenshot_encode_and_save_duration = const base::TimeDelta screenshot_encode_and_save_duration =
local_state->GetTimeDelta(prefs::kPineScreenshotEncodeAndSaveDuration); local_state->GetTimeDelta(
prefs::kInformedRestoreScreenshotEncodeAndSaveDuration);
EXPECT_FALSE(screenshot_encode_and_save_duration.is_zero()); EXPECT_FALSE(screenshot_encode_and_save_duration.is_zero());
} }

@@ -74,8 +74,8 @@ std::string GetPrefNameFromSuggestionType(BirchSuggestionType type) {
} // namespace } // namespace
BirchBarController::BirchBarController(bool from_pine_service) BirchBarController::BirchBarController(bool is_informed_restore)
: from_pine_service_(from_pine_service) { : is_informed_restore_(is_informed_restore) {
// Init and register the show suggestions pref changed callback. // Init and register the show suggestions pref changed callback.
show_suggestions_pref_registrar_.Init(GetPrefService()); show_suggestions_pref_registrar_.Init(GetPrefService());
show_suggestions_pref_registrar_.Add( show_suggestions_pref_registrar_.Add(
@@ -252,7 +252,7 @@ void BirchBarController::MaybeFetchDataFromModel() {
// Fetching data from model. // Fetching data from model.
data_fetch_in_progress_ = true; data_fetch_in_progress_ = true;
birch_model->RequestBirchDataFetch( birch_model->RequestBirchDataFetch(
/*is_post_login=*/from_pine_service_, /*is_post_login=*/is_informed_restore_,
base::BindOnce(&BirchBarController::OnItemsFetchedFromModel, base::BindOnce(&BirchBarController::OnItemsFetchedFromModel,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} else if (!birch_model_observer_.IsObserving()) { } else if (!birch_model_observer_.IsObserving()) {

@@ -119,8 +119,8 @@ class ASH_EXPORT BirchBarController : public BirchModel::Observer,
// Indicates if the data fetching is in progress. // Indicates if the data fetching is in progress.
bool data_fetch_in_progress_ = false; bool data_fetch_in_progress_ = false;
// True if the overview session was triggered by the pine service. // True if the overview session is an informed restore session.
const bool from_pine_service_; const bool is_informed_restore_;
// Show/hide suggestions pref change registrar. // Show/hide suggestions pref change registrar.
PrefChangeRegistrar show_suggestions_pref_registrar_; PrefChangeRegistrar show_suggestions_pref_registrar_;

@@ -299,8 +299,8 @@ void BirchBarView::SetupChips(const std::vector<raw_ptr<BirchItem>>& items) {
case State::kLoadingByUser: case State::kLoadingByUser:
reason = RelayoutReason::kSetupByUser; reason = RelayoutReason::kSetupByUser;
break; break;
// When loading in pine or reloading, directly perform fading in animation // When loading for informed restore or reloading, directly perform fading
// since the bar was filled by chip loaders. // in animation since the bar was filled by chip loaders.
case State::kLoadingForInformedRestore: case State::kLoadingForInformedRestore:
case State::kReloading: case State::kReloading:
break; break;

@@ -13,16 +13,16 @@
namespace ash { namespace ash {
// When entering in pine session and customizing suggestion types to show, the // When entering an informed restore session and customizing suggestion types to
// birch bar needs to fetch data from model. While waiting for the data, the // show, the birch bar needs to fetch data from the model. While waiting for the
// loader views will show on birch bar with corresponding fading in and out // data, the loader views will show on the birch bar with corresponding fading
// animations. // in and out animations.
class BirchChipLoaderView : public BirchChipButtonBase { class BirchChipLoaderView : public BirchChipButtonBase {
METADATA_HEADER(BirchChipLoaderView, BirchChipButtonBase) METADATA_HEADER(BirchChipLoaderView, BirchChipButtonBase)
public: public:
enum class Type { enum class Type {
kInit, // Used during loading in pine. kInit, // Used during loading for informed restore.
kReload, // Used when suggestions are customized by user. kReload, // Used when suggestions are customized by user.
kNone, kNone,
}; };

@@ -219,7 +219,7 @@ void OverviewSession::Init(
// Create this before the birch bar widget. // Create this before the birch bar widget.
if (features::IsForestFeatureEnabled()) { if (features::IsForestFeatureEnabled()) {
birch_bar_controller_ = std::make_unique<BirchBarController>( birch_bar_controller_ = std::make_unique<BirchBarController>(
/*from_pine_service=*/enter_exit_overview_type_ == /*is_informed_restore=*/enter_exit_overview_type_ ==
OverviewEnterExitType::kInformedRestore); OverviewEnterExitType::kInformedRestore);
} }

@@ -23,6 +23,13 @@ struct ASH_EXPORT InformedRestoreContentsData {
InformedRestoreContentsData& operator=(const InformedRestoreContentsData&) = delete; InformedRestoreContentsData& operator=(const InformedRestoreContentsData&) = delete;
~InformedRestoreContentsData(); ~InformedRestoreContentsData();
// The dialog will display a different description string based on the type.
enum class DialogType {
kNormal,
kCrash,
kUpdate,
};
struct AppInfo { struct AppInfo {
AppInfo(const std::string& id, const std::string& title, int window_id); AppInfo(const std::string& id, const std::string& title, int window_id);
AppInfo(const std::string& app_id, AppInfo(const std::string& app_id,
@@ -75,6 +82,9 @@ struct ASH_EXPORT InformedRestoreContentsData {
// different strings in this case. // different strings in this case.
bool last_session_crashed = false; bool last_session_crashed = false;
// The dialog will have slightly different strings depending on its type.
DialogType dialog_type = DialogType::kNormal;
// Callbacks for the restore and cancel buttons. // Callbacks for the restore and cancel buttons.
base::OnceClosure restore_callback; base::OnceClosure restore_callback;
base::OnceClosure cancel_callback; base::OnceClosure cancel_callback;

@@ -315,10 +315,20 @@ void InformedRestoreContentsView::CreateChildViews() {
Shell::Get()->informed_restore_controller()->contents_data(); Shell::Get()->informed_restore_controller()->contents_data();
CHECK(contents_data); CHECK(contents_data);
const int title_message_id = IDS_ASH_INFORMED_RESTORE_DIALOG_TITLE; const int title_message_id = IDS_ASH_INFORMED_RESTORE_DIALOG_TITLE;
const int description_message_id = int description_message_id;
contents_data->last_session_crashed switch (contents_data->dialog_type) {
? IDS_ASH_INFORMED_RESTORE_DIALOG_CRASH_DESCRIPTION case InformedRestoreContentsData::DialogType::kNormal:
: IDS_ASH_INFORMED_RESTORE_DIALOG_DESCRIPTION; description_message_id = IDS_ASH_INFORMED_RESTORE_DIALOG_DESCRIPTION;
break;
case InformedRestoreContentsData::DialogType::kCrash:
description_message_id =
IDS_ASH_INFORMED_RESTORE_DIALOG_CRASH_DESCRIPTION;
break;
case InformedRestoreContentsData::DialogType::kUpdate:
description_message_id =
IDS_ASH_INFORMED_RESTORE_DIALOG_UPDATE_DESCRIPTION;
break;
}
auto* primary_container_view = AddChildView( auto* primary_container_view = AddChildView(
// In landscape mode, this box layout view is the container for the left // In landscape mode, this box layout view is the container for the left

@@ -174,7 +174,6 @@ void InformedRestoreController::MaybeShowInformedRestoreOnboarding(
void InformedRestoreController:: void InformedRestoreController::
MaybeStartInformedRestoreSessionDevAccelerator() { MaybeStartInformedRestoreSessionDevAccelerator() {
auto data = std::make_unique<InformedRestoreContentsData>(); auto data = std::make_unique<InformedRestoreContentsData>();
data->last_session_crashed = false;
std::pair<base::OnceClosure, base::OnceClosure> split = std::pair<base::OnceClosure, base::OnceClosure> split =
base::SplitOnceCallback(base::BindOnce( base::SplitOnceCallback(base::BindOnce(
&InformedRestoreController::MaybeEndInformedRestoreSession, &InformedRestoreController::MaybeEndInformedRestoreSession,

@@ -39,9 +39,9 @@ void RecordScreenshotDurations(PrefService* local_state) {
}; };
record_uma(local_state, "Ash.Pine.ScreenshotTakenDuration", record_uma(local_state, "Ash.Pine.ScreenshotTakenDuration",
prefs::kPineScreenshotTakenDuration); prefs::kInformedRestoreScreenshotTakenDuration);
record_uma(local_state, "Ash.Pine.ScreenshotEncodeAndSaveDuration", record_uma(local_state, "Ash.Pine.ScreenshotEncodeAndSaveDuration",
prefs::kPineScreenshotEncodeAndSaveDuration); prefs::kInformedRestoreScreenshotEncodeAndSaveDuration);
} }
void RecordDialogScreenshotVisibility(bool visible) { void RecordDialogScreenshotVisibility(bool visible) {

@@ -29,6 +29,8 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(prefs::kInformedRestoreNudgeShownCount, 0); registry->RegisterIntegerPref(prefs::kInformedRestoreNudgeShownCount, 0);
registry->RegisterTimePref(prefs::kInformedRestoreNudgeLastShown, registry->RegisterTimePref(prefs::kInformedRestoreNudgeLastShown,
base::Time()); base::Time());
registry->RegisterStringPref(prefs::kInformedRestoreLastVersion,
std::string());
} }
} }

@@ -21,7 +21,6 @@
#include "ash/webui/settings/public/constants/routes.mojom.h" #include "ash/webui/settings/public/constants/routes.mojom.h"
#include "ash/webui/settings/public/constants/setting.mojom-shared.h" #include "ash/webui/settings/public/constants/setting.mojom-shared.h"
#include "ash/wm/desks/templates/saved_desk_controller.h" #include "ash/wm/desks/templates/saved_desk_controller.h"
#include "ash/wm/window_restore/informed_restore_contents_data.h"
#include "ash/wm/window_restore/informed_restore_controller.h" #include "ash/wm/window_restore/informed_restore_controller.h"
#include "ash/wm/window_restore/window_restore_util.h" #include "ash/wm/window_restore/window_restore_util.h"
#include "base/barrier_callback.h" #include "base/barrier_callback.h"
@@ -30,6 +29,7 @@
#include "base/ranges/algorithm.h" #include "base/ranges/algorithm.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "base/version_info/version_info.h"
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ash/app_restore/app_restore_arc_task_handler.h" #include "chrome/browser/ash/app_restore/app_restore_arc_task_handler.h"
#include "chrome/browser/ash/app_restore/full_restore_app_launch_handler.h" #include "chrome/browser/ash/app_restore/full_restore_app_launch_handler.h"
@@ -337,13 +337,27 @@ void FullRestoreService::Init(bool& show_notification) {
PrefService* prefs = profile_->GetPrefs(); PrefService* prefs = profile_->GetPrefs();
DCHECK(prefs); DCHECK(prefs);
// Determine whether we should show the update string. Crash takes priority
// over update but we do the computations to store the pref for the next
// session here first. The pref may not be registered in certain unit tests.
bool is_update = false;
if (features::IsForestFeatureEnabled() &&
prefs->HasPrefPath(prefs::kInformedRestoreLastVersion)) {
const base::Version old_version(
prefs->GetString(prefs::kInformedRestoreLastVersion));
const base::Version current_version = version_info::GetVersion();
prefs->SetString(prefs::kInformedRestoreLastVersion,
current_version.GetString());
is_update = old_version.IsValid() && current_version > old_version;
}
// If the system crashed before reboot, show the restore notification. // If the system crashed before reboot, show the restore notification.
if (ExitTypeService::GetLastSessionExitType(profile_) == ExitType::kCrashed) { if (ExitTypeService::GetLastSessionExitType(profile_) == ExitType::kCrashed) {
if (!HasRestorePref(prefs)) if (!HasRestorePref(prefs))
SetDefaultRestorePrefIfNecessary(prefs); SetDefaultRestorePrefIfNecessary(prefs);
MaybeShowRestoreNotification(kRestoreForCrashNotificationId, MaybeShowRestoreNotification(
show_notification); InformedRestoreContentsData::DialogType::kCrash, show_notification);
return; return;
} }
@@ -390,20 +404,26 @@ void FullRestoreService::Init(bool& show_notification) {
} }
switch (restore_pref) { switch (restore_pref) {
case RestoreOption::kAlways: case RestoreOption::kAlways: {
Restore(); Restore();
break; break;
case RestoreOption::kAskEveryTime: }
MaybeShowRestoreNotification(kRestoreNotificationId, show_notification); case RestoreOption::kAskEveryTime: {
const auto dialog_type =
is_update ? InformedRestoreContentsData::DialogType::kUpdate
: InformedRestoreContentsData::DialogType::kNormal;
MaybeShowRestoreNotification(dialog_type, show_notification);
MaybeInitiateAdminTemplateAutoLaunch(); MaybeInitiateAdminTemplateAutoLaunch();
break; break;
case RestoreOption::kDoNotRestore: }
case RestoreOption::kDoNotRestore: {
if (features::IsForestFeatureEnabled()) { if (features::IsForestFeatureEnabled()) {
MaybeShowInformedRestoreOnboarding(/*restore_on=*/false); MaybeShowInformedRestoreOnboarding(/*restore_on=*/false);
} }
::full_restore::FullRestoreSaveHandler::GetInstance()->AllowSave(); ::full_restore::FullRestoreSaveHandler::GetInstance()->AllowSave();
MaybeInitiateAdminTemplateAutoLaunch(); MaybeInitiateAdminTemplateAutoLaunch();
return; return;
}
} }
} }
@@ -598,11 +618,11 @@ bool FullRestoreService::CanBeInited() const {
} }
void FullRestoreService::InitInformedRestoreContentsData( void FullRestoreService::InitInformedRestoreContentsData(
bool last_session_crashed) { InformedRestoreContentsData::DialogType dialog_type) {
CHECK(app_launch_handler_->HasRestoreData()); CHECK(app_launch_handler_->HasRestoreData());
contents_data_ = std::make_unique<InformedRestoreContentsData>(); contents_data_ = std::make_unique<InformedRestoreContentsData>();
contents_data_->last_session_crashed = last_session_crashed; contents_data_->dialog_type = dialog_type;
contents_data_->restore_callback = base::BindOnce( contents_data_->restore_callback = base::BindOnce(
&FullRestoreService::OnDialogRestore, weak_ptr_factory_.GetWeakPtr()); &FullRestoreService::OnDialogRestore, weak_ptr_factory_.GetWeakPtr());
@@ -651,8 +671,9 @@ void FullRestoreService::InitInformedRestoreContentsData(
} }
} }
void FullRestoreService::MaybeShowRestoreNotification(const std::string& id, void FullRestoreService::MaybeShowRestoreNotification(
bool& show_notification) { InformedRestoreContentsData::DialogType dialog_type,
bool& show_notification) {
if (!app_launch_handler_) { if (!app_launch_handler_) {
return; return;
} }
@@ -676,7 +697,10 @@ void FullRestoreService::MaybeShowRestoreNotification(const std::string& id,
return; return;
} }
const bool last_session_crashed = id == kRestoreForCrashNotificationId; const bool last_session_crashed =
dialog_type == InformedRestoreContentsData::DialogType::kCrash;
const std::string id = last_session_crashed ? kRestoreForCrashNotificationId
: kRestoreNotificationId;
if (!app_launch_handler_->HasRestoreData()) { if (!app_launch_handler_->HasRestoreData()) {
CHECK(features::IsForestFeatureEnabled()); CHECK(features::IsForestFeatureEnabled());
MaybeShowInformedRestoreOnboarding(/*restore_on=*/true); MaybeShowInformedRestoreOnboarding(/*restore_on=*/true);
@@ -701,7 +725,7 @@ void FullRestoreService::MaybeShowRestoreNotification(const std::string& id,
if (features::IsForestFeatureEnabled()) { if (features::IsForestFeatureEnabled()) {
CHECK(delegate_); CHECK(delegate_);
InitInformedRestoreContentsData(last_session_crashed); InitInformedRestoreContentsData(dialog_type);
if (crosapi::browser_util::IsLacrosEnabled()) { if (crosapi::browser_util::IsLacrosEnabled()) {
crosapi::CrosapiManager::Get() crosapi::CrosapiManager::Get()

@@ -10,6 +10,7 @@
#include "ash/public/cpp/accelerators.h" #include "ash/public/cpp/accelerators.h"
#include "ash/public/cpp/session/session_observer.h" #include "ash/public/cpp/session/session_observer.h"
#include "ash/wm/window_restore/informed_restore_contents_data.h"
#include "base/callback_list.h" #include "base/callback_list.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h" #include "base/memory/raw_ptr.h"
@@ -32,11 +33,7 @@ namespace message_center {
class Notification; class Notification;
} // namespace message_center } // namespace message_center
namespace ash { namespace ash::full_restore {
struct InformedRestoreContentsData;
namespace full_restore {
class FullRestoreAppLaunchHandler; class FullRestoreAppLaunchHandler;
class FullRestoreDataHandler; class FullRestoreDataHandler;
@@ -159,11 +156,13 @@ class FullRestoreService : public KeyedService,
// apps. Otherwise, returns false. // apps. Otherwise, returns false.
bool CanBeInited() const; bool CanBeInited() const;
void InitInformedRestoreContentsData(bool last_session_crashed); void InitInformedRestoreContentsData(
InformedRestoreContentsData::DialogType dialog_type);
// Show the restore notification on startup. // Shows the restore notification or the informed restore dialog on startup.
void MaybeShowRestoreNotification(const std::string& id, void MaybeShowRestoreNotification(
bool& show_notification); InformedRestoreContentsData::DialogType dialog_type,
bool& show_notification);
void RecordRestoreAction(const std::string& notification_id, void RecordRestoreAction(const std::string& notification_id,
RestoreAction restore_action); RestoreAction restore_action);
@@ -263,8 +262,6 @@ class ScopedRestoreForTesting {
~ScopedRestoreForTesting(); ~ScopedRestoreForTesting();
}; };
} // namespace full_restore } // namespace ash::full_restore
} // namespace ash
#endif // CHROME_BROWSER_ASH_APP_RESTORE_FULL_RESTORE_SERVICE_H_ #endif // CHROME_BROWSER_ASH_APP_RESTORE_FULL_RESTORE_SERVICE_H_

@@ -1226,7 +1226,8 @@ TEST_F(ForestFullRestoreServiceTestHavingFullRestoreFile, Crash) {
MaybeStartInformedRestoreOverviewSession(testing::_)) MaybeStartInformedRestoreOverviewSession(testing::_))
.WillOnce([](std::unique_ptr<InformedRestoreContentsData> data) { .WillOnce([](std::unique_ptr<InformedRestoreContentsData> data) {
ASSERT_TRUE(data); ASSERT_TRUE(data);
EXPECT_TRUE(data->last_session_crashed); EXPECT_EQ(InformedRestoreContentsData::DialogType::kCrash,
data->dialog_type);
}); });
CreateFullRestoreServiceForTesting(std::move(mock_delegate)); CreateFullRestoreServiceForTesting(std::move(mock_delegate));

@@ -559,6 +559,31 @@ IN_PROC_BROWSER_TEST_F(InformedRestoreTest, AppInfo) {
EXPECT_EQ("jhdjimmaggjajfjphpljagpgkidjilnj", apps_infos[3].app_id); EXPECT_EQ("jhdjimmaggjajfjphpljagpgkidjilnj", apps_infos[3].app_id);
} }
IN_PROC_BROWSER_TEST_F(InformedRestoreTest, PRE_Update) {
// Need at least one window for restore data.
Profile* profile = ProfileManager::GetActiveUserProfile();
CreateBrowser(profile);
EXPECT_EQ(1u, BrowserList::GetInstance()->size());
// Prepare for the main test body by setting the version to one that will be
// less.
profile->GetPrefs()->SetString(prefs::kInformedRestoreLastVersion, "0.0.0.0");
// Immediate save to full restore file to bypass the 2.5 second throttle.
AppLaunchInfoSaveWaiter::Wait();
}
// Verify that the app info that is sent to ash shell is dialog type update.
IN_PROC_BROWSER_TEST_F(InformedRestoreTest, Update) {
EXPECT_TRUE(BrowserList::GetInstance()->empty());
const InformedRestoreContentsData* contents_data =
Shell::Get()->informed_restore_controller()->contents_data();
ASSERT_TRUE(contents_data);
EXPECT_EQ(InformedRestoreContentsData::DialogType::kUpdate,
contents_data->dialog_type);
}
IN_PROC_BROWSER_TEST_F(InformedRestoreTest, PRE_ReenterOverviewPineSession) { IN_PROC_BROWSER_TEST_F(InformedRestoreTest, PRE_ReenterOverviewPineSession) {
EXPECT_TRUE(BrowserList::GetInstance()->empty()); EXPECT_TRUE(BrowserList::GetInstance()->empty());
CreateBrowser(ProfileManager::GetActiveUserProfile()); CreateBrowser(ProfileManager::GetActiveUserProfile());