Bug 1267419 - Move PushRecord.getLastVisit handler to PushService.java; r=nalexander, a=sylvestre
☠☠ backed out by 59db6ee36a99 ☠ ☠
authorJim Chen <nchen@mozilla.com>
Tue, 26 Apr 2016 15:34:17 -0400
changeset 333140 61314f00fede1a8e67a27e8169df43af2cf8eddf
parent 333139 125947b0ec85f5d8f5c1ba5849bd096e57437a15
child 333141 3ff74bec4cc8e09bcc0b20c1a9a60a875336ff4a
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)
reviewersnalexander, sylvestre
bugs1267419
milestone48.0a2
Bug 1267419 - Move PushRecord.getLastVisit handler to PushService.java; r=nalexander, a=sylvestre The Android-specific handler for PushRecord.getLastVisit used to be implemented in GeckoApp, which is unavailable in headless mode. Moving the handler to PushService makes background notifications work.
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/push/PushService.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -31,17 +31,16 @@ import org.mozilla.gecko.preferences.Gec
 import org.mozilla.gecko.prompts.PromptService;
 import org.mozilla.gecko.restrictions.Restrictions;
 import org.mozilla.gecko.tabqueue.TabQueueHelper;
 import org.mozilla.gecko.text.FloatingToolbarTextSelection;
 import org.mozilla.gecko.text.TextSelection;
 import org.mozilla.gecko.updater.UpdateServiceHelper;
 import org.mozilla.gecko.util.ActivityResultHandler;
 import org.mozilla.gecko.util.ActivityUtils;
-import org.mozilla.gecko.util.BundleEventListener;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.FileUtils;
 import org.mozilla.gecko.util.GeckoEventListener;
 import org.mozilla.gecko.util.GeckoRequest;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.NativeEventListener;
 import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.PrefUtils;
@@ -122,17 +121,16 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
 public abstract class GeckoApp
     extends GeckoActivity
     implements
-    BundleEventListener,
     ContextGetter,
     GeckoAppShell.GeckoInterface,
     GeckoEventListener,
     GeckoMenu.Callback,
     GeckoMenu.MenuPresenter,
     LocationListener,
     NativeEventListener,
     SensorEventListener,
@@ -703,34 +701,16 @@ public abstract class GeckoApp
             } else if (event.equals("Accessibility:Event")) {
                 GeckoAccessibility.sendAccessibilityEvent(message);
             }
         } catch (Exception e) {
             Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
         }
     }
 
-    @Override
-    public void handleMessage(final String event, final Bundle message, final EventCallback callback) {
-        if ("History:GetPrePathLastVisitedTimeMilliseconds".equals(event)) {
-            if (callback == null) {
-                Log.e(LOGTAG, "callback must not be null in " + event);
-                return;
-            }
-            final String prePath = message.getString("prePath");
-            if (prePath == null) {
-                callback.sendError("prePath must not be null in " + event);
-                return;
-            }
-            // We're on a background thread, so we can be synchronous.
-            final long millis = getProfile().getDB().getPrePathLastVisitedTimeMilliseconds(getContentResolver(), prePath);
-            callback.sendSuccess(millis);
-        }
-    }
-
     void onStatePurged() { }
 
     /**
      * @param permissions
      *        Array of JSON objects to represent site permissions.
      *        Example: { type: "offline-app", setting: "Store Offline Data", value: "Allow" }
      */
     private void showSiteSettingsDialog(final NativeJSObject[] permissions) {
@@ -1234,19 +1214,16 @@ public abstract class GeckoApp
             "SystemUI:Visibility",
             "ToggleChrome:Focus",
             "ToggleChrome:Hide",
             "ToggleChrome:Show",
             "Update:Check",
             "Update:Download",
             "Update:Install");
 
-        EventDispatcher.getInstance().registerBackgroundThreadListener((BundleEventListener) this,
-                "History:GetPrePathLastVisitedTimeMilliseconds");
-
         GeckoThread.launch();
 
         Bundle stateBundle = ContextUtils.getBundleExtra(getIntent(), EXTRA_STATE_BUNDLE);
         if (stateBundle != null) {
             // Use the state bundle if it was given as an intent extra. This is
             // only intended to be used internally via Robocop, so a boolean
             // is read from a private shared pref to prevent other apps from
             // injecting states.
@@ -2135,19 +2112,16 @@ public abstract class GeckoApp
             "SystemUI:Visibility",
             "ToggleChrome:Focus",
             "ToggleChrome:Hide",
             "ToggleChrome:Show",
             "Update:Check",
             "Update:Download",
             "Update:Install");
 
