Bug 1124943 - Changed methods in TilesRecorder to static, added a private constructor and removed the member instance in TopSitesPanel r=mcomella
authorJannis Pinter <jannis@pinterjann.is>
Sun, 22 Mar 2015 13:22:57 +0100
changeset 264567 bf13341538f76f5ebc254b51f20133efad96a908
parent 264566 d5fe53d4a359c5105b63d80554c79bb3233bf6b5
child 264568 1ce926882513cc01fdbc5913c3cfdfd77e62b276
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1124943
milestone39.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 1124943 - Changed methods in TilesRecorder to static, added a private constructor and removed the member instance in TopSitesPanel r=mcomella
mobile/android/base/home/TopSitesPanel.java
mobile/android/base/tiles/TilesRecorder.java
--- a/mobile/android/base/home/TopSitesPanel.java
+++ b/mobile/android/base/home/TopSitesPanel.java
@@ -98,19 +98,16 @@ public class TopSitesPanel extends HomeF
     private ThumbnailsLoaderCallbacks mThumbnailsLoaderCallbacks;
 
     // Listener for editing pinned sites.
     private EditPinnedSiteListener mEditPinnedSiteListener;
 
     // Max number of entries shown in the grid from the cursor.
     private int mMaxGridEntries;
 
-    // Fields used for tiles metrics recording.
-    private TilesRecorder mTilesRecorder;
-
     // Time in ms until the Gecko thread is reset to normal priority.
     private static final long PRIORITY_RESET_TIMEOUT = 10000;
 
     public static TopSitesPanel newInstance() {
         return new TopSitesPanel();
     }
 
     private static final boolean logDebug = Log.isLoggable(LOGTAG, Log.DEBUG);
@@ -128,18 +125,16 @@ public class TopSitesPanel extends HomeF
         }
     }
 
     @Override
     public void onAttach(Activity activity) {
         super.onAttach(activity);
 
         mMaxGridEntries = activity.getResources().getInteger(R.integer.number_of_top_sites);
-
-        mTilesRecorder = new TilesRecorder();
     }
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         final View view = inflater.inflate(R.layout.home_top_sites_panel, container, false);
 
         mList = (HomeListView) view.findViewById(R.id.list);
 
@@ -224,17 +219,17 @@ public class TopSitesPanel extends HomeF
                         }
                         Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, method, Integer.toString(position));
 
                         // Record tile click events on non-private tabs.
                         final Tab tab = Tabs.getInstance().getSelectedTab();
                         if (!tab.isPrivate()) {
                             final Locale locale = Locale.getDefault();
                             final String localeTag = Locales.getLanguageTag(locale);
-                            mTilesRecorder.recordAction(tab, TilesRecorder.ACTION_CLICK, position, getTilesSnapshot(), localeTag);
+                            TilesRecorder.recordAction(tab, TilesRecorder.ACTION_CLICK, position, getTilesSnapshot(), localeTag);
                         }
 
                         mUrlOpenListener.onUrlOpen(url, EnumSet.noneOf(OnUrlOpenListener.Flags.class));
                     }
                 } else {
                     if (mEditPinnedSiteListener != null) {
                         mEditPinnedSiteListener.onEditPinnedSite(position, "");
                     }
--- a/mobile/android/base/tiles/TilesRecorder.java
+++ b/mobile/android/base/tiles/TilesRecorder.java
@@ -17,17 +17,21 @@ import org.mozilla.gecko.Tab;
 import android.util.Log;
 
 public class TilesRecorder {
     public static final String ACTION_CLICK = "click";
 
     private static final String LOG_TAG = "GeckoTilesRecorder";
     private static final String EVENT_TILES_CLICK = "Tiles:Click";
 
-    public void recordAction(Tab tab, String action, int index, List<Tile> tiles, String locale) {
+    private TilesRecorder() {
+        // Empty private constructor to prevent construction
+    }
+
+    public static void recordAction(Tab tab, String action, int index, List<Tile> tiles, String locale) {
         final Tile clickedTile = tiles.get(index);
 
         if (tab == null || clickedTile == null) {
             throw new IllegalArgumentException("Tab and tile cannot be null");
         }
 
         if (clickedTile.id == -1) {
             // User clicked a non-distribution tile, so we don't need to report it.
@@ -74,17 +78,17 @@ public class TilesRecorder {
             data.put("payload", payload.toString());
 
             GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent(EVENT_TILES_CLICK, data.toString()));
         } catch (JSONException e) {
             Log.e(LOG_TAG, "JSON error", e);
         }
     }
 
-    private JSONObject jsonForTile(Tile tile, int tileIndex, int viewIndex) throws JSONException {
+    private static JSONObject jsonForTile(Tile tile, int tileIndex, int viewIndex) throws JSONException {
         final JSONObject tileJSON = new JSONObject();
 
         // Set the ID only if it is a distribution tile with a tracking ID.
         if (tile.id != -1) {
             tileJSON.put("id", tile.id);
         }
 
         // Set pinned to true only if the tile is pinned.