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

Side by Side Diff: chrome/browser/android/banners/app_banner_infobar_delegate_android.cc

Issue 2969163002: Remove AppBannerManager::event_request_id(). (Closed)
Patch Set: Refactor into method Created 3 years, 5 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/android/banners/app_banner_infobar_delegate_android.h" 5 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 26 matching lines...) Expand all
37 37
38 namespace banners { 38 namespace banners {
39 39
40 // static 40 // static
41 bool AppBannerInfoBarDelegateAndroid::Create( 41 bool AppBannerInfoBarDelegateAndroid::Create(
42 content::WebContents* web_contents, 42 content::WebContents* web_contents,
43 base::WeakPtr<AppBannerManager> weak_manager, 43 base::WeakPtr<AppBannerManager> weak_manager,
44 std::unique_ptr<ShortcutInfo> shortcut_info, 44 std::unique_ptr<ShortcutInfo> shortcut_info,
45 const SkBitmap& primary_icon, 45 const SkBitmap& primary_icon,
46 const SkBitmap& badge_icon, 46 const SkBitmap& badge_icon,
47 int event_request_id,
48 bool is_webapk, 47 bool is_webapk,
49 webapk::InstallSource webapk_install_source) { 48 webapk::InstallSource webapk_install_source) {
50 DCHECK(shortcut_info); 49 DCHECK(shortcut_info);
51 const GURL url = shortcut_info->url; 50 const GURL url = shortcut_info->url;
52 if (url.is_empty()) 51 if (url.is_empty())
53 return false; 52 return false;
54 53
55 auto infobar_delegate = 54 auto infobar_delegate =
56 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( 55 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid(
57 weak_manager, std::move(shortcut_info), primary_icon, badge_icon, 56 weak_manager, std::move(shortcut_info), primary_icon, badge_icon,
58 event_request_id, is_webapk, webapk_install_source)); 57 is_webapk, webapk_install_source));
59 auto* raw_delegate = infobar_delegate.get(); 58 auto* raw_delegate = infobar_delegate.get();
60 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( 59 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>(
61 std::move(infobar_delegate), url, is_webapk); 60 std::move(infobar_delegate), url, is_webapk);
62 if (!InfoBarService::FromWebContents(web_contents) 61 if (!InfoBarService::FromWebContents(web_contents)
63 ->AddInfoBar(std::move(infobar))) 62 ->AddInfoBar(std::move(infobar)))
64 return false; 63 return false;
65 64
66 if (is_webapk) { 65 if (is_webapk) {
67 if (webapk_install_source == webapk::INSTALL_SOURCE_MENU) { 66 if (webapk_install_source == webapk::INSTALL_SOURCE_MENU) {
68 webapk::TrackInstallInfoBarShown( 67 webapk::TrackInstallInfoBarShown(
69 webapk::WEBAPK_INFOBAR_SHOWN_FROM_MENU); 68 webapk::WEBAPK_INFOBAR_SHOWN_FROM_MENU);
70 raw_delegate->Accept(); 69 raw_delegate->Accept();
71 } else { 70 } else {
72 webapk::TrackInstallInfoBarShown( 71 webapk::TrackInstallInfoBarShown(
73 webapk::WEBAPK_INFOBAR_SHOWN_FROM_BANNER); 72 webapk::WEBAPK_INFOBAR_SHOWN_FROM_BANNER);
74 } 73 }
75 } 74 }
76 75
77 return true; 76 return true;
78 } 77 }
79 78
80 // static 79 // static
81 bool AppBannerInfoBarDelegateAndroid::Create( 80 bool AppBannerInfoBarDelegateAndroid::Create(
82 content::WebContents* web_contents, 81 content::WebContents* web_contents,
83 const base::string16& app_title, 82 const base::string16& app_title,
84 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, 83 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data,
85 const SkBitmap& icon, 84 const SkBitmap& icon,
86 const std::string& native_app_package, 85 const std::string& native_app_package,
87 const std::string& referrer, 86 const std::string& referrer) {
88 int event_request_id) {
89 auto infobar_delegate = base::WrapUnique(new AppBannerInfoBarDelegateAndroid( 87 auto infobar_delegate = base::WrapUnique(new AppBannerInfoBarDelegateAndroid(
90 app_title, native_app_data, icon, native_app_package, referrer, 88 app_title, native_app_data, icon, native_app_package, referrer));
91 event_request_id));
92 return InfoBarService::FromWebContents(web_contents) 89 return InfoBarService::FromWebContents(web_contents)
93 ->AddInfoBar(base::MakeUnique<AppBannerInfoBarAndroid>( 90 ->AddInfoBar(base::MakeUnique<AppBannerInfoBarAndroid>(
94 std::move(infobar_delegate), native_app_data)); 91 std::move(infobar_delegate), native_app_data));
95 } 92 }
96 93
97 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { 94 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() {
98 weak_ptr_factory_.InvalidateWeakPtrs(); 95 weak_ptr_factory_.InvalidateWeakPtrs();
99 96
100 if (!has_user_interaction_) { 97 if (!has_user_interaction_) {
101 if (!native_app_data_.is_null()) { 98 if (!native_app_data_.is_null()) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 env, java_delegate_, java_webapk_package_name); 195 env, java_delegate_, java_webapk_package_name);
199 UpdateInstallState(env, nullptr); 196 UpdateInstallState(env, nullptr);
200 install_state_ = INSTALLED; 197 install_state_ = INSTALLED;
201 } 198 }
202 199
203 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( 200 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid(
204 base::WeakPtr<AppBannerManager> weak_manager, 201 base::WeakPtr<AppBannerManager> weak_manager,
205 std::unique_ptr<ShortcutInfo> shortcut_info, 202 std::unique_ptr<ShortcutInfo> shortcut_info,
206 const SkBitmap& primary_icon, 203 const SkBitmap& primary_icon,
207 const SkBitmap& badge_icon, 204 const SkBitmap& badge_icon,
208 int event_request_id,
209 bool is_webapk, 205 bool is_webapk,
210 webapk::InstallSource webapk_install_source) 206 webapk::InstallSource webapk_install_source)
211 : weak_manager_(weak_manager), 207 : weak_manager_(weak_manager),
212 app_title_(shortcut_info->name), 208 app_title_(shortcut_info->name),
213 shortcut_info_(std::move(shortcut_info)), 209 shortcut_info_(std::move(shortcut_info)),
214 primary_icon_(primary_icon), 210 primary_icon_(primary_icon),
215 badge_icon_(badge_icon), 211 badge_icon_(badge_icon),
216 event_request_id_(event_request_id),
217 has_user_interaction_(false), 212 has_user_interaction_(false),
218 is_webapk_(is_webapk), 213 is_webapk_(is_webapk),
219 install_state_(INSTALL_NOT_STARTED), 214 install_state_(INSTALL_NOT_STARTED),
220 webapk_install_source_(webapk_install_source), 215 webapk_install_source_(webapk_install_source),
221 weak_ptr_factory_(this) { 216 weak_ptr_factory_(this) {
222 CreateJavaDelegate(); 217 CreateJavaDelegate();
223 } 218 }
224 219
225 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( 220 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid(
226 const base::string16& app_title, 221 const base::string16& app_title,
227 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, 222 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data,
228 const SkBitmap& icon, 223 const SkBitmap& icon,
229 const std::string& native_app_package, 224 const std::string& native_app_package,
230 const std::string& referrer, 225 const std::string& referrer)
231 int event_request_id)
232 : app_title_(app_title), 226 : app_title_(app_title),
233 native_app_data_(native_app_data), 227 native_app_data_(native_app_data),
234 primary_icon_(icon), 228 primary_icon_(icon),
235 native_app_package_(native_app_package), 229 native_app_package_(native_app_package),
236 referrer_(referrer), 230 referrer_(referrer),
237 event_request_id_(event_request_id),
238 has_user_interaction_(false), 231 has_user_interaction_(false),
239 weak_ptr_factory_(this) { 232 weak_ptr_factory_(this) {
240 DCHECK(!native_app_data_.is_null()); 233 DCHECK(!native_app_data_.is_null());
241 CreateJavaDelegate(); 234 CreateJavaDelegate();
242 } 235 }
243 236
244 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() { 237 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() {
245 java_delegate_.Reset(Java_AppBannerInfoBarDelegateAndroid_create( 238 java_delegate_.Reset(Java_AppBannerInfoBarDelegateAndroid_create(
246 base::android::AttachCurrentThread(), 239 base::android::AttachCurrentThread(),
247 reinterpret_cast<intptr_t>(this))); 240 reinterpret_cast<intptr_t>(this)));
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 328
336 bool AppBannerInfoBarDelegateAndroid::TriggeredFromBanner() const { 329 bool AppBannerInfoBarDelegateAndroid::TriggeredFromBanner() const {
337 return !is_webapk_ || webapk_install_source_ == webapk::INSTALL_SOURCE_BANNER; 330 return !is_webapk_ || webapk_install_source_ == webapk::INSTALL_SOURCE_BANNER;
338 } 331 }
339 332
340 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted() { 333 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted() {
341 if (!weak_manager_) 334 if (!weak_manager_)
342 return; 335 return;
343 336
344 if (TriggeredFromBanner()) 337 if (TriggeredFromBanner())
345 weak_manager_->SendBannerAccepted(event_request_id_); 338 weak_manager_->SendBannerAccepted();
346 339
347 // Send the appinstalled event. Note that this is fired *before* the 340 // Send the appinstalled event. Note that this is fired *before* the
348 // installation actually takes place (which can be a significant amount of 341 // installation actually takes place (which can be a significant amount of
349 // time later, especially if using WebAPKs). 342 // time later, especially if using WebAPKs).
350 // TODO(mgiuca): Fire the event *after* the installation is completed. 343 // TODO(mgiuca): Fire the event *after* the installation is completed.
351 weak_manager_->OnInstall(); 344 weak_manager_->OnInstall();
352 } 345 }
353 346
354 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( 347 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished(
355 WebApkInstallResult result, 348 WebApkInstallResult result,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 return gfx::Image::CreateFrom1xBitmap(primary_icon_); 396 return gfx::Image::CreateFrom1xBitmap(primary_icon_);
404 } 397 }
405 398
406 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { 399 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() {
407 has_user_interaction_ = true; 400 has_user_interaction_ = true;
408 401
409 content::WebContents* web_contents = 402 content::WebContents* web_contents =
410 InfoBarService::WebContentsFromInfoBar(infobar()); 403 InfoBarService::WebContentsFromInfoBar(infobar());
411 404
412 if (weak_manager_ && TriggeredFromBanner()) 405 if (weak_manager_ && TriggeredFromBanner())
413 weak_manager_->SendBannerDismissed(event_request_id_); 406 weak_manager_->SendBannerDismissed();
414 407
415 if (native_app_data_.is_null()) { 408 if (native_app_data_.is_null()) {
416 if (is_webapk_) 409 if (is_webapk_)
417 TrackWebApkInstallationDismissEvents(install_state_); 410 TrackWebApkInstallationDismissEvents(install_state_);
418 if (TriggeredFromBanner()) { 411 if (TriggeredFromBanner()) {
419 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); 412 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED);
420 AppBannerSettingsHelper::RecordBannerDismissEvent( 413 AppBannerSettingsHelper::RecordBannerDismissEvent(
421 web_contents, shortcut_info_->url.spec(), 414 web_contents, shortcut_info_->url.spec(),
422 AppBannerSettingsHelper::WEB); 415 AppBannerSettingsHelper::WEB);
423 } 416 }
(...skipping 30 matching lines...) Expand all
454 447
455 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); 448 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK);
456 return true; 449 return true;
457 } 450 }
458 451
459 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { 452 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) {
460 return RegisterNativesImpl(env); 453 return RegisterNativesImpl(env);
461 } 454 }
462 455
463 } // namespace banners 456 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698