Bug 1265351 - HomeScreenPrompt: Save rejection and send telemetry only once. r=margaret
authorSebastian Kaspari <s.kaspari@gmail.com>
Mon, 18 Apr 2016 14:38:06 +0200
changeset 331629 6b2350929cdb675daf16baedf10e06f2dff008fb
parent 331628 29d7a174bdb4f63cb198b639d62a80fc6ea02dc6
child 331630 f271329c8fef6bedb9f52030d4fecf0632e18c36
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1265351
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1265351 - HomeScreenPrompt: Save rejection and send telemetry only once. r=margaret Additionally this patch: * unifies the telemetry for declining the prompt to always be: (cancel,back,'home_screen_promotion') * moves saving the rejection in the database to a background thread MozReview-Commit-ID: HywutUDtGcY
mobile/android/base/java/org/mozilla/gecko/promotion/HomeScreenPrompt.java
--- a/mobile/android/base/java/org/mozilla/gecko/promotion/HomeScreenPrompt.java
+++ b/mobile/android/base/java/org/mozilla/gecko/promotion/HomeScreenPrompt.java
@@ -41,16 +41,17 @@ public class HomeScreenPrompt extends Lo
     private static final String TELEMETRY_EXTRA = "home_screen_promotion";
 
     private View containerView;
     private ImageView iconView;
     private String title;
     private String url;
     private boolean isAnimating;
     private boolean hasAccepted;
+    private boolean hasDeclined;
 
     public static void show(Context context, String url, String title) {
         Intent intent = new Intent(context, HomeScreenPrompt.class);
         intent.putExtra(EXTRA_TITLE, title);
         intent.putExtra(EXTRA_URL, url);
         context.startActivity(intent);
     }
 
@@ -103,20 +104,17 @@ public class HomeScreenPrompt extends Lo
 
                 addToHomeScreen();
             }
         });
 
         findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                rememberRejection();
-                slideOut();
-
-                Telemetry.sendUIEvent(TelemetryContract.Event.CANCEL, TelemetryContract.Method.BUTTON, TELEMETRY_EXTRA);
+                onDecline();
             }
         });
     }
 
     private void addToHomeScreen() {
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
@@ -168,23 +166,23 @@ public class HomeScreenPrompt extends Lo
 
         set.start();
     }
 
     /**
      * Remember that the user rejected creating a home screen shortcut for this URL.
      */
     private void rememberRejection() {
-        if (hasAccepted) {
-            // User has already accepted to create a shortcut.
-            return;
-        }
-
-        final UrlAnnotations urlAnnotations = GeckoProfile.get(this).getDB().getUrlAnnotations();
-        urlAnnotations.insertHomeScreenShortcut(getContentResolver(), url, false);
+        ThreadUtils.postToBackgroundThread(new Runnable() {
+            @Override
+            public void run() {
+                final UrlAnnotations urlAnnotations = GeckoProfile.get(HomeScreenPrompt.this).getDB().getUrlAnnotations();
+                urlAnnotations.insertHomeScreenShortcut(getContentResolver(), url, false);
+            }
+        });
     }
 
     private void slideOut() {
         if (isAnimating) {
             return;
         }
 
         isAnimating = true;
@@ -205,33 +203,40 @@ public class HomeScreenPrompt extends Lo
         super.finish();
 
         // Don't perform an activity-dismiss animation.
         overridePendingTransition(0, 0);
     }
 
     @Override
     public void onBackPressed() {
+        onDecline();
+    }
+
+    private void onDecline() {
+        if (hasDeclined || hasAccepted) {
+            return;
+        }
+
         rememberRejection();
         slideOut();
 
+        // Technically not always an action triggered by the "back" button but with the same effect: Finishing this
+        // activity and going back to the previous one.
         Telemetry.sendUIEvent(TelemetryContract.Event.CANCEL, TelemetryContract.Method.BACK, TELEMETRY_EXTRA);
+
+        hasDeclined = true;
     }
 
     /**
      * User clicked outside of the prompt.
      */
     @Override
     public boolean onTouchEvent(MotionEvent event) {
-        rememberRejection();
-        slideOut();
-
-        // Not really an action triggered by the "back" button but with the same effect: Finishing this
-        // activity and going back to the previous one.
-        Telemetry.sendUIEvent(TelemetryContract.Event.CANCEL, TelemetryContract.Method.BACK, TELEMETRY_EXTRA);
+        onDecline();
 
         return true;
     }
 
     @Override
     public void onFaviconLoaded(String url, String faviconURL, final Bitmap favicon) {
         if (favicon == null) {
             return;