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

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

Issue 2301263004: Add WebAPK installation metrics. (Closed)
Patch Set: Update the metrics. Created 4 years, 3 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 25 matching lines...) Expand all
36 using base::android::ConvertUTF16ToJavaString; 36 using base::android::ConvertUTF16ToJavaString;
37 using base::android::JavaParamRef; 37 using base::android::JavaParamRef;
38 using base::android::ScopedJavaLocalRef; 38 using base::android::ScopedJavaLocalRef;
39 39
40 namespace { 40 namespace {
41 41
42 bool IsInfoEmpty(const ShortcutInfo* info) { 42 bool IsInfoEmpty(const ShortcutInfo* info) {
43 return !info || info->url.is_empty(); 43 return !info || info->url.is_empty();
44 } 44 }
45 45
46 void TrackWebApkInstallationDismissEvents(webapk::InstallState install_state) {
47 if (install_state == webapk::WAIT_FOR_START)
48 webapk::TrackInstallEvent(webapk::INSTALL_EVENT_ADD_TO_HOME_SCREEN_DISMISS);
49 else if (install_state == webapk::INSTALLING)
50 webapk::TrackInstallEvent(webapk::INSTALL_EVENT_ADDING_DISMISS);
dominickn 2016/09/09 08:14:11 Why is this method recording metrics in two differ
Xi Han 2016/09/09 15:37:32 Because the first two are recorded in the INSTALL_
51 else if (install_state == webapk::INSTALLED)
52 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN_DISMISS);
53 }
54
46 } // anonymous namespace 55 } // anonymous namespace
47 56
48 namespace banners { 57 namespace banners {
49 58
50 // static 59 // static
51 bool AppBannerInfoBarDelegateAndroid::Create( 60 bool AppBannerInfoBarDelegateAndroid::Create(
52 content::WebContents* web_contents, 61 content::WebContents* web_contents,
53 base::WeakPtr<AppBannerManager> weak_manager, 62 base::WeakPtr<AppBannerManager> weak_manager,
54 const base::string16& app_title, 63 const base::string16& app_title,
55 std::unique_ptr<ShortcutInfo> shortcut_info, 64 std::unique_ptr<ShortcutInfo> shortcut_info,
56 std::unique_ptr<SkBitmap> icon, 65 std::unique_ptr<SkBitmap> icon,
57 int event_request_id, 66 int event_request_id,
58 bool is_webapk, 67 bool is_webapk,
59 bool start_install_webapk) { 68 bool start_install_webapk) {
60 const GURL& url = shortcut_info->url; 69 const GURL& url = shortcut_info->url;
61 auto infobar_delegate = 70 auto infobar_delegate =
62 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( 71 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid(
63 weak_manager, app_title, std::move(shortcut_info), std::move(icon), 72 weak_manager, app_title, std::move(shortcut_info), std::move(icon),
64 event_request_id, is_webapk)); 73 event_request_id, is_webapk));
65 auto raw_delegate = infobar_delegate.get(); 74 auto raw_delegate = infobar_delegate.get();
66 75
67 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( 76 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>(
68 std::move(infobar_delegate), url, is_webapk); 77 std::move(infobar_delegate), url, is_webapk);
69 78
70 if (!InfoBarService::FromWebContents(web_contents) 79 if (!InfoBarService::FromWebContents(web_contents)
71 ->AddInfoBar(std::move(infobar))) 80 ->AddInfoBar(std::move(infobar)))
72 return false; 81 return false;
73 82
74 if (is_webapk && start_install_webapk) 83 if (is_webapk) {
75 raw_delegate->AcceptWebApk(web_contents); 84 if (start_install_webapk) {
85 raw_delegate->AcceptWebApk(web_contents);
86 webapk::TrackStartType(webapk::STARTED_FROM_ADD_TO_HOME_SCREEN_MENU);
87 } else {
88 webapk::TrackStartType(webapk::TRIGGERED_FROM_BANNER);
89 }
90 }
76 return true; 91 return true;
77 } 92 }
78 93
79 // static 94 // static
80 bool AppBannerInfoBarDelegateAndroid::Create( 95 bool AppBannerInfoBarDelegateAndroid::Create(
81 content::WebContents* web_contents, 96 content::WebContents* web_contents,
82 const base::string16& app_title, 97 const base::string16& app_title,
83 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, 98 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data,
84 std::unique_ptr<SkBitmap> icon, 99 std::unique_ptr<SkBitmap> icon,
85 const std::string& native_app_package, 100 const std::string& native_app_package,
86 const std::string& referrer, 101 const std::string& referrer,
87 int event_request_id) { 102 int event_request_id) {
88 auto infobar_delegate = base::WrapUnique(new AppBannerInfoBarDelegateAndroid( 103 auto infobar_delegate = base::WrapUnique(new AppBannerInfoBarDelegateAndroid(
89 app_title, native_app_data, std::move(icon), native_app_package, referrer, 104 app_title, native_app_data, std::move(icon), native_app_package, referrer,
90 event_request_id)); 105 event_request_id));
91 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( 106 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>(
92 std::move(infobar_delegate), native_app_data); 107 std::move(infobar_delegate), native_app_data);
93 108
94 return InfoBarService::FromWebContents(web_contents) 109 return InfoBarService::FromWebContents(web_contents)
95 ->AddInfoBar(std::move(infobar)); 110 ->AddInfoBar(std::move(infobar));
96 } 111 }
97 112
98 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { 113 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() {
99 weak_ptr_factory_.InvalidateWeakPtrs(); 114 weak_ptr_factory_.InvalidateWeakPtrs();
100 115
101 if (!has_user_interaction_) { 116 if (!has_user_interaction_) {
102 if (!native_app_data_.is_null()) 117 if (!native_app_data_.is_null()) {
103 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); 118 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED);
104 else if (!IsInfoEmpty(shortcut_info_.get())) 119 } else if (!IsInfoEmpty(shortcut_info_.get())) {
105 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); 120 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED);
121 if (is_webapk_)
122 webapk::TrackInstallEvent(webapk::INSTALL_EVENT_BANNER_IGNORED);
123 }
106 } 124 }
107 125
108 TrackDismissEvent(DISMISS_EVENT_DISMISSED); 126 TrackDismissEvent(DISMISS_EVENT_DISMISSED);
109 JNIEnv* env = base::android::AttachCurrentThread(); 127 JNIEnv* env = base::android::AttachCurrentThread();
110 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_); 128 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_);
111 java_delegate_.Reset(); 129 java_delegate_.Reset();
112 } 130 }
113 131
114 void AppBannerInfoBarDelegateAndroid::UpdateInstallState( 132 void AppBannerInfoBarDelegateAndroid::UpdateInstallState(
115 JNIEnv* env, 133 JNIEnv* env,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 if (IsInfoEmpty(shortcut_info_.get())) 191 if (IsInfoEmpty(shortcut_info_.get()))
174 return true; 192 return true;
175 193
176 JNIEnv* env = base::android::AttachCurrentThread(); 194 JNIEnv* env = base::android::AttachCurrentThread();
177 // |webapk_package_name_| is set when the WebAPK has finished installing. 195 // |webapk_package_name_| is set when the WebAPK has finished installing.
178 // If the |webapk_package_name_| is empty, it means the "Add to Homescreen" 196 // If the |webapk_package_name_| is empty, it means the "Add to Homescreen"
179 // button is pressed, so request WebAPK installation. Otherwise, it means 197 // button is pressed, so request WebAPK installation. Otherwise, it means
180 // the "Open" button is pressed, then open the installed WebAPK. 198 // the "Open" button is pressed, then open the installed WebAPK.
181 if (webapk_package_name_.empty()) { 199 if (webapk_package_name_.empty()) {
182 // Request install the WebAPK. 200 // Request install the WebAPK.
201 install_state_ = webapk::INSTALLING;
183 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); 202 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
184 203
185 AppBannerSettingsHelper::RecordBannerInstallEvent( 204 AppBannerSettingsHelper::RecordBannerInstallEvent(
186 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); 205 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
187 206
188 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( 207 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState(
189 env, java_delegate_, true); 208 env, java_delegate_, true);
190 UpdateInstallState(env, nullptr); 209 UpdateInstallState(env, nullptr);
191 210
192 WebApkInstaller::FinishCallback callback = 211 WebApkInstaller::FinishCallback callback =
193 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, 212 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished,
194 weak_ptr_factory_.GetWeakPtr()); 213 weak_ptr_factory_.GetWeakPtr());
195 DVLOG(1) << "Trigger the installation of the WebAPK."; 214 DVLOG(1) << "Trigger the installation of the WebAPK.";
196 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), 215 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(),
197 *shortcut_info_.get(), 216 *shortcut_info_.get(),
198 *icon_.get(), callback); 217 *icon_.get(), callback);
199 218
200 SendBannerAccepted(web_contents, "web"); 219 SendBannerAccepted(web_contents, "web");
201 // Returns false to prevent the infobar from disappearing. 220 // Returns false to prevent the infobar from disappearing.
202 return false; 221 return false;
203 } 222 }
204 223
205 // Open the WebAPK. 224 // Open the WebAPK.
206 ScopedJavaLocalRef<jstring> java_webapk_package_name = 225 ScopedJavaLocalRef<jstring> java_webapk_package_name =
207 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); 226 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_);
208 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, 227 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_,
209 java_webapk_package_name); 228 java_webapk_package_name);
210 229
211 SendBannerAccepted(web_contents, "web"); 230 SendBannerAccepted(web_contents, "web");
231 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN);
212 return true; 232 return true;
213 } 233 }
214 234
215 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( 235 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid(
216 base::WeakPtr<AppBannerManager> weak_manager, 236 base::WeakPtr<AppBannerManager> weak_manager,
217 const base::string16& app_title, 237 const base::string16& app_title,
218 std::unique_ptr<ShortcutInfo> shortcut_info, 238 std::unique_ptr<ShortcutInfo> shortcut_info,
219 std::unique_ptr<SkBitmap> icon, 239 std::unique_ptr<SkBitmap> icon,
220 int event_request_id, 240 int event_request_id,
221 bool is_webapk) 241 bool is_webapk)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 web_contents->GetMainFrame()->Send( 307 web_contents->GetMainFrame()->Send(
288 new ChromeViewMsg_AppBannerDismissed( 308 new ChromeViewMsg_AppBannerDismissed(
289 web_contents->GetMainFrame()->GetRoutingID(), 309 web_contents->GetMainFrame()->GetRoutingID(),
290 event_request_id_)); 310 event_request_id_));
291 311
292 if (!native_app_data_.is_null()) { 312 if (!native_app_data_.is_null()) {
293 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); 313 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED);
294 AppBannerSettingsHelper::RecordBannerDismissEvent( 314 AppBannerSettingsHelper::RecordBannerDismissEvent(
295 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE); 315 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE);
296 } else if (!IsInfoEmpty(shortcut_info_.get())) { 316 } else if (!IsInfoEmpty(shortcut_info_.get())) {
317 if (is_webapk_)
318 TrackWebApkInstallationDismissEvents(install_state_);
297 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); 319 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED);
298 AppBannerSettingsHelper::RecordBannerDismissEvent( 320 AppBannerSettingsHelper::RecordBannerDismissEvent(
299 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); 321 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
300 } 322 }
301 } 323 }
302 324
303 base::string16 AppBannerInfoBarDelegateAndroid::GetMessageText() const { 325 base::string16 AppBannerInfoBarDelegateAndroid::GetMessageText() const {
304 return app_title_; 326 return app_title_;
305 } 327 }
306 328
307 int AppBannerInfoBarDelegateAndroid::GetButtons() const { 329 int AppBannerInfoBarDelegateAndroid::GetButtons() const {
308 return BUTTON_OK; 330 return BUTTON_OK;
309 } 331 }
310 332
311 bool AppBannerInfoBarDelegateAndroid::Accept() { 333 bool AppBannerInfoBarDelegateAndroid::Accept() {
312 has_user_interaction_ = true; 334 has_user_interaction_ = true;
313 335
314 content::WebContents* web_contents = 336 content::WebContents* web_contents =
315 InfoBarService::WebContentsFromInfoBar(infobar()); 337 InfoBarService::WebContentsFromInfoBar(infobar());
316 if (!web_contents) { 338 if (!web_contents) {
317 TrackDismissEvent(DISMISS_EVENT_ERROR); 339 TrackDismissEvent(DISMISS_EVENT_ERROR);
318 return true; 340 return true;
319 } 341 }
320 342
321 if (!native_app_data_.is_null()) 343 if (!native_app_data_.is_null()) {
322 return AcceptNativeApp(web_contents); 344 return AcceptNativeApp(web_contents);
323 else if (is_webapk_) 345 } else if (is_webapk_) {
346 webapk::TrackStartType(webapk::STARTED_FROM_BANNER);
324 return AcceptWebApk(web_contents); 347 return AcceptWebApk(web_contents);
325 else 348 } else {
326 return AcceptWebApp(web_contents); 349 return AcceptWebApp(web_contents);
350 }
327 } 351 }
328 352
329 bool AppBannerInfoBarDelegateAndroid::AcceptNativeApp( 353 bool AppBannerInfoBarDelegateAndroid::AcceptNativeApp(
330 content::WebContents* web_contents) { 354 content::WebContents* web_contents) {
331 TrackUserResponse(USER_RESPONSE_NATIVE_APP_ACCEPTED); 355 TrackUserResponse(USER_RESPONSE_NATIVE_APP_ACCEPTED);
332 JNIEnv* env = base::android::AttachCurrentThread(); 356 JNIEnv* env = base::android::AttachCurrentThread();
333 357
334 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); 358 TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
335 if (tab == nullptr) { 359 if (tab == nullptr) {
336 TrackDismissEvent(DISMISS_EVENT_ERROR); 360 TrackDismissEvent(DISMISS_EVENT_ERROR);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( 400 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished(
377 bool success, 401 bool success,
378 const std::string& webapk_package_name) { 402 const std::string& webapk_package_name) {
379 JNIEnv* env = base::android::AttachCurrentThread(); 403 JNIEnv* env = base::android::AttachCurrentThread();
380 if (!success) { 404 if (!success) {
381 // The installation failed. 405 // The installation failed.
382 if (infobar()) 406 if (infobar())
383 infobar()->RemoveSelf(); 407 infobar()->RemoveSelf();
384 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); 408 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env);
385 DVLOG(1) << "The WebAPK installation failed."; 409 DVLOG(1) << "The WebAPK installation failed.";
410 webapk::TrackInstallEvent(webapk::INSTALL_EVENT_FAILED);
386 return; 411 return;
387 } 412 }
388 413
389 webapk_package_name_ = webapk_package_name; 414 webapk_package_name_ = webapk_package_name;
390 ScopedJavaLocalRef<jstring> java_webapk_package_name = 415 ScopedJavaLocalRef<jstring> java_webapk_package_name =
391 base::android::ConvertUTF8ToJavaString(env, webapk_package_name); 416 base::android::ConvertUTF8ToJavaString(env, webapk_package_name);
392 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( 417 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState(
393 env, java_delegate_, false); 418 env, java_delegate_, false);
394 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName( 419 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName(
395 env, java_delegate_, java_webapk_package_name); 420 env, java_delegate_, java_webapk_package_name);
396 UpdateInstallState(env, nullptr); 421 UpdateInstallState(env, nullptr);
422 install_state_ = webapk::INSTALLED;
423 webapk::TrackInstallEvent(webapk::INSTALL_EVENT_COMPLETED);
397 } 424 }
398 425
399 bool AppBannerInfoBarDelegateAndroid::LinkClicked( 426 bool AppBannerInfoBarDelegateAndroid::LinkClicked(
400 WindowOpenDisposition disposition) { 427 WindowOpenDisposition disposition) {
401 if (native_app_data_.is_null()) 428 if (native_app_data_.is_null())
402 return false; 429 return false;
403 430
404 // Try to show the details for the native app. 431 // Try to show the details for the native app.
405 JNIEnv* env = base::android::AttachCurrentThread(); 432 JNIEnv* env = base::android::AttachCurrentThread();
406 433
(...skipping 11 matching lines...) Expand all
418 445
419 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); 446 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK);
420 return true; 447 return true;
421 } 448 }
422 449
423 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { 450 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) {
424 return RegisterNativesImpl(env); 451 return RegisterNativesImpl(env);
425 } 452 }
426 453
427 } // namespace banners 454 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/android/banners/app_banner_infobar_delegate_android.h ('k') | chrome/browser/android/webapk/webapk_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698