Commit b64b55c2 authored by Nicholas Verne's avatar Nicholas Verne Committed by Commit Bot

Upgrading Crostini via settings, don't always end by showing a Terminal.

The original implementation ended the Crostini Upgrade by displaying a
Terminal connected to the upgraded Crostini container. This is not
wanted when the user has canceled the upgrade.

Bug: 1060770
Change-Id: If27c8dd90657eac76c3478b1c57351fadfba00e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2109571Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Commit-Queue: Nicholas Verne <nverne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#752658}
parent 19b03167
...@@ -24,21 +24,26 @@ GURL GetUrl() { ...@@ -24,21 +24,26 @@ GURL GetUrl() {
namespace chromeos { namespace chromeos {
void CrostiniUpgraderDialog::Show(base::OnceClosure launch_closure) { void CrostiniUpgraderDialog::Show(base::OnceClosure launch_closure,
bool only_run_launch_closure_on_restart) {
auto* instance = SystemWebDialogDelegate::FindInstance(GetUrl().spec()); auto* instance = SystemWebDialogDelegate::FindInstance(GetUrl().spec());
if (instance) { if (instance) {
instance->Focus(); instance->Focus();
return; return;
} }
instance = new CrostiniUpgraderDialog(std::move(launch_closure)); instance = new CrostiniUpgraderDialog(std::move(launch_closure),
only_run_launch_closure_on_restart);
instance->ShowSystemDialog(); instance->ShowSystemDialog();
base::UmaHistogramEnumeration(crostini::kUpgradeDialogEventHistogram, base::UmaHistogramEnumeration(crostini::kUpgradeDialogEventHistogram,
crostini::UpgradeDialogEvent::kDialogShown); crostini::UpgradeDialogEvent::kDialogShown);
} }
CrostiniUpgraderDialog::CrostiniUpgraderDialog(base::OnceClosure launch_closure) CrostiniUpgraderDialog::CrostiniUpgraderDialog(
base::OnceClosure launch_closure,
bool only_run_launch_closure_on_restart)
: SystemWebDialogDelegate{GetUrl(), /*title=*/{}}, : SystemWebDialogDelegate{GetUrl(), /*title=*/{}},
only_run_launch_closure_on_restart_(only_run_launch_closure_on_restart),
launch_closure_{std::move(launch_closure)} {} launch_closure_{std::move(launch_closure)} {}
CrostiniUpgraderDialog::~CrostiniUpgraderDialog() = default; CrostiniUpgraderDialog::~CrostiniUpgraderDialog() = default;
...@@ -71,12 +76,15 @@ bool CrostiniUpgraderDialog::CanCloseDialog() const { ...@@ -71,12 +76,15 @@ bool CrostiniUpgraderDialog::CanCloseDialog() const {
namespace { namespace {
void RunLaunchClosure(base::WeakPtr<crostini::CrostiniManager> crostini_manager, void RunLaunchClosure(base::WeakPtr<crostini::CrostiniManager> crostini_manager,
base::OnceClosure launch_closure, base::OnceClosure launch_closure,
bool only_run_launch_closure_on_restart,
bool restart_required) { bool restart_required) {
if (!crostini_manager) { if (!crostini_manager) {
return; return;
} }
if (!restart_required) { if (!restart_required) {
std::move(launch_closure).Run(); if (!only_run_launch_closure_on_restart) {
std::move(launch_closure).Run();
}
return; return;
} }
crostini_manager->RestartCrostini( crostini_manager->RestartCrostini(
...@@ -106,9 +114,9 @@ void CrostiniUpgraderDialog::OnDialogShown(content::WebUI* webui) { ...@@ -106,9 +114,9 @@ void CrostiniUpgraderDialog::OnDialogShown(content::WebUI* webui) {
crostini::kCrostiniDefaultContainerName)); crostini::kCrostiniDefaultContainerName));
upgrader_ui_ = static_cast<CrostiniUpgraderUI*>(webui->GetController()); upgrader_ui_ = static_cast<CrostiniUpgraderUI*>(webui->GetController());
upgrader_ui_->set_launch_callback( upgrader_ui_->set_launch_callback(base::BindOnce(
base::BindOnce(&RunLaunchClosure, crostini_manager->GetWeakPtr(), &RunLaunchClosure, crostini_manager->GetWeakPtr(),
std::move(launch_closure_))); std::move(launch_closure_), only_run_launch_closure_on_restart_));
return SystemWebDialogDelegate::OnDialogShown(webui); return SystemWebDialogDelegate::OnDialogShown(webui);
} }
......
...@@ -13,10 +13,18 @@ class CrostiniUpgraderUI; ...@@ -13,10 +13,18 @@ class CrostiniUpgraderUI;
class CrostiniUpgraderDialog : public SystemWebDialogDelegate { class CrostiniUpgraderDialog : public SystemWebDialogDelegate {
public: public:
static void Show(base::OnceClosure launch_closure); // If a restart of Crostini is not required, the launch closure can be
// optionally dropped. e.g. when running the upgrader from Settings, if the
// user cancels before starting the upgrade, the launching of a Terminal is
// not desired. This contrasts to being propmpted for container upgrade from
// The app launcher, in which case the user could opt not to upgrade and the
// app should still be launched.
static void Show(base::OnceClosure launch_closure,
bool only_run_launch_closure_on_restart = false);
private: private:
explicit CrostiniUpgraderDialog(base::OnceClosure launch_closure); explicit CrostiniUpgraderDialog(base::OnceClosure launch_closure,
bool only_run_launch_closure_on_restart);
~CrostiniUpgraderDialog() override; ~CrostiniUpgraderDialog() override;
// SystemWebDialogDelegate: // SystemWebDialogDelegate:
...@@ -30,8 +38,8 @@ class CrostiniUpgraderDialog : public SystemWebDialogDelegate { ...@@ -30,8 +38,8 @@ class CrostiniUpgraderDialog : public SystemWebDialogDelegate {
bool* out_close_dialog) override; bool* out_close_dialog) override;
private: private:
// Not owned. CrostiniUpgraderUI* upgrader_ui_ = nullptr; // Not owned.
CrostiniUpgraderUI* upgrader_ui_ = nullptr; const bool only_run_launch_closure_on_restart_;
base::OnceClosure launch_closure_; base::OnceClosure launch_closure_;
}; };
......
...@@ -87,22 +87,23 @@ void CrostiniUpgraderPageHandler::Cancel() { ...@@ -87,22 +87,23 @@ void CrostiniUpgraderPageHandler::Cancel() {
} }
void CrostiniUpgraderPageHandler::Launch() { void CrostiniUpgraderPageHandler::Launch() {
std::move(launch_callback_).Run(true); std::move(launch_callback_).Run(restart_required_);
} }
void CrostiniUpgraderPageHandler::CancelBeforeStart() { void CrostiniUpgraderPageHandler::CancelBeforeStart() {
base::UmaHistogramEnumeration(crostini::kUpgradeDialogEventHistogram, base::UmaHistogramEnumeration(crostini::kUpgradeDialogEventHistogram,
crostini::UpgradeDialogEvent::kNotStarted); crostini::UpgradeDialogEvent::kNotStarted);
restart_required_ = false;
upgrader_ui_delegate_->CancelBeforeStart(); upgrader_ui_delegate_->CancelBeforeStart();
if (launch_callback_) { if (launch_callback_) {
// Running launch closure - no upgrade wanted, no need to restart crostini. // Running launch closure - no upgrade wanted, no need to restart crostini.
std::move(launch_callback_).Run(false); Launch();
} }
} }
void CrostiniUpgraderPageHandler::Close() { void CrostiniUpgraderPageHandler::Close() {
if (launch_callback_) { if (launch_callback_) {
std::move(launch_callback_).Run(true); Launch();
} }
std::move(close_dialog_callback_).Run(); std::move(close_dialog_callback_).Run();
} }
......
...@@ -70,6 +70,10 @@ class CrostiniUpgraderPageHandler ...@@ -70,6 +70,10 @@ class CrostiniUpgraderPageHandler
mojo::Remote<chromeos::crostini_upgrader::mojom::Page> page_; mojo::Remote<chromeos::crostini_upgrader::mojom::Page> page_;
base::OnceClosure close_dialog_callback_; base::OnceClosure close_dialog_callback_;
base::OnceCallback<void(bool)> launch_callback_; base::OnceCallback<void(bool)> launch_callback_;
// Will we need to restart the container as part of launch_callback?
// |restart_required_| is true unless the user cancels before starting the
// upgrade.
bool restart_required_ = true;
base::WeakPtrFactory<CrostiniUpgraderPageHandler> weak_ptr_factory_{this}; base::WeakPtrFactory<CrostiniUpgraderPageHandler> weak_ptr_factory_{this};
......
...@@ -445,8 +445,12 @@ void CrostiniHandler::LaunchTerminal() { ...@@ -445,8 +445,12 @@ void CrostiniHandler::LaunchTerminal() {
void CrostiniHandler::HandleRequestContainerUpgradeView( void CrostiniHandler::HandleRequestContainerUpgradeView(
const base::ListValue* args) { const base::ListValue* args) {
CHECK_EQ(0U, args->GetList().size()); CHECK_EQ(0U, args->GetList().size());
chromeos::CrostiniUpgraderDialog::Show(base::BindOnce( chromeos::CrostiniUpgraderDialog::Show(
&CrostiniHandler::LaunchTerminal, weak_ptr_factory_.GetWeakPtr())); base::BindOnce(&CrostiniHandler::LaunchTerminal,
weak_ptr_factory_.GetWeakPtr()),
// If the user cancels the upgrade, we won't need to restart Crostini and
// we don't want to run the launch closure which would launch Terminal.
/*only_run_launch_closure_on_restart=*/true);
} }
void CrostiniHandler::OnCrostiniExportImportOperationStatusChanged( void CrostiniHandler::OnCrostiniExportImportOperationStatusChanged(
......
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