Componentize HistoryURLProvider/ScoredHistoryMatch.
[chromium-blink-merge.git] / chrome / browser / banners / app_banner_data_fetcher_desktop.cc
blobff1923c49aced125d47bc9df6581314509d4387e
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/banners/app_banner_data_fetcher_desktop.h"
7 #include "chrome/browser/banners/app_banner_infobar_delegate_desktop.h"
8 #include "chrome/browser/banners/app_banner_settings_helper.h"
9 #include "chrome/browser/extensions/bookmark_app_helper.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/render_messages.h"
12 #include "chrome/common/web_application_info.h"
13 #include "content/public/browser/render_frame_host.h"
15 namespace infobars {
16 class InfoBar;
17 } // namespace infobars
19 namespace banners {
21 AppBannerDataFetcherDesktop::AppBannerDataFetcherDesktop(
22 content::WebContents* web_contents,
23 base::WeakPtr<Delegate> weak_delegate,
24 int ideal_icon_size)
25 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size) {
28 AppBannerDataFetcherDesktop::~AppBannerDataFetcherDesktop() {
31 void AppBannerDataFetcherDesktop::ShowBanner(const SkBitmap* icon,
32 const base::string16& title) {
33 content::WebContents* web_contents = GetWebContents();
34 DCHECK(web_contents && !web_app_data().IsEmpty());
36 Profile* profile =
37 Profile::FromBrowserContext(web_contents->GetBrowserContext());
38 WebApplicationInfo web_app_info;
40 bookmark_app_helper_.reset(
41 new extensions::BookmarkAppHelper(profile, web_app_info, web_contents));
43 // This differs from the Android infobar creation, which has an explicit
44 // InfoBarAndroid class interfacing with Java. On Android, the data fetcher
45 // calls the InfoBarService to show the banner. On desktop, an InfoBar class
46 // is not required, so the InfoBarService call is made within the delegate.
47 infobars::InfoBar* infobar = AppBannerInfoBarDelegateDesktop::Create(
48 make_scoped_refptr(this), web_contents, web_app_data(),
49 bookmark_app_helper_.get(), event_request_id());
50 if (infobar) {
51 RecordDidShowBanner("AppBanner.WebApp.Shown");
55 void AppBannerDataFetcherDesktop::FinishCreateBookmarkApp(
56 const extensions::Extension* extension,
57 const WebApplicationInfo& web_app_info) {
58 content::WebContents* web_contents = GetWebContents();
59 if (web_contents) {
60 // A null extension pointer indicates that the bookmark app install was
61 // not successful.
62 if (extension == nullptr) {
63 web_contents->GetMainFrame()->Send(
64 new ChromeViewMsg_AppBannerDismissed(
65 web_contents->GetMainFrame()->GetRoutingID(),
66 event_request_id()));
68 AppBannerSettingsHelper::RecordBannerDismissEvent(
69 web_contents, web_app_data().start_url.spec(),
70 AppBannerSettingsHelper::WEB);
71 } else {
72 web_contents->GetMainFrame()->Send(
73 new ChromeViewMsg_AppBannerAccepted(
74 web_contents->GetMainFrame()->GetRoutingID(),
75 event_request_id(), "web"));
77 AppBannerSettingsHelper::RecordBannerInstallEvent(
78 web_contents, web_app_data().start_url.spec(),
79 AppBannerSettingsHelper::WEB);
84 } // namespace banners