-        EventDispatcher.getInstance().unregisterBackgroundThreadListener((BundleEventListener) this,
-                "History:GetPrePathLastVisitedTimeMilliseconds");
-
         deleteTempFiles();
 
         if (mDoorHangerPopup != null)
             mDoorHangerPopup.destroy();
         if (mFormAssistPopup != null)
             mFormAssistPopup.destroy();
         if (mContactService != null)
             mContactService.destroy();
--- a/mobile/android/base/java/org/mozilla/gecko/push/PushService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/push/PushService.java
@@ -58,16 +58,17 @@ public class PushService implements Bund
             "PushServiceAndroidGCM:DumpRegistration",
             "PushServiceAndroidGCM:DumpSubscriptions",
             "PushServiceAndroidGCM:Initialized",
             "PushServiceAndroidGCM:Uninitialized",
             "PushServiceAndroidGCM:RegisterUserAgent",
             "PushServiceAndroidGCM:UnregisterUserAgent",
             "PushServiceAndroidGCM:SubscribeChannel",
             "PushServiceAndroidGCM:UnsubscribeChannel",
+            "History:GetPrePathLastVisitedTimeMilliseconds",
     };
 
     public static synchronized PushService getInstance() {
         if (sInstance == null) {
             throw new IllegalStateException("PushService not yet created!");
         }
         return sInstance;
     }
@@ -225,19 +226,20 @@ public class PushService implements Bund
         EventDispatcher.getInstance().unregisterBackgroundThreadListener(this, GECKO_EVENTS);
     }
 
     @Override
     public void handleMessage(final String event, final Bundle message, final EventCallback callback) {
         Log.i(LOG_TAG, "Handling event: " + event);
         ThreadUtils.assertOnBackgroundThread();
 
+        final Context context = GeckoAppShell.getApplicationContext();
         // We're invoked in response to a Gecko message on a background thread.  We should always
         // be able to safely retrieve the current Gecko profile.
-        final GeckoProfile geckoProfile = GeckoProfile.get(GeckoAppShell.getApplicationContext());
+        final GeckoProfile geckoProfile = GeckoProfile.get(context);
 
         if (callback == null) {
             Log.e(LOG_TAG, "callback must not be null in " + event);
             return;
         }
 
         try {
             if ("PushServiceAndroidGCM:Configure".equals(event)) {
@@ -356,16 +358,32 @@ public class PushService implements Bund
                     Telemetry.sendUIEvent(TelemetryContract.Event.UNSAVE, TelemetryContract.Method.SERVICE, "dom-push-api");
                     callback.sendSuccess(null);
                     return;
                 }
 
                 callback.sendError("Could not unsubscribe from channel: " + channelID);
                 return;
             }
+            if ("History:GetPrePathLastVisitedTimeMilliseconds".equals(event)) {
+                if (callback == null) {
+                    Log.e(LOG_TAG, "callback must not be null in " + event);
+                    return;
+                }
+                final String prePath = message.getString("prePath");
+                if (prePath == null) {
+                    callback.sendError("prePath must not be null in " + event);
+                    return;
+                }
+                // We're on a background thread, so we can be synchronous.
+                final long millis = geckoProfile.getDB().getPrePathLastVisitedTimeMilliseconds(
+                        context.getContentResolver(), prePath);
+                callback.sendSuccess(millis);
+                return;
+            }
         } catch (GcmTokenClient.NeedsGooglePlayServicesException e) {
             // TODO: improve this.  Can we find a point where the user is *definitely* interacting
             // with the WebPush?  Perhaps we can show a dialog when interacting with the Push
             // permissions, and then be more aggressive showing this notification when we have
             // registrations and subscriptions that can't be advanced.
             callback.sendError("To handle event [" + event + "], user interaction is needed to enable Google Play Services.");
         }
     }