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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/banners/app_banner_manager_desktop.h" 5 #include "chrome/browser/banners/app_banner_manager_desktop.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
8 #include "build/build_config.h" 9 #include "build/build_config.h"
9 #include "chrome/browser/banners/app_banner_data_fetcher_desktop.h" 10 #include "chrome/browser/banners/app_banner_infobar_delegate_desktop.h"
11 #include "chrome/browser/banners/app_banner_metrics.h"
12 #include "chrome/browser/banners/app_banner_settings_helper.h"
13 #include "chrome/browser/extensions/bookmark_app_helper.h"
14 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/render_messages.h"
17 #include "chrome/common/web_application_info.h"
18 #include "content/public/browser/render_frame_host.h"
11 #include "extensions/common/constants.h" 19 #include "extensions/common/constants.h"
12 20
13 namespace {
14 // TODO(dominickn) Identify the best minimum icon size to guarantee the best
15 // user experience.
16 int kMinimumIconSize = extension_misc::EXTENSION_ICON_LARGE;
17 } // anonymous namespace
18
19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManagerDesktop); 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManagerDesktop);
20 22
21 namespace banners { 23 namespace banners {
22 24
23 bool AppBannerManagerDesktop::IsEnabled() { 25 bool AppBannerManagerDesktop::IsEnabled() {
24 #if defined(OS_CHROMEOS) 26 #if defined(OS_CHROMEOS)
25 return !base::CommandLine::ForCurrentProcess()->HasSwitch( 27 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
26 switches::kDisableAddToShelf); 28 switches::kDisableAddToShelf);
27 #else 29 #else
28 return base::CommandLine::ForCurrentProcess()->HasSwitch( 30 return base::CommandLine::ForCurrentProcess()->HasSwitch(
29 switches::kEnableAddToShelf); 31 switches::kEnableAddToShelf);
30 #endif 32 #endif
31 } 33 }
32 34
33 AppBannerDataFetcher* AppBannerManagerDesktop::CreateAppBannerDataFetcher(
34 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate,
35 bool is_debug_mode) {
36 return new AppBannerDataFetcherDesktop(web_contents(), weak_delegate,
37 kMinimumIconSize, kMinimumIconSize,
38 is_debug_mode);
39 }
40
41 AppBannerManagerDesktop::AppBannerManagerDesktop( 35 AppBannerManagerDesktop::AppBannerManagerDesktop(
42 content::WebContents* web_contents) 36 content::WebContents* web_contents)
43 : AppBannerManager(web_contents) { 37 : AppBannerManager(web_contents) { }
38
39 AppBannerManagerDesktop::~AppBannerManagerDesktop() { }
40
41 void AppBannerManagerDesktop::DidFinishCreatingBookmarkApp(
42 const extensions::Extension* extension,
43 const WebApplicationInfo& web_app_info) {
44 content::WebContents* contents = web_contents();
45 if (contents) {
46 // A null extension pointer indicates that the bookmark app install was
47 // not successful.
48 if (extension == nullptr) {
49 contents->GetMainFrame()->Send(new ChromeViewMsg_AppBannerDismissed(
50 contents->GetMainFrame()->GetRoutingID(), event_request_id()));
51
52 AppBannerSettingsHelper::RecordBannerDismissEvent(
53 contents, GetAppIdentifier(), AppBannerSettingsHelper::WEB);
54 } else {
55 contents->GetMainFrame()->Send(new ChromeViewMsg_AppBannerAccepted(
56 contents->GetMainFrame()->GetRoutingID(), event_request_id(),
57 GetBannerType()));
58
59 AppBannerSettingsHelper::RecordBannerInstallEvent(
60 contents, GetAppIdentifier(), AppBannerSettingsHelper::WEB);
61 }
62 }
63 }
64
65 bool AppBannerManagerDesktop::IsWebAppInstalled(
66 content::BrowserContext* browser_context,
67 const GURL& start_url) {
68 return extensions::BookmarkAppHelper::BookmarkOrHostedAppInstalled(
69 browser_context, start_url);
70 }
71
72 void AppBannerManagerDesktop::ShowBanner() {
73 content::WebContents* contents = web_contents();
74 DCHECK(contents && !manifest_.IsEmpty());
75
76 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
77 WebApplicationInfo web_app_info;
78
79 bookmark_app_helper_.reset(
80 new extensions::BookmarkAppHelper(profile, web_app_info, contents));
81
82 // This differs from Android, where there is a concrete
83 // AppBannerInfoBarAndroid class to interface with Java, and the manager calls
84 // the InfoBarService to show the banner. On desktop, an InfoBar class
85 // is not required, and the delegate calls the InfoBarService.
86 infobars::InfoBar* infobar = AppBannerInfoBarDelegateDesktop::Create(
87 contents, GetWeakPtr(), bookmark_app_helper_.get(), manifest_,
88 event_request_id());
89 if (infobar) {
90 RecordDidShowBanner("AppBanner.WebApp.Shown");
91 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED);
92 }
93 }
94
95 void AppBannerManagerDesktop::DidFinishLoad(
96 content::RenderFrameHost* render_frame_host,
97 const GURL& validated_url) {
98 // Explicitly forbid banners from triggering on navigation unless this is
99 // enabled.
100 if (!IsEnabled())
101 return;
102
103 AppBannerManager::DidFinishLoad(render_frame_host, validated_url);
104 }
105
106 void AppBannerManagerDesktop::OnEngagementIncreased(
107 content::WebContents* web_contents,
108 const GURL& url,
109 double score) {
110 // Explicitly forbid banners from triggering on navigation unless this is
111 // enabled.
112 if (!IsEnabled())
113 return;
114
115 AppBannerManager::OnEngagementIncreased(web_contents, url, score);
44 } 116 }
45 117
46 } // namespace banners 118 } // namespace banners
OLDNEW
« 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