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

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

Issue 2363183002: Skip installation process if WebAPK is already installed. (Closed)
Patch Set: Addressing comments Created 4 years, 2 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 "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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // Open the WebAPK. 184 // Open the WebAPK.
185 ScopedJavaLocalRef<jstring> java_webapk_package_name = 185 ScopedJavaLocalRef<jstring> java_webapk_package_name =
186 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); 186 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_);
187 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, 187 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_,
188 java_webapk_package_name); 188 java_webapk_package_name);
189 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); 189 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN);
190 SendBannerAccepted(web_contents, "web"); 190 SendBannerAccepted(web_contents, "web");
191 return true; 191 return true;
192 } 192 }
193 193
194 // Request install the WebAPK. 194 // Check whether the WebAPK has been installed.
195 install_state_ = INSTALLING; 195 std::string installed_webapk_package_name =
196 ShortcutHelper::QueryWebApkPackage(web_contents->GetLastCommittedURL());
197 if (installed_webapk_package_name.empty()) {
198 // Request install the WebAPK.
199 install_state_ = INSTALLING;
200 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
201 webapk::TrackInstallSource(webapk_install_source_);
202 AppBannerSettingsHelper::RecordBannerInstallEvent(
203 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
204
205 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState(
206 env, java_delegate_, true);
207 UpdateInstallState(env, nullptr);
208 WebApkInstaller::FinishCallback callback =
209 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished,
210 weak_ptr_factory_.GetWeakPtr());
211 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(),
212 *shortcut_info_,
213 *icon_.get(), callback);
214 SendBannerAccepted(web_contents, "web");
215
216 // Prevent the infobar from disappearing, because the infobar will show
217 // "Adding" during the installation process.
218 return false;
219 }
220
221 // Bypass the installation process.
dominickn 2016/09/30 23:32:24 If you keep this comment, make it more explicit, l
F 2016/10/03 14:13:44 Done.
196 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); 222 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
197 webapk::TrackInstallSource(webapk_install_source_); 223 weak_ptr_factory_.GetWeakPtr()->OnWebApkInstallFinished(
dominickn 2016/09/30 23:32:24 Directly call OnWebApkInstallFinished(true, instal
F 2016/10/03 14:13:44 Done. Thanks!
198 AppBannerSettingsHelper::RecordBannerInstallEvent( 224 true, installed_webapk_package_name);
199 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
200
201 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState(
202 env, java_delegate_, true);
203 UpdateInstallState(env, nullptr);
204 WebApkInstaller::FinishCallback callback =
205 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished,
206 weak_ptr_factory_.GetWeakPtr());
207 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(),
208 *shortcut_info_,
209 *icon_.get(), callback);
210 SendBannerAccepted(web_contents, "web");
211
212 // Prevent the infobar from disappearing, because the infobar will show
213 // "Adding" during the installation process.
214 return false; 225 return false;
215 } 226 }
216 227
217 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( 228 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid(
218 base::WeakPtr<AppBannerManager> weak_manager, 229 base::WeakPtr<AppBannerManager> weak_manager,
219 const base::string16& app_title, 230 const base::string16& app_title,
220 std::unique_ptr<ShortcutInfo> shortcut_info, 231 std::unique_ptr<ShortcutInfo> shortcut_info,
221 std::unique_ptr<SkBitmap> icon, 232 std::unique_ptr<SkBitmap> icon,
222 int event_request_id, 233 int event_request_id,
223 bool is_webapk, 234 bool is_webapk,
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 442
432 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); 443 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK);
433 return true; 444 return true;
434 } 445 }
435 446
436 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { 447 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) {
437 return RegisterNativesImpl(env); 448 return RegisterNativesImpl(env);
438 } 449 }
439 450
440 } // namespace banners 451 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java ('k') | chrome/browser/android/shortcut_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698