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

Side by Side Diff: chrome/browser/banners/app_banner_infobar_delegate_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_infobar_delegate_desktop.h" 5 #include "chrome/browser/banners/app_banner_infobar_delegate_desktop.h"
6 6
7 #include "base/bind.h"
7 #include "build/build_config.h" 8 #include "build/build_config.h"
8 #include "chrome/browser/banners/app_banner_data_fetcher_desktop.h" 9 #include "chrome/browser/banners/app_banner_manager.h"
9 #include "chrome/browser/banners/app_banner_metrics.h" 10 #include "chrome/browser/banners/app_banner_metrics.h"
10 #include "chrome/browser/banners/app_banner_settings_helper.h" 11 #include "chrome/browser/banners/app_banner_settings_helper.h"
11 #include "chrome/browser/extensions/bookmark_app_helper.h" 12 #include "chrome/browser/extensions/bookmark_app_helper.h"
12 #include "chrome/browser/infobars/infobar_service.h" 13 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/common/render_messages.h" 14 #include "chrome/common/render_messages.h"
15 #include "chrome/common/web_application_info.h"
14 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
15 #include "components/infobars/core/infobar.h" 17 #include "components/infobars/core/infobar.h"
16 #include "content/public/browser/render_frame_host.h" 18 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
18 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/gfx/vector_icons_public.h" 22 #include "ui/gfx/vector_icons_public.h"
21 23
22 namespace banners { 24 namespace banners {
23 25
24 AppBannerInfoBarDelegateDesktop::AppBannerInfoBarDelegateDesktop( 26 AppBannerInfoBarDelegateDesktop::AppBannerInfoBarDelegateDesktop(
25 scoped_refptr<AppBannerDataFetcherDesktop> fetcher, 27 base::WeakPtr<AppBannerManager> weak_manager,
26 const content::Manifest& web_manifest,
27 extensions::BookmarkAppHelper* bookmark_app_helper, 28 extensions::BookmarkAppHelper* bookmark_app_helper,
29 const content::Manifest& manifest,
28 int event_request_id) 30 int event_request_id)
29 : ConfirmInfoBarDelegate(), 31 : ConfirmInfoBarDelegate(),
30 fetcher_(fetcher), 32 weak_manager_(weak_manager),
31 web_manifest_(web_manifest),
32 bookmark_app_helper_(bookmark_app_helper), 33 bookmark_app_helper_(bookmark_app_helper),
34 manifest_(manifest),
33 event_request_id_(event_request_id), 35 event_request_id_(event_request_id),
34 has_user_interaction_(false) { 36 has_user_interaction_(false) {
35 } 37 }
36 38
37 AppBannerInfoBarDelegateDesktop::~AppBannerInfoBarDelegateDesktop() { 39 AppBannerInfoBarDelegateDesktop::~AppBannerInfoBarDelegateDesktop() {
38 if (!has_user_interaction_) 40 if (!has_user_interaction_)
39 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); 41 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED);
40 } 42 }
41 43
42 // static 44 // static
43 infobars::InfoBar* AppBannerInfoBarDelegateDesktop::Create( 45 infobars::InfoBar* AppBannerInfoBarDelegateDesktop::Create(
44 scoped_refptr<AppBannerDataFetcherDesktop> fetcher,
45 content::WebContents* web_contents, 46 content::WebContents* web_contents,
46 const content::Manifest& web_manifest, 47 base::WeakPtr<AppBannerManager> weak_manager,
47 extensions::BookmarkAppHelper* bookmark_app_helper, 48 extensions::BookmarkAppHelper* bookmark_app_helper,
49 const content::Manifest& manifest,
48 int event_request_id) { 50 int event_request_id) {
49 InfoBarService* infobar_service = 51 InfoBarService* infobar_service =
50 InfoBarService::FromWebContents(web_contents); 52 InfoBarService::FromWebContents(web_contents);
51 return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( 53 return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
52 std::unique_ptr<ConfirmInfoBarDelegate>( 54 std::unique_ptr<ConfirmInfoBarDelegate>(
53 new AppBannerInfoBarDelegateDesktop( 55 new AppBannerInfoBarDelegateDesktop(weak_manager, bookmark_app_helper,
54 fetcher, web_manifest, bookmark_app_helper, event_request_id)))); 56 manifest, event_request_id))));
55 } 57 }
56 58
57 infobars::InfoBarDelegate::Type 59 infobars::InfoBarDelegate::Type
58 AppBannerInfoBarDelegateDesktop::GetInfoBarType() const { 60 AppBannerInfoBarDelegateDesktop::GetInfoBarType() const {
59 return PAGE_ACTION_TYPE; 61 return PAGE_ACTION_TYPE;
60 } 62 }
61 63
62 int AppBannerInfoBarDelegateDesktop::GetIconId() const { 64 int AppBannerInfoBarDelegateDesktop::GetIconId() const {
63 return IDR_INFOBAR_APP_BANNER; 65 return IDR_INFOBAR_APP_BANNER;
64 } 66 }
(...skipping 17 matching lines...) Expand all
82 base::string16 AppBannerInfoBarDelegateDesktop::GetButtonLabel( 84 base::string16 AppBannerInfoBarDelegateDesktop::GetButtonLabel(
83 InfoBarButton button) const { 85 InfoBarButton button) const {
84 return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_ADD_BUTTON); 86 return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_ADD_BUTTON);
85 } 87 }
86 88
87 bool AppBannerInfoBarDelegateDesktop::Accept() { 89 bool AppBannerInfoBarDelegateDesktop::Accept() {
88 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); 90 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
89 has_user_interaction_ = true; 91 has_user_interaction_ = true;
90 92
91 bookmark_app_helper_->CreateFromAppBanner( 93 bookmark_app_helper_->CreateFromAppBanner(
92 base::Bind(&AppBannerDataFetcherDesktop::FinishCreateBookmarkApp, 94 base::Bind(&AppBannerManager::DidFinishCreatingBookmarkApp,
93 fetcher_), 95 weak_manager_),
94 web_manifest_); 96 manifest_);
95 return true; 97 return true;
96 } 98 }
97 99
98 infobars::InfoBarDelegate::InfoBarIdentifier 100 infobars::InfoBarDelegate::InfoBarIdentifier
99 AppBannerInfoBarDelegateDesktop::GetIdentifier() const { 101 AppBannerInfoBarDelegateDesktop::GetIdentifier() const {
100 return APP_BANNER_INFOBAR_DELEGATE_DESKTOP; 102 return APP_BANNER_INFOBAR_DELEGATE_DESKTOP;
101 } 103 }
102 104
103 void AppBannerInfoBarDelegateDesktop::InfoBarDismissed() { 105 void AppBannerInfoBarDelegateDesktop::InfoBarDismissed() {
104 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); 106 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED);
105 has_user_interaction_ = true; 107 has_user_interaction_ = true;
106 108
107 content::WebContents* web_contents = 109 content::WebContents* web_contents =
108 InfoBarService::WebContentsFromInfoBar(infobar()); 110 InfoBarService::WebContentsFromInfoBar(infobar());
109 if (web_contents) { 111 if (web_contents) {
110 fetcher_.get()->Cancel();
111
112 web_contents->GetMainFrame()->Send( 112 web_contents->GetMainFrame()->Send(
113 new ChromeViewMsg_AppBannerDismissed( 113 new ChromeViewMsg_AppBannerDismissed(
114 web_contents->GetMainFrame()->GetRoutingID(), 114 web_contents->GetMainFrame()->GetRoutingID(),
115 event_request_id_)); 115 event_request_id_));
116 116
117 AppBannerSettingsHelper::RecordBannerDismissEvent( 117 AppBannerSettingsHelper::RecordBannerDismissEvent(
118 web_contents, web_manifest_.start_url.spec(), 118 web_contents, manifest_.start_url.spec(), AppBannerSettingsHelper::WEB);
119 AppBannerSettingsHelper::WEB);
120 } 119 }
121 } 120 }
122 121
123 } // namespace banners 122 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_infobar_delegate_desktop.h ('k') | chrome/browser/banners/app_banner_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698