Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / gcm_driver / android / java / src / org / chromium / components / gcm_driver / GCMListener.java
index 134712e..83d2972 100644 (file)
@@ -5,6 +5,7 @@
 package org.chromium.components.gcm_driver;
 
 import android.content.Intent;
+import android.os.Bundle;
 
 import com.google.ipc.invalidation.external.client.contrib.MultiplexingGcmListener;
 
@@ -29,38 +30,42 @@ public class GCMListener extends MultiplexingGcmListener.AbstractListener {
 
     private static final String TAG = "GCMListener";
 
-    // Used as a fallback since GCM doesn't yet give us the app ID.
-    // TODO(johnme): Get real app IDs from GCM, and remove this.
-    private static final String UNKNOWN_APP_ID = "push#https://www.gcmlistenerfake.com#0";
+    // Used as a fallback until GCM always gives us the subtype.
+    // TODO(johnme): Remove this once it does.
+    static final String UNKNOWN_APP_ID = "push#https://www.gcmlistenerfake.com#0";
 
     public GCMListener() {
         super(TAG);
     }
 
     @Override
-    protected void onRegistered(final String registrationId) {
-        ThreadUtils.runOnUiThread(new Runnable() {
-            @Override public void run() {
-                GCMDriver.onRegisterFinished(UNKNOWN_APP_ID, registrationId);
-            }
-        });
+    protected void onRegistered(String registrationId) {
+        // Ignore this, since we register using GoogleCloudMessagingV2.
     }
 
     @Override
     protected void onUnregistered(String registrationId) {
-        ThreadUtils.runOnUiThread(new Runnable() {
-            @Override public void run() {
-                GCMDriver.onUnregisterFinished(UNKNOWN_APP_ID);
-            }
-        });
+        // Ignore this, since we register using GoogleCloudMessagingV2.
     }
 
     @Override
     protected void onMessage(final Intent intent) {
+        final String bundleSubtype = "subtype";
+        final String bundleDataForPushApi = "data";
+        Bundle extras = intent.getExtras();
+        if (!extras.containsKey(bundleSubtype) && !extras.containsKey(bundleDataForPushApi)) {
+            // TODO(johnme): Once GCM always gives us the subtype, we'll be able to early-out if
+            // there is no subtype extra. For now we have to also allow messages without subtype
+            // if they have the data key which suggests they are for the Push API, but this is
+            // technically a layering violation as this code is for other consumers of GCM too.
+            return;
+        }
+        final String appId = extras.containsKey(bundleSubtype) ? extras.getString(bundleSubtype)
+                                                               : UNKNOWN_APP_ID;
         ThreadUtils.runOnUiThread(new Runnable() {
             @Override public void run() {
-                GCMDriver.onMessageReceived(getApplicationContext(), UNKNOWN_APP_ID,
-                    intent.getExtras());
+                GCMDriver.onMessageReceived(getApplicationContext(), appId,
+                        intent.getExtras());
             }
         });
     }