Commit c279a6fb authored by Ella Ge's avatar Ella Ge Committed by Chromium LUCI CQ

Change close_callback in browser_dialogs to OnceCallback

Bug: 1152282
Change-Id: I73ea595a0ff4005067510d37790b737d7608fa64
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2602358Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Ella Ge <eirage@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840518}
parent 0513c111
......@@ -93,7 +93,7 @@ void ShowCreateChromeAppShortcutsDialog(
gfx::NativeWindow parent_window,
Profile* profile,
const extensions::Extension* app,
const base::Callback<void(bool /* created */)>& close_callback);
base::OnceCallback<void(bool /* created */)> close_callback);
// Shows the create chrome app shortcut dialog box. Same as above but for a
// WebApp instead of an Extension. |close_callback| may be null.
......@@ -101,7 +101,7 @@ void ShowCreateChromeAppShortcutsDialog(
gfx::NativeWindow parent_window,
Profile* profile,
const std::string& web_app_id,
const base::Callback<void(bool /* created */)>& close_callback);
base::OnceCallback<void(bool /* created */)> close_callback);
// Callback used to indicate whether a user has accepted the installation of a
// web app. The boolean parameter is true when the user accepts the dialog. The
......
......@@ -124,9 +124,8 @@ void AppInfoFooterPanel::OnExtensionUninstallDialogClosed(
void AppInfoFooterPanel::CreateShortcuts() {
DCHECK(CanCreateShortcuts(app_));
chrome::ShowCreateChromeAppShortcutsDialog(
GetWidget()->GetNativeWindow(), profile_, app_,
base::RepeatingCallback<void(bool)>());
chrome::ShowCreateChromeAppShortcutsDialog(GetWidget()->GetNativeWindow(),
profile_, app_, base::DoNothing());
}
// static
......
......@@ -34,20 +34,22 @@ void ShowCreateChromeAppShortcutsDialog(
gfx::NativeWindow parent_window,
Profile* profile,
const extensions::Extension* app,
const base::RepeatingCallback<void(bool)>& close_callback) {
base::OnceCallback<void(bool)> close_callback) {
constrained_window::CreateBrowserModalDialogViews(
new CreateChromeApplicationShortcutView(profile, app, close_callback),
parent_window)->Show();
new CreateChromeApplicationShortcutView(profile, app,
std::move(close_callback)),
parent_window)
->Show();
}
void ShowCreateChromeAppShortcutsDialog(
gfx::NativeWindow parent_window,
Profile* profile,
const std::string& web_app_id,
const base::RepeatingCallback<void(bool)>& close_callback) {
base::OnceCallback<void(bool)> close_callback) {
constrained_window::CreateBrowserModalDialogViews(
new CreateChromeApplicationShortcutView(profile, web_app_id,
close_callback),
std::move(close_callback)),
parent_window)
->Show();
}
......@@ -57,8 +59,8 @@ void ShowCreateChromeAppShortcutsDialog(
CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView(
Profile* profile,
const extensions::Extension* app,
const base::RepeatingCallback<void(bool)>& close_callback)
: CreateChromeApplicationShortcutView(profile, close_callback) {
base::OnceCallback<void(bool)> close_callback)
: CreateChromeApplicationShortcutView(profile, std::move(close_callback)) {
// Get shortcut and icon information; needed for creating the shortcut.
web_app::GetShortcutInfoForApp(
app, profile,
......@@ -69,8 +71,8 @@ CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView(
CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView(
Profile* profile,
const std::string& web_app_id,
const base::RepeatingCallback<void(bool)>& close_callback)
: CreateChromeApplicationShortcutView(profile, close_callback) {
base::OnceCallback<void(bool)> close_callback)
: CreateChromeApplicationShortcutView(profile, std::move(close_callback)) {
web_app::WebAppProvider* provider = web_app::WebAppProvider::Get(profile);
provider->os_integration_manager().GetShortcutInfoForApp(
web_app_id,
......@@ -80,8 +82,8 @@ CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView(
CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView(
Profile* profile,
const base::RepeatingCallback<void(bool)>& close_callback)
: profile_(profile), close_callback_(close_callback) {
base::OnceCallback<void(bool)> close_callback)
: profile_(profile), close_callback_(std::move(close_callback)) {
SetButtonLabel(ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_COMMIT));
set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
......@@ -91,7 +93,7 @@ CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView(
base::Unretained(this)));
auto canceled = [](CreateChromeApplicationShortcutView* dialog) {
if (!dialog->close_callback_.is_null())
dialog->close_callback_.Run(false);
std::move(dialog->close_callback_).Run(false);
};
SetCancelCallback(base::BindOnce(canceled, base::Unretained(this)));
SetCloseCallback(base::BindOnce(canceled, base::Unretained(this)));
......@@ -219,7 +221,7 @@ void CreateChromeApplicationShortcutView::OnDialogAccepted() {
DCHECK(IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
if (!close_callback_.is_null())
close_callback_.Run(/*success=*/shortcut_info_ != nullptr);
std::move(close_callback_).Run(/*success=*/shortcut_info_ != nullptr);
// Shortcut can't be created because app info hasn't been loaded.
if (!shortcut_info_)
......
......@@ -31,11 +31,11 @@ class CreateChromeApplicationShortcutView : public views::DialogDelegateView {
CreateChromeApplicationShortcutView(
Profile* profile,
const extensions::Extension* app,
const base::RepeatingCallback<void(bool)>& close_callback);
base::OnceCallback<void(bool)> close_callback);
CreateChromeApplicationShortcutView(
Profile* profile,
const std::string& web_app_id,
const base::RepeatingCallback<void(bool)>& close_callback);
base::OnceCallback<void(bool)> close_callback);
~CreateChromeApplicationShortcutView() override;
// Initialize the controls on the dialog.
......@@ -48,9 +48,8 @@ class CreateChromeApplicationShortcutView : public views::DialogDelegateView {
base::string16 GetWindowTitle() const override;
private:
CreateChromeApplicationShortcutView(
Profile* profile,
const base::RepeatingCallback<void(bool)>& cb);
CreateChromeApplicationShortcutView(Profile* profile,
base::OnceCallback<void(bool)> cb);
// Creates a new check-box with the given text and checked state.
std::unique_ptr<views::Checkbox> AddCheckbox(const base::string16& text,
......@@ -66,7 +65,7 @@ class CreateChromeApplicationShortcutView : public views::DialogDelegateView {
// Profile in which the shortcuts will be created.
Profile* profile_;
base::RepeatingCallback<void(bool)> close_callback_;
base::OnceCallback<void(bool)> close_callback_;
// May be null if the platform doesn't support a particular location.
views::Checkbox* desktop_check_box_ = nullptr;
......
......@@ -956,7 +956,7 @@ void AppLauncherHandler::HandleCreateAppShortcut(const base::ListValue* args) {
chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
chrome::ShowCreateChromeAppShortcutsDialog(
browser->window()->GetNativeWindow(), browser->profile(), app_id,
base::BindRepeating([](bool success) {
base::BindOnce([](bool success) {
base::UmaHistogramBoolean(
"Apps.AppInfoDialog.CreateWebAppShortcutSuccess", success);
}));
......@@ -977,7 +977,7 @@ void AppLauncherHandler::HandleCreateAppShortcut(const base::ListValue* args) {
web_ui()->GetWebContents());
chrome::ShowCreateChromeAppShortcutsDialog(
browser->window()->GetNativeWindow(), browser->profile(), extension,
base::BindRepeating([](bool success) {
base::BindOnce([](bool success) {
base::UmaHistogramBoolean(
"Apps.AppInfoDialog.CreateExtensionShortcutSuccess", success);
}));
......
......@@ -149,28 +149,28 @@ void ShowCreateChromeAppShortcutsDialog(
gfx::NativeWindow /*parent_window*/,
Profile* profile,
const extensions::Extension* app,
const base::Callback<void(bool)>& close_callback) {
base::OnceCallback<void(bool)> close_callback) {
// On Mac, the Applications folder is the only option, so don't bother asking
// the user anything. Just create shortcuts.
CreateShortcuts(web_app::SHORTCUT_CREATION_BY_USER,
web_app::ShortcutLocations(), profile, app,
base::DoNothing());
if (!close_callback.is_null())
close_callback.Run(true);
std::move(close_callback).Run(true);
}
void ShowCreateChromeAppShortcutsDialog(
gfx::NativeWindow /*parent_window*/,
Profile* profile,
const std::string& app_id,
const base::Callback<void(bool)>& close_callback) {
base::OnceCallback<void(bool)> close_callback) {
// On Mac, the Applications folder is the only option, so don't bother asking
// the user anything. Just create shortcuts.
CreateShortcutsForWebApp(web_app::SHORTCUT_CREATION_BY_USER,
web_app::ShortcutLocations(), profile, app_id,
base::DoNothing());
if (!close_callback.is_null())
close_callback.Run(true);
std::move(close_callback).Run(true);
}
} // namespace chrome
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