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

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

Issue 2473243002: Ensure WebAPKs installed from the menu do not pollute banner statistics. (Closed)
Patch Set: Address nit Created 4 years, 1 month 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
« no previous file with comments | « chrome/browser/android/banners/app_banner_infobar_delegate_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 std::move(infobar_delegate), native_app_data)); 107 std::move(infobar_delegate), native_app_data));
108 } 108 }
109 109
110 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { 110 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() {
111 weak_ptr_factory_.InvalidateWeakPtrs(); 111 weak_ptr_factory_.InvalidateWeakPtrs();
112 112
113 if (!has_user_interaction_) { 113 if (!has_user_interaction_) {
114 if (!native_app_data_.is_null()) { 114 if (!native_app_data_.is_null()) {
115 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); 115 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED);
116 } else { 116 } else {
117 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); 117 if (TriggeredFromBanner())
118 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED);
118 if (is_webapk_) 119 if (is_webapk_)
119 webapk::TrackInstallEvent(webapk::INFOBAR_IGNORED); 120 webapk::TrackInstallEvent(webapk::INFOBAR_IGNORED);
120 } 121 }
121 } 122 }
122 123
123 TrackDismissEvent(DISMISS_EVENT_DISMISSED); 124 if (TriggeredFromBanner())
125 TrackDismissEvent(DISMISS_EVENT_DISMISSED);
124 JNIEnv* env = base::android::AttachCurrentThread(); 126 JNIEnv* env = base::android::AttachCurrentThread();
125 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_); 127 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_);
126 java_delegate_.Reset(); 128 java_delegate_.Reset();
127 } 129 }
128 130
129 void AppBannerInfoBarDelegateAndroid::UpdateInstallState( 131 void AppBannerInfoBarDelegateAndroid::UpdateInstallState(
130 JNIEnv* env, 132 JNIEnv* env,
131 const JavaParamRef<jobject>& obj) { 133 const JavaParamRef<jobject>& obj) {
132 if (native_app_data_.is_null() && !is_webapk_) 134 if (native_app_data_.is_null() && !is_webapk_)
133 return; 135 return;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 infobar()->owner()->RemoveInfoBar(infobar()); 179 infobar()->owner()->RemoveInfoBar(infobar());
178 } 180 }
179 } 181 }
180 182
181 bool AppBannerInfoBarDelegateAndroid::Accept() { 183 bool AppBannerInfoBarDelegateAndroid::Accept() {
182 has_user_interaction_ = true; 184 has_user_interaction_ = true;
183 185
184 content::WebContents* web_contents = 186 content::WebContents* web_contents =
185 InfoBarService::WebContentsFromInfoBar(infobar()); 187 InfoBarService::WebContentsFromInfoBar(infobar());
186 if (!web_contents) { 188 if (!web_contents) {
187 TrackDismissEvent(DISMISS_EVENT_ERROR); 189 if (TriggeredFromBanner())
190 TrackDismissEvent(DISMISS_EVENT_ERROR);
188 return true; 191 return true;
189 } 192 }
190 193
191 if (!native_app_data_.is_null()) 194 if (!native_app_data_.is_null())
192 return AcceptNativeApp(web_contents); 195 return AcceptNativeApp(web_contents);
193 196
194 if (is_webapk_) 197 if (is_webapk_)
195 return AcceptWebApk(web_contents); 198 return AcceptWebApk(web_contents);
196 199
197 return AcceptWebApp(web_contents); 200 return AcceptWebApp(web_contents);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 webapk::TrackUserAction(webapk::USER_ACTION_OPEN); 321 webapk::TrackUserAction(webapk::USER_ACTION_OPEN);
319 else 322 else
320 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); 323 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN);
321 SendBannerAccepted(); 324 SendBannerAccepted();
322 return true; 325 return true;
323 } 326 }
324 327
325 // If the WebAPK is not installed and the "Add to Home Screen" button is 328 // If the WebAPK is not installed and the "Add to Home Screen" button is
326 // clicked, install the WebAPK. 329 // clicked, install the WebAPK.
327 install_state_ = INSTALLING; 330 install_state_ = INSTALLING;
328 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
329 webapk::TrackInstallSource(webapk_install_source_); 331 webapk::TrackInstallSource(webapk_install_source_);
330 AppBannerSettingsHelper::RecordBannerInstallEvent( 332
331 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); 333 if (TriggeredFromBanner()) {
334 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
335 AppBannerSettingsHelper::RecordBannerInstallEvent(
336 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
337 }
332 338
333 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( 339 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState(
334 env, java_delegate_, true); 340 env, java_delegate_, true);
335 UpdateInstallState(env, nullptr); 341 UpdateInstallState(env, nullptr);
336 WebApkInstaller::FinishCallback callback = 342 WebApkInstaller::FinishCallback callback =
337 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, 343 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished,
338 weak_ptr_factory_.GetWeakPtr()); 344 weak_ptr_factory_.GetWeakPtr());
339 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), 345 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(),
340 *shortcut_info_, 346 *shortcut_info_,
341 *icon_.get(), callback); 347 *icon_.get(), callback);
342 SendBannerAccepted(); 348 SendBannerAccepted();
343 349
344 // Prevent the infobar from disappearing, because the infobar will show 350 // Prevent the infobar from disappearing, because the infobar will show
345 // "Adding" during the installation process. 351 // "Adding" during the installation process.
346 return false; 352 return false;
347 } 353 }
348 354
355 bool AppBannerInfoBarDelegateAndroid::TriggeredFromBanner() const {
356 return !is_webapk_ || webapk_install_source_ == webapk::INSTALL_SOURCE_BANNER;
357 }
358
349 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted() { 359 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted() {
350 if (weak_manager_) 360 if (weak_manager_ && TriggeredFromBanner())
351 weak_manager_->SendBannerAccepted(event_request_id_); 361 weak_manager_->SendBannerAccepted(event_request_id_);
352 } 362 }
353 363
354 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( 364 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished(
355 bool success, 365 bool success,
356 const std::string& webapk_package_name) { 366 const std::string& webapk_package_name) {
357 JNIEnv* env = base::android::AttachCurrentThread(); 367 JNIEnv* env = base::android::AttachCurrentThread();
358 if (!success) { 368 if (!success) {
359 DVLOG(1) << "The WebAPK installation failed."; 369 DVLOG(1) << "The WebAPK installation failed.";
360 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); 370 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { 402 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const {
393 return gfx::Image::CreateFrom1xBitmap(*icon_.get()); 403 return gfx::Image::CreateFrom1xBitmap(*icon_.get());
394 } 404 }
395 405
396 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { 406 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() {
397 has_user_interaction_ = true; 407 has_user_interaction_ = true;
398 408
399 content::WebContents* web_contents = 409 content::WebContents* web_contents =
400 InfoBarService::WebContentsFromInfoBar(infobar()); 410 InfoBarService::WebContentsFromInfoBar(infobar());
401 411
402 if (weak_manager_) 412 if (weak_manager_ && TriggeredFromBanner())
403 weak_manager_->SendBannerDismissed(event_request_id_); 413 weak_manager_->SendBannerDismissed(event_request_id_);
404 414
405 if (native_app_data_.is_null()) { 415 if (native_app_data_.is_null()) {
406 if (is_webapk_) 416 if (is_webapk_)
407 TrackWebApkInstallationDismissEvents(install_state_); 417 TrackWebApkInstallationDismissEvents(install_state_);
408 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); 418 if (TriggeredFromBanner()) {
409 AppBannerSettingsHelper::RecordBannerDismissEvent( 419 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED);
410 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); 420 AppBannerSettingsHelper::RecordBannerDismissEvent(
421 web_contents, shortcut_info_->url.spec(),
422 AppBannerSettingsHelper::WEB);
423 }
411 } else { 424 } else {
412 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); 425 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED);
413 AppBannerSettingsHelper::RecordBannerDismissEvent( 426 AppBannerSettingsHelper::RecordBannerDismissEvent(
414 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE); 427 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE);
415 } 428 }
416 } 429 }
417 430
418 base::string16 AppBannerInfoBarDelegateAndroid::GetMessageText() const { 431 base::string16 AppBannerInfoBarDelegateAndroid::GetMessageText() const {
419 return app_title_; 432 return app_title_;
420 } 433 }
(...skipping 20 matching lines...) Expand all
441 454
442 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); 455 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK);
443 return true; 456 return true;
444 } 457 }
445 458
446 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { 459 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) {
447 return RegisterNativesImpl(env); 460 return RegisterNativesImpl(env);
448 } 461 }
449 462
450 } // namespace banners 463 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/android/banners/app_banner_infobar_delegate_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698