Bug 1251362 - Part 14 - Add telemetry for restoring tabs. r=liuche
authorJan Henning <jh+bugzilla@buttercookie.de>
Wed, 18 May 2016 19:04:49 +0200
changeset 301167 1060ef1606c577ac10f6686aba08925d79847cfe
parent 301166 85eee022eb7d957112571226dbe89882a5799852
child 301168 e2b22babd7b3b15e21e9e325bff5ef386611adc7
push id78241
push userkwierso@gmail.com
push dateThu, 09 Jun 2016 00:09:10 +0000
treeherdermozilla-inbound@2c66b75bbb7f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1251362
milestone50.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 1251362 - Part 14 - Add telemetry for restoring tabs. r=liuche This adds telemetry for clicking on a closed tab or the "Open all" button. Methods and extras strings are based on those used for the old Recent Tabs panel. MozReview-Commit-ID: 1Kc8fACkmIc
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java
mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -420,17 +420,20 @@ public class CombinedHistoryPanel extend
                     mRecentTabsAdapter.clearLastSessionData();
                             Telemetry.sendUIEvent(TelemetryContract.Event.SANITIZE, TelemetryContract.Method.BUTTON, "history");
                         }
                     });
 
                     dialogBuilder.show();
                     break;
                 case CHILD_RECENT_TABS:
-                    mRecentTabsAdapter.restoreAllTabs();
+                    final String telemetryExtra = mRecentTabsAdapter.restoreAllTabs();
+                    if (telemetryExtra != null) {
+                        Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.BUTTON, telemetryExtra);
+                    }
                     break;
             }
         }
     }
 
     private void updateEmptyView() {
         boolean showEmptyHistoryView = false;
         boolean showEmptyClientsView = false;
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java
@@ -85,16 +85,17 @@ public class CombinedHistoryRecyclerView
     public void setHiddenClientsDialogBuilder(CombinedHistoryPanel.DialogBuilder<RemoteClient> builder) {
         mDialogBuilder = builder;
     }
 
     @Override
     public void onItemClicked(RecyclerView recyclerView, int position, View v) {
         final int viewType = getAdapter().getItemViewType(position);
         final CombinedHistoryItem.ItemType itemType = CombinedHistoryItem.ItemType.viewTypeToItemType(viewType);
+        final String telemetryExtra;
 
         switch (itemType) {
             case RECENT_TABS:
                 mOnPanelLevelChangeListener.changeLevel(CHILD_RECENT_TABS);
                 break;
 
             case SYNCED_DEVICES:
                 mOnPanelLevelChangeListener.changeLevel(CHILD_SYNC);
@@ -119,17 +120,18 @@ public class CombinedHistoryRecyclerView
                 if (mOnUrlOpenListener != null) {
                     final TwoLinePageRow historyItem = (TwoLinePageRow) v;
                     Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM, "history");
                     mOnUrlOpenListener.onUrlOpen(historyItem.getUrl(), EnumSet.of(HomePager.OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB));
                 }
                 break;
 
             case CLOSED_TAB:
-                ((RecentTabsAdapter) getAdapter()).restoreTabFromPosition(position);
+                telemetryExtra = ((RecentTabsAdapter) getAdapter()).restoreTabFromPosition(position);
+                Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM, telemetryExtra);
                 break;
         }
     }
 
     @Override
     public boolean onItemLongClicked(RecyclerView recyclerView, int position, View v) {
         mContextMenuInfo = ((AdapterContextMenuBuilder) getAdapter()).makeContextMenuInfoFromPosition(v, position);
         return showContextMenuForChild(this);
--- a/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
@@ -35,16 +35,20 @@ import java.util.List;
 import static org.mozilla.gecko.home.CombinedHistoryItem.ItemType;
 
 public class RecentTabsAdapter extends RecyclerView.Adapter<CombinedHistoryItem>
                                implements CombinedHistoryRecyclerView.AdapterContextMenuBuilder, NativeEventListener {
     private static final String LOGTAG = "GeckoRecentTabsAdapter";
 
     private static final int NAVIGATION_BACK_BUTTON_INDEX = 0;
 
+    private static final String TELEMETRY_EXTRA_LAST_TIME = "recent_tabs_last_time";
+    private static final String TELEMETRY_EXTRA_RECENTY_CLOSED = "recent_closed_tabs";
+    private static final String TELEMETRY_EXTRA_MIXED = "recent_tabs_mixed";
+
     // Recently closed tabs from Gecko.
     private ClosedTab[] recentlyClosedTabs;
 
     // "Tabs from last time".
     private ClosedTab[] lastSessionTabs;
 
     public static final class ClosedTab {
         public final String url;
@@ -228,32 +232,43 @@ public class RecentTabsAdapter extends R
             notifyItemRangeRemoved(lastTabListIndex + 1, -closedTabsCountChange); // Remove tabs from the bottom of the list.
             notifyItemRangeChanged(firstTabListIndex, closedTabsCount); // Update the contents of the remaining items.
         } else { // closedTabsCountChange > 0
             notifyItemRangeInserted(firstTabListIndex, closedTabsCountChange); // Add additional tabs at the top of the list.
             notifyItemRangeChanged(firstTabListIndex + closedTabsCountChange, prevClosedTabsCount); // Update any previous list items.
         }
     }
 
-    public void restoreTabFromPosition(int position) {
+    public String restoreTabFromPosition(int position) {
         final List<String> dataList = new ArrayList<>(1);
         dataList.add(getClosedTabForPosition(position).data);
+
+        final String telemetryExtra =
+                position > getLastRecentTabIndex() ? TELEMETRY_EXTRA_LAST_TIME : TELEMETRY_EXTRA_RECENTY_CLOSED;
+
         restoreSessionWithHistory(dataList);
+
+        return telemetryExtra;
     }
 
-    public void restoreAllTabs() {
+    public String restoreAllTabs() {
         if (recentlyClosedTabs.length == 0 && lastSessionTabs.length == 0) {
-            return;
+            return null;
         }
 
         final List<String> dataList = new ArrayList<>(getClosedTabsCount());
         addTabDataToList(dataList, recentlyClosedTabs);
         addTabDataToList(dataList, lastSessionTabs);
 
+        final String telemetryExtra = recentlyClosedTabs.length > 0 && lastSessionTabs.length > 0 ? TELEMETRY_EXTRA_MIXED :
+                recentlyClosedTabs.length > 0 ? TELEMETRY_EXTRA_RECENTY_CLOSED : TELEMETRY_EXTRA_LAST_TIME;
+
         restoreSessionWithHistory(dataList);
+
+        return telemetryExtra;
     }
 
     private void addTabDataToList(List<String> dataList, ClosedTab[] closedTabs) {
         for (ClosedTab closedTab : closedTabs) {
             dataList.add(closedTab.data);
         }
     }