Commit 638fb03e authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

ash: stop overriding DialogDelegate closure hooks

This change updates:
* AcceleratorConfirmationDialog, to pass the provided callbacks
  directly to DialogDelegate
* RemoveQueryConfirmationDialog, to use inline callback lambdas
  instead of overrides
* MultiprofilesIntroDialog, to use inline callback lambdas
* SessionAbortedDialog, to use an inline callback lambda
* TeleportWarningDialog, to use inline callback lambdas
* AccessibilityFeatureDisableDialog, to pass the provided callbacks
  directly to DialogDelegate
* ScreenSwitchCheckController, to use private callback methods
* LogoutConfirmationDialog, to use a private callback method
* ShutdownConfirmationDialog, to pass the provided callbacks
  directly to DialogDelegate

Bug: 1011446
Change-Id: Ib2608d8f9095335d1a00fea3b498cd7c29c23d3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2047413
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741316}
parent 9732f799
......@@ -27,11 +27,11 @@ AcceleratorConfirmationDialog::AcceleratorConfirmationDialog(
int dialog_text_id,
base::OnceClosure on_accept_callback,
base::OnceClosure on_cancel_callback)
: window_title_(l10n_util::GetStringUTF16(window_title_text_id)),
on_accept_callback_(std::move(on_accept_callback)),
on_cancel_callback_(std::move(on_cancel_callback)) {
: window_title_(l10n_util::GetStringUTF16(window_title_text_id)) {
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK, l10n_util::GetStringUTF16(IDS_ASH_CONTINUE_BUTTON));
DialogDelegate::set_accept_callback(std::move(on_accept_callback));
DialogDelegate::set_cancel_callback(std::move(on_cancel_callback));
SetLayoutManager(std::make_unique<views::FillLayout>());
SetBorder(views::CreateEmptyBorder(
......@@ -59,16 +59,6 @@ AcceleratorConfirmationDialog::AcceleratorConfirmationDialog(
AcceleratorConfirmationDialog::~AcceleratorConfirmationDialog() = default;
bool AcceleratorConfirmationDialog::Accept() {
std::move(on_accept_callback_).Run();
return true;
}
bool AcceleratorConfirmationDialog::Cancel() {
std::move(on_cancel_callback_).Run();
return true;
}
ui::ModalType AcceleratorConfirmationDialog::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
......
......@@ -5,7 +5,7 @@
#ifndef ASH_ACCELERATORS_ACCELERATOR_CONFIRMATION_DIALOG_H_
#define ASH_ACCELERATORS_ACCELERATOR_CONFIRMATION_DIALOG_H_
#include "base/callback.h"
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
......@@ -24,8 +24,6 @@ class AcceleratorConfirmationDialog : public views::DialogDelegateView {
~AcceleratorConfirmationDialog() override;
// views::DialogDelegateView:
bool Accept() override;
bool Cancel() override;
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
......@@ -33,8 +31,6 @@ class AcceleratorConfirmationDialog : public views::DialogDelegateView {
private:
const base::string16 window_title_;
base::OnceClosure on_accept_callback_;
base::OnceClosure on_cancel_callback_;
base::WeakPtrFactory<AcceleratorConfirmationDialog> weak_ptr_factory_{this};
......
......@@ -35,6 +35,14 @@ RemoveQueryConfirmationDialog::RemoveQueryConfirmationDialog(
DialogDelegate::set_button_label(ui::DIALOG_BUTTON_CANCEL,
l10n_util::GetStringUTF16(IDS_APP_CANCEL));
auto run_callback = [](RemoveQueryConfirmationDialog* dialog, bool accept) {
std::move(dialog->confirm_callback_).Run(accept, dialog->event_flags_);
};
DialogDelegate::set_accept_callback(
base::BindOnce(run_callback, base::Unretained(this), true));
DialogDelegate::set_cancel_callback(
base::BindOnce(run_callback, base::Unretained(this), false));
const views::LayoutProvider* provider = views::LayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
......@@ -77,20 +85,6 @@ bool RemoveQueryConfirmationDialog::ShouldShowCloseButton() const {
return false;
}
bool RemoveQueryConfirmationDialog::Accept() {
if (confirm_callback_)
std::move(confirm_callback_).Run(true, event_flags_);
return true;
}
bool RemoveQueryConfirmationDialog::Cancel() {
if (confirm_callback_)
std::move(confirm_callback_).Run(false, event_flags_);
return true;
}
gfx::Size RemoveQueryConfirmationDialog::CalculatePreferredSize() const {
const int default_width = kDialogWidth;
return gfx::Size(default_width, GetHeightForWidth(default_width));
......
......@@ -26,7 +26,7 @@ class RemoveQueryConfirmationDialog
RemoveQueryConfirmationDialog(const base::string16& query,
RemovalConfirmationCallback callback,
int event_flgas,
int event_flags,
ContentsView* contents_view);
~RemoveQueryConfirmationDialog() override;
......@@ -42,10 +42,6 @@ class RemoveQueryConfirmationDialog
ui::ModalType GetModalType() const override;
bool ShouldShowCloseButton() const override;
// views::DialogDelegate:
bool Accept() override;
bool Cancel() override;
// views::View:
gfx::Size CalculatePreferredSize() const override;
......
......@@ -37,16 +37,6 @@ void MultiprofilesIntroDialog::Show(OnAcceptCallback on_accept) {
widget->Show();
}
bool MultiprofilesIntroDialog::Cancel() {
std::move(on_accept_).Run(false, false);
return true;
}
bool MultiprofilesIntroDialog::Accept() {
std::move(on_accept_).Run(true, never_show_again_checkbox_->GetChecked());
return true;
}
ui::ModalType MultiprofilesIntroDialog::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
......@@ -70,6 +60,17 @@ MultiprofilesIntroDialog::MultiprofilesIntroDialog(OnAcceptCallback on_accept)
l10n_util::GetStringUTF16(IDS_ASH_DIALOG_DONT_SHOW_AGAIN))),
on_accept_(std::move(on_accept)) {
never_show_again_checkbox_->SetChecked(true);
DialogDelegate::set_accept_callback(base::BindOnce(
[](MultiprofilesIntroDialog* dialog) {
std::move(dialog->on_accept_)
.Run(true, dialog->never_show_again_checkbox_->GetChecked());
},
base::Unretained(this)));
DialogDelegate::set_cancel_callback(base::BindOnce(
[](MultiprofilesIntroDialog* dialog) {
std::move(dialog->on_accept_).Run(false, false);
},
base::Unretained(this)));
}
MultiprofilesIntroDialog::~MultiprofilesIntroDialog() = default;
......
......@@ -23,10 +23,6 @@ class MultiprofilesIntroDialog : public views::DialogDelegateView {
static void Show(OnAcceptCallback on_accept);
// views::DialogDelegate overrides.
bool Cancel() override;
bool Accept() override;
// views::WidgetDelegate overrides.
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
......
......@@ -49,11 +49,6 @@ void SessionAbortedDialog::Show(const std::string& user_email) {
}
}
bool SessionAbortedDialog::Accept() {
Shell::Get()->session_controller()->RequestSignOut();
return true;
}
ui::ModalType SessionAbortedDialog::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
......@@ -79,6 +74,8 @@ SessionAbortedDialog::SessionAbortedDialog() {
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(
IDS_ASH_MULTIPROFILES_SESSION_ABORT_BUTTON_LABEL));
DialogDelegate::set_accept_callback(base::BindOnce(
[]() { Shell::Get()->session_controller()->RequestSignOut(); }));
}
SessionAbortedDialog::~SessionAbortedDialog() = default;
......
......@@ -18,9 +18,6 @@ class SessionAbortedDialog : public views::DialogDelegateView {
public:
static void Show(const std::string& user_email);
// views::DialogDelegate overrides.
bool Accept() override;
// views::WidgetDelegate overrides.
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
......
......@@ -30,6 +30,17 @@ TeleportWarningDialog::TeleportWarningDialog(OnAcceptCallback callback)
l10n_util::GetStringUTF16(IDS_ASH_DIALOG_DONT_SHOW_AGAIN))),
on_accept_(std::move(callback)) {
never_show_again_checkbox_->SetChecked(true);
DialogDelegate::set_accept_callback(base::BindOnce(
[](TeleportWarningDialog* dialog) {
std::move(dialog->on_accept_)
.Run(true, dialog->never_show_again_checkbox_->GetChecked());
},
base::Unretained(this)));
DialogDelegate::set_cancel_callback(base::BindOnce(
[](TeleportWarningDialog* dialog) {
std::move(dialog->on_accept_).Run(false, false);
},
base::Unretained(this)));
}
TeleportWarningDialog::~TeleportWarningDialog() = default;
......@@ -46,16 +57,6 @@ void TeleportWarningDialog::Show(OnAcceptCallback callback) {
widget->Show();
}
bool TeleportWarningDialog::Cancel() {
std::move(on_accept_).Run(false, false);
return true;
}
bool TeleportWarningDialog::Accept() {
std::move(on_accept_).Run(true, never_show_again_checkbox_->GetChecked());
return true;
}
ui::ModalType TeleportWarningDialog::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
......
......@@ -27,10 +27,6 @@ class TeleportWarningDialog : public views::DialogDelegateView {
static void Show(OnAcceptCallback callback);
// views::DialogDelegate overrides.
bool Cancel() override;
bool Accept() override;
// views::WidgetDelegate overrides.
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
......
......@@ -26,11 +26,11 @@ AccessibilityFeatureDisableDialog::AccessibilityFeatureDisableDialog(
int dialog_text_id,
base::OnceClosure on_accept_callback,
base::OnceClosure on_cancel_callback)
: window_title_(l10n_util::GetStringUTF16(window_title_text_id)),
on_accept_callback_(std::move(on_accept_callback)),
on_cancel_callback_(std::move(on_cancel_callback)) {
: window_title_(l10n_util::GetStringUTF16(window_title_text_id)) {
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK, l10n_util::GetStringUTF16(IDS_ASH_YES_BUTTON));
DialogDelegate::set_accept_callback(std::move(on_accept_callback));
DialogDelegate::set_cancel_callback(std::move(on_cancel_callback));
SetLayoutManager(std::make_unique<views::FillLayout>());
SetBorder(views::CreateEmptyBorder(
......@@ -61,16 +61,6 @@ AccessibilityFeatureDisableDialog::AccessibilityFeatureDisableDialog(
AccessibilityFeatureDisableDialog::~AccessibilityFeatureDisableDialog() =
default;
bool AccessibilityFeatureDisableDialog::Cancel() {
std::move(on_cancel_callback_).Run();
return true;
}
bool AccessibilityFeatureDisableDialog::Accept() {
std::move(on_accept_callback_).Run();
return true;
}
ui::ModalType AccessibilityFeatureDisableDialog::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
......
......@@ -26,8 +26,6 @@ class AccessibilityFeatureDisableDialog : public views::DialogDelegateView {
~AccessibilityFeatureDisableDialog() override;
// views::DialogDelegateView:
bool Cancel() override;
bool Accept() override;
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
......@@ -38,8 +36,6 @@ class AccessibilityFeatureDisableDialog : public views::DialogDelegateView {
private:
const base::string16 window_title_;
base::OnceClosure on_accept_callback_;
base::OnceClosure on_cancel_callback_;
base::WeakPtrFactory<AccessibilityFeatureDisableDialog> weak_ptr_factory_{
this};
......
......@@ -29,6 +29,10 @@ class CancelCastingDialog : public views::DialogDelegateView {
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_DESKTOP_CASTING_ACTIVE_CONTINUE));
DialogDelegate::set_accept_callback(base::BindOnce(
&CancelCastingDialog::OnDialogAccepted, base::Unretained(this)));
DialogDelegate::set_cancel_callback(base::BindOnce(
&CancelCastingDialog::OnDialogCancelled, base::Unretained(this)));
}
~CancelCastingDialog() override = default;
......@@ -36,12 +40,9 @@ class CancelCastingDialog : public views::DialogDelegateView {
return l10n_util::GetStringUTF16(IDS_DESKTOP_CASTING_ACTIVE_TITLE);
}
bool Cancel() override {
std::move(callback_).Run(false);
return true;
}
void OnDialogCancelled() { std::move(callback_).Run(false); }
bool Accept() override {
void OnDialogAccepted() {
// Stop screen sharing and capturing. When notified, all capture sessions or
// all share sessions will be stopped.
// Currently, the logic is in ScreenSecurityNotificationController.
......@@ -49,7 +50,6 @@ class CancelCastingDialog : public views::DialogDelegateView {
Shell::Get()->system_tray_notifier()->NotifyScreenShareStop();
std::move(callback_).Run(true);
return true;
}
bool ShouldShowCloseButton() const override { return false; }
......
......@@ -40,6 +40,8 @@ LogoutConfirmationDialog::LogoutConfirmationDialog(
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON));
DialogDelegate::set_accept_callback(base::BindOnce(
&LogoutConfirmationDialog::OnDialogAccepted, base::Unretained(this)));
SetLayoutManager(std::make_unique<views::FillLayout>());
SetBorder(views::CreateEmptyBorder(
......@@ -78,13 +80,6 @@ void LogoutConfirmationDialog::ControllerGone() {
GetWidget()->Close();
}
bool LogoutConfirmationDialog::Accept() {
logout_time_ = controller_->clock()->NowTicks();
UpdateLabel();
controller_->OnLogoutConfirmed();
return true;
}
ui::ModalType LogoutConfirmationDialog::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
......@@ -129,4 +124,10 @@ void LogoutConfirmationDialog::UpdateLabel() {
}
}
void LogoutConfirmationDialog::OnDialogAccepted() {
logout_time_ = controller_->clock()->NowTicks();
UpdateLabel();
controller_->OnLogoutConfirmed();
}
} // namespace ash
......@@ -32,9 +32,6 @@ class LogoutConfirmationDialog : public views::DialogDelegateView {
// Called when |controller_| is no longer valid.
void ControllerGone();
// views::DialogDelegateView:
bool Accept() override;
// views::WidgetDelegate:
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
......@@ -47,6 +44,7 @@ class LogoutConfirmationDialog : public views::DialogDelegateView {
private:
void UpdateLabel();
void OnDialogAccepted();
LogoutConfirmationController* controller_;
base::TimeTicks logout_time_;
......
......@@ -33,15 +33,15 @@ ShutdownConfirmationDialog::ShutdownConfirmationDialog(
int dialog_text_id,
base::OnceClosure on_accept_callback,
base::OnceClosure on_cancel_callback)
: window_title_(l10n_util::GetStringUTF16(window_title_text_id)),
on_accept_callback_(std::move(on_accept_callback)),
on_cancel_callback_(std::move(on_cancel_callback)) {
: window_title_(l10n_util::GetStringUTF16(window_title_text_id)) {
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_ASH_SHUTDOWN_CONFIRMATION_OK_BUTTON));
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_CANCEL,
l10n_util::GetStringUTF16(IDS_ASH_SHUTDOWN_CONFIRMATION_CANCEL_BUTTON));
DialogDelegate::set_accept_callback(std::move(on_accept_callback));
DialogDelegate::set_cancel_callback(std::move(on_cancel_callback));
SetLayoutManager(std::make_unique<views::FillLayout>());
SetBorder(views::CreateEmptyBorder(
views::LayoutProvider::Get()->GetDialogInsetsForContentType(
......@@ -64,16 +64,6 @@ ShutdownConfirmationDialog::ShutdownConfirmationDialog(
ShutdownConfirmationDialog::~ShutdownConfirmationDialog() = default;
bool ShutdownConfirmationDialog::Accept() {
std::move(on_accept_callback_).Run();
return true;
}
bool ShutdownConfirmationDialog::Cancel() {
std::move(on_cancel_callback_).Run();
return true;
}
ui::ModalType ShutdownConfirmationDialog::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
......
......@@ -26,10 +26,6 @@ class ShutdownConfirmationDialog : public views::DialogDelegateView {
base::OnceClosure on_cancel_callback);
~ShutdownConfirmationDialog() override;
// views::DialogDelegateView:
bool Accept() override;
bool Cancel() override;
// views::WidgetDelegate:
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
......@@ -40,8 +36,6 @@ class ShutdownConfirmationDialog : public views::DialogDelegateView {
private:
const base::string16 window_title_;
base::OnceClosure on_accept_callback_;
base::OnceClosure on_cancel_callback_;
views::Label* label_;
DISALLOW_COPY_AND_ASSIGN(ShutdownConfirmationDialog);
......
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