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

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

Issue 2913383002: Remove unnecessary IsInfoEmpty() call in app_banner_infobar_delegate_android.cc (Closed)
Patch Set: Created 3 years, 6 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 | « no previous file | 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 <utility> 7 #include <utility>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 17 matching lines...) Expand all
28 #include "ui/gfx/android/java_bitmap.h" 28 #include "ui/gfx/android/java_bitmap.h"
29 #include "url/gurl.h" 29 #include "url/gurl.h"
30 30
31 using base::android::ConvertJavaStringToUTF8; 31 using base::android::ConvertJavaStringToUTF8;
32 using base::android::ConvertJavaStringToUTF16; 32 using base::android::ConvertJavaStringToUTF16;
33 using base::android::ConvertUTF8ToJavaString; 33 using base::android::ConvertUTF8ToJavaString;
34 using base::android::ConvertUTF16ToJavaString; 34 using base::android::ConvertUTF16ToJavaString;
35 using base::android::JavaParamRef; 35 using base::android::JavaParamRef;
36 using base::android::ScopedJavaLocalRef; 36 using base::android::ScopedJavaLocalRef;
37 37
38 namespace {
39
40 bool IsInfoEmpty(const std::unique_ptr<ShortcutInfo>& info) {
41 return !info || info->url.is_empty();
42 }
43
44 } // anonymous namespace
45
46 namespace banners { 38 namespace banners {
47 39
48 // static 40 // static
49 bool AppBannerInfoBarDelegateAndroid::Create( 41 bool AppBannerInfoBarDelegateAndroid::Create(
50 content::WebContents* web_contents, 42 content::WebContents* web_contents,
51 base::WeakPtr<AppBannerManager> weak_manager, 43 base::WeakPtr<AppBannerManager> weak_manager,
52 const base::string16& app_title, 44 const base::string16& app_title,
53 std::unique_ptr<ShortcutInfo> shortcut_info, 45 std::unique_ptr<ShortcutInfo> shortcut_info,
54 const SkBitmap& primary_icon, 46 const SkBitmap& primary_icon,
55 const SkBitmap& badge_icon, 47 const SkBitmap& badge_icon,
56 int event_request_id, 48 int event_request_id,
57 bool is_webapk, 49 bool is_webapk,
58 webapk::InstallSource webapk_install_source) { 50 webapk::InstallSource webapk_install_source) {
59 const GURL url = shortcut_info->url; 51 const GURL url = shortcut_info->url;
52 if (url.is_empty())
dominickn 2017/06/01 04:56:30 Nit: add DCHECK(shortcut_info) if we're going to a
pkotwicz 2017/06/01 05:11:28 This is unnecessary. Line 51 will crash if unique_
dominickn 2017/06/01 05:29:04 Yes, I know, but I prefer a DCHECK crash (which is
53 return false;
54
60 auto infobar_delegate = 55 auto infobar_delegate =
61 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( 56 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid(
62 weak_manager, app_title, std::move(shortcut_info), primary_icon, 57 weak_manager, app_title, std::move(shortcut_info), primary_icon,
63 badge_icon, event_request_id, is_webapk, webapk_install_source)); 58 badge_icon, event_request_id, is_webapk, webapk_install_source));
64 auto* raw_delegate = infobar_delegate.get(); 59 auto* raw_delegate = infobar_delegate.get();
65 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( 60 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>(
66 std::move(infobar_delegate), url, is_webapk); 61 std::move(infobar_delegate), url, is_webapk);
67 if (!InfoBarService::FromWebContents(web_contents) 62 if (!InfoBarService::FromWebContents(web_contents)
68 ->AddInfoBar(std::move(infobar))) 63 ->AddInfoBar(std::move(infobar)))
69 return false; 64 return false;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 app_title_(app_title), 213 app_title_(app_title),
219 shortcut_info_(std::move(shortcut_info)), 214 shortcut_info_(std::move(shortcut_info)),
220 primary_icon_(primary_icon), 215 primary_icon_(primary_icon),
221 badge_icon_(badge_icon), 216 badge_icon_(badge_icon),
222 event_request_id_(event_request_id), 217 event_request_id_(event_request_id),
223 has_user_interaction_(false), 218 has_user_interaction_(false),
224 is_webapk_(is_webapk), 219 is_webapk_(is_webapk),
225 install_state_(INSTALL_NOT_STARTED), 220 install_state_(INSTALL_NOT_STARTED),
226 webapk_install_source_(webapk_install_source), 221 webapk_install_source_(webapk_install_source),
227 weak_ptr_factory_(this) { 222 weak_ptr_factory_(this) {
228 DCHECK(!IsInfoEmpty(shortcut_info_));
229 CreateJavaDelegate(); 223 CreateJavaDelegate();
230 } 224 }
231 225
232 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( 226 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid(
233 const base::string16& app_title, 227 const base::string16& app_title,
234 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, 228 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data,
235 const SkBitmap& icon, 229 const SkBitmap& icon,
236 const std::string& native_app_package, 230 const std::string& native_app_package,
237 const std::string& referrer, 231 const std::string& referrer,
238 int event_request_id) 232 int event_request_id)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 TrackDismissEvent(DISMISS_EVENT_APP_OPEN); 267 TrackDismissEvent(DISMISS_EVENT_APP_OPEN);
274 else 268 else
275 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED); 269 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED);
276 270
277 SendBannerAccepted(); 271 SendBannerAccepted();
278 return was_opened; 272 return was_opened;
279 } 273 }
280 274
281 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( 275 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp(
282 content::WebContents* web_contents) { 276 content::WebContents* web_contents) {
283 if (IsInfoEmpty(shortcut_info_))
284 return true;
285 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); 277 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
286 278
287 AppBannerSettingsHelper::RecordBannerInstallEvent( 279 AppBannerSettingsHelper::RecordBannerInstallEvent(
288 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); 280 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
289 281
290 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_, 282 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, *shortcut_info_,
291 primary_icon_); 283 primary_icon_);
292 284
293 SendBannerAccepted(); 285 SendBannerAccepted();
294 return true; 286 return true;
295 } 287 }
296 288
297 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( 289 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk(
298 content::WebContents* web_contents) { 290 content::WebContents* web_contents) {
299 if (IsInfoEmpty(shortcut_info_))
300 return true;
301
302 JNIEnv* env = base::android::AttachCurrentThread(); 291 JNIEnv* env = base::android::AttachCurrentThread();
303 292
304 // If the WebAPK is installed and the "Open" button is clicked, open the 293 // If the WebAPK is installed and the "Open" button is clicked, open the
305 // WebAPK. Do not send a BannerAccepted message. 294 // WebAPK. Do not send a BannerAccepted message.
306 if (install_state_ == INSTALLED) { 295 if (install_state_ == INSTALLED) {
307 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_); 296 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_);
308 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); 297 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN);
309 return true; 298 return true;
310 } 299 }
311 300
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 455
467 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); 456 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK);
468 return true; 457 return true;
469 } 458 }
470 459
471 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { 460 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) {
472 return RegisterNativesImpl(env); 461 return RegisterNativesImpl(env);
473 } 462 }
474 463
475 } // namespace banners 464 } // namespace banners
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698