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

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: Update add_to_homescreen_data_fetcher_unittest.cc. 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 will delete itself after the the check whether Google
216 // Play Install API is done.
217 ChromeWebApkHost* host = new ChromeWebApkHost();
218 ChromeWebApkHost::CanUseGooglePlayInstallApiCallback callback
219 = base::Bind(&AppBannerManagerAndroid::OnCanUseGooglePlayInstallApi,
220 weak_ptr_factory_.GetWeakPtr(),
221 contents);
222 host->CanUseGooglePlayInstallApi(callback);
215 } 223 }
216 } else { 224 } else {
217 if (AppBannerInfoBarDelegateAndroid::Create( 225 if (AppBannerInfoBarDelegateAndroid::Create(
218 contents, app_title_, native_app_data_, std::move(icon_), 226 contents, app_title_, native_app_data_, std::move(icon_),
219 native_app_package_, referrer_, event_request_id())) { 227 native_app_package_, referrer_, event_request_id())) {
220 RecordDidShowBanner("AppBanner.NativeApp.Shown"); 228 RecordDidShowBanner("AppBanner.NativeApp.Shown");
221 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); 229 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED);
222 ReportStatus(contents, SHOWING_NATIVE_APP_BANNER); 230 ReportStatus(contents, SHOWING_NATIVE_APP_BANNER);
223 } else { 231 } else {
224 ReportStatus(contents, FAILED_TO_CREATE_BANNER); 232 ReportStatus(contents, FAILED_TO_CREATE_BANNER);
225 } 233 }
226 } 234 }
227 } 235 }
228 236
237 void AppBannerManagerAndroid::ShowBannerImpl(content::WebContents* contents,
238 bool can_use_webapk_install_flow) {
239 if (AppBannerInfoBarDelegateAndroid::Create(
240 contents, GetWeakPtr(), app_title_,
241 CreateShortcutInfo(manifest_url_, manifest_, icon_url_),
242 std::move(icon_), event_request_id(), can_use_webapk_install_flow,
243 webapk::INSTALL_SOURCE_BANNER)) {
244 RecordDidShowBanner("AppBanner.WebApp.Shown");
245 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED);
246 ReportStatus(contents, SHOWING_WEB_APP_BANNER);
247 } else {
248 ReportStatus(contents, FAILED_TO_CREATE_BANNER);
249 }
250 }
251
252 void AppBannerManagerAndroid::OnCanUseGooglePlayInstallApi(
253 content::WebContents* web_contents,
254 bool isAvailable) {
255 ShowBannerImpl(web_contents, isAvailable);
256 }
257
229 bool AppBannerManagerAndroid::CanHandleNonWebApp(const std::string& platform, 258 bool AppBannerManagerAndroid::CanHandleNonWebApp(const std::string& platform,
230 const GURL& url, 259 const GURL& url,
231 const std::string& id) { 260 const std::string& id) {
232 if (!CheckPlatformAndId(platform, id)) 261 if (!CheckPlatformAndId(platform, id))
233 return false; 262 return false;
234 263
235 banners::TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_REQUESTED); 264 banners::TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_REQUESTED);
236 265
237 // Send the info to the Java side to get info about the app. 266 // Send the info to the Java side to get info about the app.
238 JNIEnv* env = base::android::AttachCurrentThread(); 267 JNIEnv* env = base::android::AttachCurrentThread();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 } 358 }
330 359
331 // static 360 // static
332 void SetTotalEngagementToTrigger(JNIEnv* env, 361 void SetTotalEngagementToTrigger(JNIEnv* env,
333 const JavaParamRef<jclass>& clazz, 362 const JavaParamRef<jclass>& clazz,
334 jdouble engagement) { 363 jdouble engagement) {
335 AppBannerSettingsHelper::SetTotalEngagementToTrigger(engagement); 364 AppBannerSettingsHelper::SetTotalEngagementToTrigger(engagement);
336 } 365 }
337 366
338 } // namespace banners 367 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698