Bug 1280446 - Create PushService if needed; r=snorp
authorJim Chen <nchen@mozilla.com>
Tue, 05 Jul 2016 14:34:57 -0400
changeset 303791 29386385b953468a720cbd610c0713a233fb6c46
parent 303731 3db27bf874fa9e5057b7bcb96f325699bb7f1688
child 303792 0a3a72e9ecba8af5dc1063c8edb8cdb1546a4ef0
push id30402
push usercbook@mozilla.com
push dateWed, 06 Jul 2016 09:42:05 +0000
treeherdermozilla-central@95ffbc4ff635 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1280446
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 1280446 - Create PushService if needed; r=snorp If PushService has not been created when getInstance is called, create the PushService instead of throwing an error. This fixes a possible race condition between initializing PushService and receiving a push message, where we can receive a push message first.
mobile/android/base/java/org/mozilla/gecko/gcm/GcmInstanceIDListenerService.java
mobile/android/base/java/org/mozilla/gecko/gcm/GcmMessageListenerService.java
mobile/android/base/java/org/mozilla/gecko/push/PushService.java
--- a/mobile/android/base/java/org/mozilla/gecko/gcm/GcmInstanceIDListenerService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gcm/GcmInstanceIDListenerService.java
@@ -23,13 +23,13 @@ public class GcmInstanceIDListenerServic
      * InstanceID provider.
      */
     @Override
     public void onTokenRefresh() {
         Log.d("GeckoPushGCM", "Token refresh request received.  Processing on background thread.");
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
-                PushService.getInstance().onRefresh();
+                PushService.getInstance(GcmInstanceIDListenerService.this).onRefresh();
             }
         });
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/gcm/GcmMessageListenerService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gcm/GcmMessageListenerService.java
@@ -25,14 +25,14 @@ public class GcmMessageListenerService e
      * @param bundle Data bundle containing message data as key/value pairs.
      */
     @Override
     public void onMessageReceived(final String from, final Bundle bundle) {
         Log.d("GeckoPushGCM", "Message received.  Processing on background thread.");
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
-                PushService.getInstance().onMessageReceived(
+                PushService.getInstance(GcmMessageListenerService.this).onMessageReceived(
                         GcmMessageListenerService.this, bundle);
             }
         });
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/push/PushService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/push/PushService.java
@@ -61,19 +61,19 @@ public class PushService implements Bund
             "PushServiceAndroidGCM:Uninitialized",
             "PushServiceAndroidGCM:RegisterUserAgent",
             "PushServiceAndroidGCM:UnregisterUserAgent",
             "PushServiceAndroidGCM:SubscribeChannel",
             "PushServiceAndroidGCM:UnsubscribeChannel",
             "History:GetPrePathLastVisitedTimeMilliseconds",
     };
 
-    public static synchronized PushService getInstance() {
+    public static synchronized PushService getInstance(Context context) {
         if (sInstance == null) {
-            throw new IllegalStateException("PushService not yet created!");
+            onCreate(context);
         }
         return sInstance;
     }
 
     @ReflectionTarget
     public static synchronized void onCreate(Context context) {
         if (sInstance != null) {
             throw new IllegalStateException("PushService already created!");