Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1995)

Unified Diff: chrome/browser/banners/app_banner_manager_desktop.cc

Issue 2156113002: Replace AppBannerDataFetcher with InstallableManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@banner-refactor
Patch Set: Naming, includes Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/banners/app_banner_manager_desktop.cc
diff --git a/chrome/browser/banners/app_banner_manager_desktop.cc b/chrome/browser/banners/app_banner_manager_desktop.cc
index 01b8e80f782a802aa980690021a3c433f529c99c..bab306a008fff7ea2c58aaaa8f24208b802e2206 100644
--- a/chrome/browser/banners/app_banner_manager_desktop.cc
+++ b/chrome/browser/banners/app_banner_manager_desktop.cc
@@ -5,17 +5,19 @@
#include "chrome/browser/banners/app_banner_manager_desktop.h"
#include "base/command_line.h"
+#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
-#include "chrome/browser/banners/app_banner_data_fetcher_desktop.h"
+#include "chrome/browser/banners/app_banner_infobar_delegate_desktop.h"
+#include "chrome/browser/banners/app_banner_metrics.h"
+#include "chrome/browser/banners/app_banner_settings_helper.h"
+#include "chrome/browser/extensions/bookmark_app_helper.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/render_messages.h"
+#include "chrome/common/web_application_info.h"
+#include "content/public/browser/render_frame_host.h"
#include "extensions/common/constants.h"
-namespace {
-// TODO(dominickn) Identify the best minimum icon size to guarantee the best
-// user experience.
-int kMinimumIconSize = extension_misc::EXTENSION_ICON_LARGE;
-} // anonymous namespace
-
DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManagerDesktop);
namespace banners {
@@ -30,17 +32,87 @@ bool AppBannerManagerDesktop::IsEnabled() {
#endif
}
-AppBannerDataFetcher* AppBannerManagerDesktop::CreateAppBannerDataFetcher(
- base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate,
- bool is_debug_mode) {
- return new AppBannerDataFetcherDesktop(web_contents(), weak_delegate,
- kMinimumIconSize, kMinimumIconSize,
- is_debug_mode);
-}
-
AppBannerManagerDesktop::AppBannerManagerDesktop(
content::WebContents* web_contents)
- : AppBannerManager(web_contents) {
+ : AppBannerManager(web_contents) { }
+
+AppBannerManagerDesktop::~AppBannerManagerDesktop() { }
+
+void AppBannerManagerDesktop::DidFinishCreatingBookmarkApp(
+ const extensions::Extension* extension,
+ const WebApplicationInfo& web_app_info) {
+ content::WebContents* contents = web_contents();
+ if (contents) {
+ // A null extension pointer indicates that the bookmark app install was
+ // not successful.
+ if (extension == nullptr) {
+ contents->GetMainFrame()->Send(new ChromeViewMsg_AppBannerDismissed(
+ contents->GetMainFrame()->GetRoutingID(), event_request_id()));
+
+ AppBannerSettingsHelper::RecordBannerDismissEvent(
+ contents, GetAppIdentifier(), AppBannerSettingsHelper::WEB);
+ } else {
+ contents->GetMainFrame()->Send(new ChromeViewMsg_AppBannerAccepted(
+ contents->GetMainFrame()->GetRoutingID(), event_request_id(),
+ GetBannerType()));
+
+ AppBannerSettingsHelper::RecordBannerInstallEvent(
+ contents, GetAppIdentifier(), AppBannerSettingsHelper::WEB);
+ }
+ }
+}
+
+bool AppBannerManagerDesktop::IsWebAppInstalled(
+ content::BrowserContext* browser_context,
+ const GURL& start_url) {
+ return extensions::BookmarkAppHelper::BookmarkOrHostedAppInstalled(
+ browser_context, start_url);
+}
+
+void AppBannerManagerDesktop::ShowBanner() {
+ content::WebContents* contents = web_contents();
+ DCHECK(contents && !manifest_.IsEmpty());
+
+ Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
+ WebApplicationInfo web_app_info;
+
+ bookmark_app_helper_.reset(
+ new extensions::BookmarkAppHelper(profile, web_app_info, contents));
+
+ // This differs from Android, where there is a concrete
+ // AppBannerInfoBarAndroid class to interface with Java, and the manager calls
+ // the InfoBarService to show the banner. On desktop, an InfoBar class
+ // is not required, and the delegate calls the InfoBarService.
+ infobars::InfoBar* infobar = AppBannerInfoBarDelegateDesktop::Create(
+ contents, GetWeakPtr(), bookmark_app_helper_.get(), manifest_,
+ event_request_id());
+ if (infobar) {
+ RecordDidShowBanner("AppBanner.WebApp.Shown");
+ TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED);
+ }
+}
+
+void AppBannerManagerDesktop::DidFinishLoad(
+ content::RenderFrameHost* render_frame_host,
+ const GURL& validated_url) {
+ // Explicitly forbid banners from triggering on navigation unless this is
+ // enabled.
+ if (!IsEnabled())
+ return;
+
+ AppBannerManager::DidFinishLoad(render_frame_host, validated_url);
+}
+
+void AppBannerManagerDesktop::OnEngagementIncreased(
+ content::WebContents* web_contents,
+ const GURL& url,
+ double score) {
+ // Explicitly forbid banners from triggering on navigation unless this is
+ // enabled.
+ if (!IsEnabled())
+ return;
+
+ AppBannerManager::OnEngagementIncreased(web_contents, url, score);
}
} // namespace banners
« no previous file with comments | « chrome/browser/banners/app_banner_manager_desktop.h ('k') | chrome/browser/banners/app_banner_manager_emulation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698