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

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

Issue 2721203004: Add webapp homescreen shortcut when WebAPK install fails (Closed)
Patch Set: Merge branch 'refactor_shortcut_helper2' into launch_webapp Created 3 years, 9 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
« 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/location.h" 9 #include "base/location.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // TODO(mgiuca): Send the appinstalled event for WebAPKs (but just removing 368 // TODO(mgiuca): Send the appinstalled event for WebAPKs (but just removing
369 // this check won't be sufficient). 369 // this check won't be sufficient).
370 if (!is_webapk_) 370 if (!is_webapk_)
371 weak_manager_->OnInstall(); 371 weak_manager_->OnInstall();
372 } 372 }
373 } 373 }
374 374
375 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( 375 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished(
376 bool success, 376 bool success,
377 const std::string& webapk_package_name) { 377 const std::string& webapk_package_name) {
378 JNIEnv* env = base::android::AttachCurrentThread();
379 if (!success) { 378 if (!success) {
380 DVLOG(1) << "The WebAPK installation failed."; 379 OnWebApkInstallFailed();
381 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env);
382 webapk::TrackInstallEvent(webapk::INSTALL_FAILED);
383 if (infobar())
384 infobar()->RemoveSelf();
385 return; 380 return;
386 } 381 }
387
388 UpdateStateForInstalledWebAPK(webapk_package_name); 382 UpdateStateForInstalledWebAPK(webapk_package_name);
389 webapk::TrackInstallDuration(timer_->Elapsed()); 383 webapk::TrackInstallDuration(timer_->Elapsed());
390 timer_.reset(); 384 timer_.reset();
391 webapk::TrackInstallEvent(webapk::INSTALL_COMPLETED); 385 webapk::TrackInstallEvent(webapk::INSTALL_COMPLETED);
392 } 386 }
393 387
388 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFailed() {
389 DVLOG(1) << "The WebAPK installation failed.";
390 webapk::TrackInstallEvent(webapk::INSTALL_FAILED);
391
392 if (!infobar())
393 return;
394
395 content::WebContents* web_contents =
396 InfoBarService::WebContentsFromInfoBar(infobar());
397 // Add webapp shortcut to the homescreen.
398 // TODO(pkotwicz): Only add webapp shortcut to the homescreen if
399 // WebAPK install did not timeout. If the WebAPK install timed out
400 // it is possible that Google Play is taking a long time and will
401 // eventually installs the WebAPK.
402 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_,
403 *icon_.get());
404
405 infobar()->RemoveSelf();
406 }
407
394 void AppBannerInfoBarDelegateAndroid::TrackWebApkInstallationDismissEvents( 408 void AppBannerInfoBarDelegateAndroid::TrackWebApkInstallationDismissEvents(
395 InstallState install_state) { 409 InstallState install_state) {
396 if (install_state == INSTALL_NOT_STARTED) { 410 if (install_state == INSTALL_NOT_STARTED) {
397 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_BEFORE_INSTALLATION); 411 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_BEFORE_INSTALLATION);
398 } else if (install_state == INSTALLING) { 412 } else if (install_state == INSTALLING) {
399 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_DURING_INSTALLATION); 413 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_DURING_INSTALLATION);
400 } else if (install_state == INSTALLED) { 414 } else if (install_state == INSTALLED) {
401 // If WebAPK is installed from this banner, TrackInstallEvent() is called in 415 // If WebAPK is installed from this banner, TrackInstallEvent() is called in
402 // OnWebApkInstallFinished(). 416 // OnWebApkInstallFinished().
403 if (is_webapk_already_installed_) 417 if (is_webapk_already_installed_)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 481
468 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); 482 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK);
469 return true; 483 return true;
470 } 484 }
471 485
472 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { 486 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) {
473 return RegisterNativesImpl(env); 487 return RegisterNativesImpl(env);
474 } 488 }
475 489
476 } // namespace banners 490 } // 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