Chromium Code Reviews| Index: chrome/browser/android/webapps/add_to_homescreen_manager.cc |
| diff --git a/chrome/browser/android/webapps/add_to_homescreen_manager.cc b/chrome/browser/android/webapps/add_to_homescreen_manager.cc |
| index 3608e943e34200d435da7aae84e1ee3567502880..297a016aa16f4ea6ee1fa2df60ae830eff0be81e 100644 |
| --- a/chrome/browser/android/webapps/add_to_homescreen_manager.cc |
| +++ b/chrome/browser/android/webapps/add_to_homescreen_manager.cc |
| @@ -42,7 +42,8 @@ jlong InitializeAndStart(JNIEnv* env, |
| AddToHomescreenManager::AddToHomescreenManager(JNIEnv* env, jobject obj) |
| : add_shortcut_pending_(false), |
| - is_webapk_compatible_(false) { |
| + is_webapk_compatible_(false), |
| + weak_ptr_factory_(this) { |
| java_ref_.Reset(env, obj); |
| } |
| @@ -79,17 +80,38 @@ void AddToHomescreenManager::Start(content::WebContents* web_contents) { |
| if (ChromeWebApkHost::AreWebApkEnabled() && |
| InstallableManager::IsContentSecure(web_contents)) { |
| check_webapk_compatible = true; |
| - } else { |
| - ShowDialog(); |
| + if (ChromeWebApkHost::CanUseGooglePlayToInstallWebApk()) { |
| + // It is possible that the Google Play Install API isn't available when |
| + // Google Play install is enabled. In that case, we fallback to classic |
| + // add-to-homescreen shortcut flow. |
| + // ChromeWebApkHost will delete itself after the the check whether Google |
| + // Play Install API is done. |
| + ChromeWebApkHost* host = new ChromeWebApkHost(); |
| + ChromeWebApkHost::CanUseGooglePlayInstallApiCallback callback |
| + = base::Bind(&AddToHomescreenManager::OnCanUseGooglePlayInstallApi, |
| + weak_ptr_factory_.GetWeakPtr(), |
|
pkotwicz
2017/02/03 18:56:32
Is a weak ptr needed? We currently leak AddToHomes
Xi Han
2017/02/03 22:16:21
Updated to Unretained(this).
|
| + web_contents, check_webapk_compatible); |
| + host->CanUseGooglePlayInstallApi(callback); |
| + return; |
| + } |
| } |
| + StartImpl(web_contents, check_webapk_compatible, true); |
| +} |
| + |
| +void AddToHomescreenManager::StartImpl(content::WebContents* web_contents, |
| + bool check_webapk_compatible, |
| + bool can_use_webapk_install_flow) { |
| + if (!check_webapk_compatible) |
| + ShowDialog(); |
| + |
| data_fetcher_ = new AddToHomescreenDataFetcher( |
| web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(), |
| ShortcutHelper::GetMinimumHomescreenIconSizeInPx(), |
| ShortcutHelper::GetIdealSplashImageSizeInPx(), |
| ShortcutHelper::GetMinimumSplashImageSizeInPx(), |
| ShortcutHelper::GetIdealBadgeIconSizeInPx(), |
| - check_webapk_compatible, this); |
| + check_webapk_compatible, can_use_webapk_install_flow, this); |
| } |
| AddToHomescreenManager::~AddToHomescreenManager() { |
| @@ -99,6 +121,13 @@ AddToHomescreenManager::~AddToHomescreenManager() { |
| } |
| } |
| +void AddToHomescreenManager::OnCanUseGooglePlayInstallApi( |
| + content::WebContents* web_contents, |
| + bool check_webapk_compatible, |
| + bool isAvailable) { |
| + StartImpl(web_contents, check_webapk_compatible, isAvailable); |
| +} |
| + |
| void AddToHomescreenManager::ShowDialog() { |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| Java_AddToHomescreenManager_showDialog(env, java_ref_); |
| @@ -194,7 +223,8 @@ void AddToHomescreenManager::CreateInfoBarForWebApk(const ShortcutInfo& info, |
| banners::AppBannerInfoBarDelegateAndroid::Create( |
| data_fetcher_->web_contents(), nullptr, info.user_title, |
| base::MakeUnique<ShortcutInfo>(info), base::MakeUnique<SkBitmap>(icon), |
| - -1 /* event_request_id */, webapk::INSTALL_SOURCE_MENU); |
| + -1 /* event_request_id */, true /* can_use_webapk_install_flow */, |
| + webapk::INSTALL_SOURCE_MENU); |
| } |
| SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( |