Bug 1041632 - Part 8: eliminate enclosing instance member access in PrefsHelper. r=ckitching
authorRichard Newman <rnewman@mozilla.com>
Mon, 21 Jul 2014 10:24:15 -0700
changeset 195371 278e109b79f5f363cd90b4da473ec49f249ffb51
parent 195370 827990281932854dbb5fdb350a9903a5a64bf7b1
child 195372 0234ad055a7b978dd0a9a43561ee9f1a701d1061
push id46575
push userkwierso@gmail.com
push dateTue, 22 Jul 2014 00:35:21 +0000
treeherdermozilla-inbound@fee5c4bdd713 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckitching
bugs1041632
milestone33.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 1041632 - Part 8: eliminate enclosing instance member access in PrefsHelper. r=ckitching
mobile/android/base/PrefsHelper.java
--- a/mobile/android/base/PrefsHelper.java
+++ b/mobile/android/base/PrefsHelper.java
@@ -18,18 +18,18 @@ import java.util.ArrayList;
 
 /**
  * Helper class to get/set gecko prefs.
  */
 public final class PrefsHelper {
     private static final String LOGTAG = "GeckoPrefsHelper";
 
     private static boolean sRegistered = false;
-    private static final SparseArray<PrefHandler> sCallbacks = new SparseArray<PrefHandler>();
     private static int sUniqueRequestId = 1;
+    /* inner-access */ static final SparseArray<PrefHandler> sCallbacks = new SparseArray<PrefHandler>();
 
     public static int getPref(String prefName, PrefHandler callback) {
         return getPrefsInternal(new String[] { prefName }, callback);
     }
 
     public static int getPrefs(String[] prefNames, PrefHandler callback) {
         return getPrefsInternal(prefNames, callback);
     }
@@ -58,31 +58,33 @@ public final class PrefsHelper {
         return requestId;
     }
 
     private static void ensureRegistered() {
         if (sRegistered) {
             return;
         }
 
-        EventDispatcher.getInstance().registerGeckoThreadListener(new GeckoEventListener() {
-            @Override public void handleMessage(String event, JSONObject message) {
+        GeckoEventListener listener = new GeckoEventListener() {
+            @Override
+            public void handleMessage(String event, JSONObject message) {
                 try {
                     PrefHandler callback;
                     synchronized (PrefsHelper.class) {
                         try {
                             int requestId = message.getInt("requestId");
                             callback = sCallbacks.get(requestId);
                             if (callback != null && !callback.isObserver()) {
                                 sCallbacks.delete(requestId);
                             }
                         } catch (Exception e) {
                             callback = null;
                         }
                     }
+
                     if (callback == null) {
                         Log.d(LOGTAG, "Preferences:Data message had an unknown requestId; ignoring");
                         return;
                     }
 
                     JSONArray jsonPrefs = message.getJSONArray("preferences");
                     for (int i = 0; i < jsonPrefs.length(); i++) {
                         JSONObject pref = jsonPrefs.getJSONObject(i);
@@ -102,17 +104,18 @@ public final class PrefsHelper {
                             Log.e(LOGTAG, "Handler for preference [" + name + "] threw exception", e);
                         }
                     }
                     callback.finish();
                 } catch (Exception e) {
                     Log.e(LOGTAG, "Error handling Preferences:Data message", e);
                 }
             }
-        }, "Preferences:Data");
+        };
+        EventDispatcher.getInstance().registerGeckoThreadListener(listener, "Preferences:Data");
         sRegistered = true;
     }
 
     public static void setPref(String pref, Object value) {
         if (pref == null || pref.length() == 0) {
             throw new IllegalArgumentException("Pref name must be non-empty");
         }