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

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

Issue 2675803004: Fall back to shortcut A2HS when Phonesky is out of date or unavailable. (Closed)
Patch Set: pkotwicz@'s comments. Created 3 years, 10 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_manager_android.h" 5 #include "chrome/browser/android/banners/app_banner_manager_android.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 return shortcut_info; 50 return shortcut_info;
51 } 51 }
52 52
53 } // anonymous namespace 53 } // anonymous namespace
54 54
55 namespace banners { 55 namespace banners {
56 56
57 AppBannerManagerAndroid::AppBannerManagerAndroid( 57 AppBannerManagerAndroid::AppBannerManagerAndroid(
58 content::WebContents* web_contents) 58 content::WebContents* web_contents)
59 : AppBannerManager(web_contents) { 59 : AppBannerManager(web_contents),
60 weak_ptr_factory_(this) {
60 CreateJavaBannerManager(); 61 CreateJavaBannerManager();
61 } 62 }
62 63
63 AppBannerManagerAndroid::~AppBannerManagerAndroid() { 64 AppBannerManagerAndroid::~AppBannerManagerAndroid() {
64 JNIEnv* env = base::android::AttachCurrentThread(); 65 JNIEnv* env = base::android::AttachCurrentThread();
65 Java_AppBannerManager_destroy(env, java_banner_manager_); 66 Java_AppBannerManager_destroy(env, java_banner_manager_);
66 java_banner_manager_.Reset(); 67 java_banner_manager_.Reset();
67 } 68 }
68 69
69 base::Closure AppBannerManagerAndroid::FetchWebappSplashScreenImageCallback( 70 base::Closure AppBannerManagerAndroid::FetchWebappSplashScreenImageCallback(
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 196
196 icon_.reset(new SkBitmap(bitmap)); 197 icon_.reset(new SkBitmap(bitmap));
197 SendBannerPromptRequest(); 198 SendBannerPromptRequest();
198 } 199 }
199 200
200 void AppBannerManagerAndroid::ShowBanner() { 201 void AppBannerManagerAndroid::ShowBanner() {
201 content::WebContents* contents = web_contents(); 202 content::WebContents* contents = web_contents();
202 DCHECK(contents); 203 DCHECK(contents);
203 204
204 if (native_app_data_.is_null()) { 205 if (native_app_data_.is_null()) {
205 if (AppBannerInfoBarDelegateAndroid::Create( 206 if (!ChromeWebApkHost::AreWebApkEnabled() ||
206 contents, GetWeakPtr(), app_title_, 207 !ChromeWebApkHost::CanUseGooglePlayToInstallWebApk()) {
207 CreateShortcutInfo(manifest_url_, manifest_, icon_url_), 208 // If WebAPK isn't enabled, we don't care about whether the install flow
208 std::move(icon_), event_request_id(), 209 // can be used.
209 webapk::INSTALL_SOURCE_BANNER)) { 210 // If WebAPK is enabled but the Google Play Install isn't allowed, we set
210 RecordDidShowBanner("AppBanner.WebApp.Shown"); 211 // the flag be true to conitnue with the regular WebAPK install flow.
211 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); 212 ShowBannerImpl(contents, true);
212 ReportStatus(contents, SHOWING_WEB_APP_BANNER);
213 } else { 213 } else {
214 ReportStatus(contents, FAILED_TO_CREATE_BANNER); 214 // Checks whether Google Play install API is avaible.
215 ChromeWebApkHost::CanUseGooglePlayInstallApiCallback callback
216 = base::Bind(&AppBannerManagerAndroid::OnCanUseGooglePlayInstallApi,
217 weak_ptr_factory_.GetWeakPtr(),
218 contents);
219 ChromeWebApkHost::CanUseGooglePlayInstallApi(callback);
215 } 220 }
216 } else { 221 } else {
217 if (AppBannerInfoBarDelegateAndroid::Create( 222 if (AppBannerInfoBarDelegateAndroid::Create(
218 contents, app_title_, native_app_data_, std::move(icon_), 223 contents, app_title_, native_app_data_, std::move(icon_),
219 native_app_package_, referrer_, event_request_id())) { 224 native_app_package_, referrer_, event_request_id())) {
220 RecordDidShowBanner("AppBanner.NativeApp.Shown"); 225 RecordDidShowBanner("AppBanner.NativeApp.Shown");
221 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); 226 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED);
222 ReportStatus(contents, SHOWING_NATIVE_APP_BANNER); 227 ReportStatus(contents, SHOWING_NATIVE_APP_BANNER);
223 } else { 228 } else {
224 ReportStatus(contents, FAILED_TO_CREATE_BANNER); 229 ReportStatus(contents, FAILED_TO_CREATE_BANNER);
225 } 230 }
226 } 231 }
227 } 232 }
228 233
234 void AppBannerManagerAndroid::ShowBannerImpl(content::WebContents* contents,
235 bool can_use_webapk_install_flow) {
236 if (AppBannerInfoBarDelegateAndroid::Create(
237 contents, GetWeakPtr(), app_title_,
238 CreateShortcutInfo(manifest_url_, manifest_, icon_url_),
239 std::move(icon_), event_request_id(), can_use_webapk_install_flow,
240 webapk::INSTALL_SOURCE_BANNER)) {
241 RecordDidShowBanner("AppBanner.WebApp.Shown");
242 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED);
243 ReportStatus(contents, SHOWING_WEB_APP_BANNER);
244 } else {
245 ReportStatus(contents, FAILED_TO_CREATE_BANNER);
246 }
247 }
248
249 void AppBannerManagerAndroid::OnCanUseGooglePlayInstallApi(
250 content::WebContents* web_contents,
251 bool isAvailable) {
252 ShowBannerImpl(web_contents, isAvailable);
253 }
254
229 bool AppBannerManagerAndroid::CanHandleNonWebApp(const std::string& platform, 255 bool AppBannerManagerAndroid::CanHandleNonWebApp(const std::string& platform,
230 const GURL& url, 256 const GURL& url,
231 const std::string& id) { 257 const std::string& id) {
232 if (!CheckPlatformAndId(platform, id)) 258 if (!CheckPlatformAndId(platform, id))
233 return false; 259 return false;
234 260
235 banners::TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_REQUESTED); 261 banners::TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_REQUESTED);
236 262
237 // Send the info to the Java side to get info about the app. 263 // Send the info to the Java side to get info about the app.
238 JNIEnv* env = base::android::AttachCurrentThread(); 264 JNIEnv* env = base::android::AttachCurrentThread();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 } 355 }
330 356
331 // static 357 // static
332 void SetTotalEngagementToTrigger(JNIEnv* env, 358 void SetTotalEngagementToTrigger(JNIEnv* env,
333 const JavaParamRef<jclass>& clazz, 359 const JavaParamRef<jclass>& clazz,
334 jdouble engagement) { 360 jdouble engagement) {
335 AppBannerSettingsHelper::SetTotalEngagementToTrigger(engagement); 361 AppBannerSettingsHelper::SetTotalEngagementToTrigger(engagement);
336 } 362 }
337 363
338 } // namespace banners 364 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698