Commit 61bb4da3 authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

WebApp: Retire BookmarkAppAcceptanceCallback

AppInstallationAcceptanceCallback
now accepts a unique_ptr.

The type adapter function
BookmarkAppAcceptanceCallback
is no longer required.

Bug: 915043
Change-Id: Ia32ca1f704c5e110da0fe5e677218d1913dce7dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1600939Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658724}
parent a3aa96ab
...@@ -367,14 +367,16 @@ void BookmarkAppHelper::OnIconsDownloaded( ...@@ -367,14 +367,16 @@ void BookmarkAppHelper::OnIconsDownloaded(
if (!contents_) { if (!contents_) {
// The web contents can be null in tests. // The web contents can be null in tests.
OnBubbleCompleted(true, web_app_info_); OnBubbleCompleted(true,
std::make_unique<WebApplicationInfo>(web_app_info_));
return; return;
} }
Browser* browser = chrome::FindBrowserWithWebContents(contents_); Browser* browser = chrome::FindBrowserWithWebContents(contents_);
if (!browser) { if (!browser) {
// The browser can be null in tests. // The browser can be null in tests.
OnBubbleCompleted(true, web_app_info_); OnBubbleCompleted(true,
std::make_unique<WebApplicationInfo>(web_app_info_));
return; return;
} }
...@@ -404,9 +406,10 @@ void BookmarkAppHelper::OnIconsDownloaded( ...@@ -404,9 +406,10 @@ void BookmarkAppHelper::OnIconsDownloaded(
void BookmarkAppHelper::OnBubbleCompleted( void BookmarkAppHelper::OnBubbleCompleted(
bool user_accepted, bool user_accepted,
const WebApplicationInfo& web_app_info) { std::unique_ptr<WebApplicationInfo> web_app_info) {
if (user_accepted) { if (user_accepted) {
web_app_info_ = web_app_info; DCHECK(web_app_info);
web_app_info_ = *web_app_info;
if (is_policy_installed_app_) if (is_policy_installed_app_)
crx_installer_->set_install_source(Manifest::EXTERNAL_POLICY_DOWNLOAD); crx_installer_->set_install_source(Manifest::EXTERNAL_POLICY_DOWNLOAD);
......
...@@ -164,7 +164,7 @@ class BookmarkAppHelper : public content::NotificationObserver { ...@@ -164,7 +164,7 @@ class BookmarkAppHelper : public content::NotificationObserver {
// Called after the bubble has been shown, and the user has either accepted or // Called after the bubble has been shown, and the user has either accepted or
// the dialog was dismissed. // the dialog was dismissed.
void OnBubbleCompleted(bool user_accepted, void OnBubbleCompleted(bool user_accepted,
const WebApplicationInfo& web_app_info); std::unique_ptr<WebApplicationInfo> web_app_info);
// Called when the installation of the app is complete to perform the final // Called when the installation of the app is complete to perform the final
// installation steps. // installation steps.
......
...@@ -182,8 +182,9 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppHelperTest, CreateWindowedPWAIntoAppWindow) { ...@@ -182,8 +182,9 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppHelperTest, CreateWindowedPWAIntoAppWindow) {
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> observer(this); ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> observer(this);
observer.Add(ExtensionRegistry::Get(browser()->profile())); observer.Add(ExtensionRegistry::Get(browser()->profile()));
bookmark_app_helper_->OnBubbleCompleted(true, bookmark_app_helper_->OnBubbleCompleted(
bookmark_app_helper_->web_app_info_); true, std::make_unique<WebApplicationInfo>(
bookmark_app_helper_->web_app_info_));
Wait(); // Quits when the extension install completes. Wait(); // Quits when the extension install completes.
Browser* app_browser = chrome::FindBrowserWithWebContents(web_contents()); Browser* app_browser = chrome::FindBrowserWithWebContents(web_contents());
......
...@@ -96,7 +96,7 @@ void ShowCreateChromeAppShortcutsDialog( ...@@ -96,7 +96,7 @@ void ShowCreateChromeAppShortcutsDialog(
// WebApplicationInfo parameter contains the information about the app, // WebApplicationInfo parameter contains the information about the app,
// possibly modified by the user. // possibly modified by the user.
using AppInstallationAcceptanceCallback = using AppInstallationAcceptanceCallback =
base::OnceCallback<void(bool, const WebApplicationInfo&)>; base::OnceCallback<void(bool, std::unique_ptr<WebApplicationInfo>)>;
// Shows the Bookmark App bubble. // Shows the Bookmark App bubble.
// See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of // See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of
......
...@@ -118,15 +118,18 @@ bool BookmarkAppConfirmationView::ShouldShowCloseButton() const { ...@@ -118,15 +118,18 @@ bool BookmarkAppConfirmationView::ShouldShowCloseButton() const {
} }
void BookmarkAppConfirmationView::WindowClosing() { void BookmarkAppConfirmationView::WindowClosing() {
if (callback_) if (callback_) {
std::move(callback_).Run(false, web_app_info_); std::move(callback_).Run(
false, std::make_unique<WebApplicationInfo>(web_app_info_));
}
} }
bool BookmarkAppConfirmationView::Accept() { bool BookmarkAppConfirmationView::Accept() {
web_app_info_.title = GetTrimmedTitle(); web_app_info_.title = GetTrimmedTitle();
web_app_info_.open_as_window = web_app_info_.open_as_window =
open_as_window_checkbox_ && open_as_window_checkbox_->checked(); open_as_window_checkbox_ && open_as_window_checkbox_->checked();
std::move(callback_).Run(true, web_app_info_); std::move(callback_).Run(true,
std::make_unique<WebApplicationInfo>(web_app_info_));
return true; return true;
} }
......
...@@ -124,12 +124,15 @@ base::string16 PWAConfirmation::GetDialogButtonLabel(ui::DialogButton button) { ...@@ -124,12 +124,15 @@ base::string16 PWAConfirmation::GetDialogButtonLabel(ui::DialogButton button) {
} }
void PWAConfirmation::Accept() { void PWAConfirmation::Accept() {
std::move(callback_).Run(true, web_app_info_); std::move(callback_).Run(true,
std::make_unique<WebApplicationInfo>(web_app_info_));
} }
void PWAConfirmation::WindowClosing() { void PWAConfirmation::WindowClosing() {
if (callback_) if (callback_) {
std::move(callback_).Run(false, web_app_info_); std::move(callback_).Run(
false, std::make_unique<WebApplicationInfo>(web_app_info_));
}
} }
namespace chrome { namespace chrome {
......
...@@ -25,26 +25,13 @@ namespace web_app { ...@@ -25,26 +25,13 @@ namespace web_app {
namespace { namespace {
// Use tricky function adapters here to connect old API with new unique_ptr
// based API. TODO(loyso): Erase these type adapters. crbug.com/915043.
using AcceptanceCallback = InstallManager::WebAppInstallationAcceptanceCallback;
void BookmarkAppAcceptanceCallback(
AcceptanceCallback web_app_acceptance_callback,
bool user_accepted,
const WebApplicationInfo& web_app_info) {
std::move(web_app_acceptance_callback)
.Run(user_accepted, std::make_unique<WebApplicationInfo>(web_app_info));
}
void WebAppInstallDialogCallback( void WebAppInstallDialogCallback(
WebappInstallSource install_source, WebappInstallSource install_source,
content::WebContents* initiator_web_contents, content::WebContents* initiator_web_contents,
std::unique_ptr<WebApplicationInfo> web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
ForInstallableSite for_installable_site, ForInstallableSite for_installable_site,
AcceptanceCallback web_app_acceptance_callback) { InstallManager::WebAppInstallationAcceptanceCallback
chrome::AppInstallationAcceptanceCallback adapted_callback = base::BindOnce( web_app_acceptance_callback) {
BookmarkAppAcceptanceCallback, std::move(web_app_acceptance_callback));
// This is a copy paste of BookmarkAppHelper::OnIconsDownloaded(). // This is a copy paste of BookmarkAppHelper::OnIconsDownloaded().
// TODO(https://crbug.com/915043): Delete // TODO(https://crbug.com/915043): Delete
// BookmarkAppHelper::OnIconsDownloaded(). // BookmarkAppHelper::OnIconsDownloaded().
...@@ -53,14 +40,14 @@ void WebAppInstallDialogCallback( ...@@ -53,14 +40,14 @@ void WebAppInstallDialogCallback(
web_app_info->open_as_window = true; web_app_info->open_as_window = true;
if (install_source == WebappInstallSource::OMNIBOX_INSTALL_ICON) { if (install_source == WebappInstallSource::OMNIBOX_INSTALL_ICON) {
chrome::ShowPWAInstallBubble(initiator_web_contents, *web_app_info, chrome::ShowPWAInstallBubble(initiator_web_contents, *web_app_info,
std::move(adapted_callback)); std::move(web_app_acceptance_callback));
} else { } else {
chrome::ShowPWAInstallDialog(initiator_web_contents, *web_app_info, chrome::ShowPWAInstallDialog(initiator_web_contents, *web_app_info,
std::move(adapted_callback)); std::move(web_app_acceptance_callback));
} }
} else { } else {
chrome::ShowBookmarkAppDialog(initiator_web_contents, *web_app_info, chrome::ShowBookmarkAppDialog(initiator_web_contents, *web_app_info,
std::move(adapted_callback)); std::move(web_app_acceptance_callback));
} }
} }
......
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