Index: components/gcm_driver/android/java/src/org/chromium/components/gcm_driver/GCMListener.java |
diff --git a/components/gcm_driver/android/java/src/org/chromium/components/gcm_driver/GCMListener.java b/components/gcm_driver/android/java/src/org/chromium/components/gcm_driver/GCMListener.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d3cb556f930e9155ced28ea364ca0ec0e3a4d433 |
--- /dev/null |
+++ b/components/gcm_driver/android/java/src/org/chromium/components/gcm_driver/GCMListener.java |
@@ -0,0 +1,75 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.components.gcm_driver; |
+ |
+import android.content.Intent; |
+ |
+import com.google.ipc.invalidation.external.client.contrib.MultiplexingGcmListener; |
+ |
+import org.chromium.base.ThreadUtils; |
+ |
+/** |
+ * Receives GCM registration events and messages rebroadcast by MultiplexingGcmListener. |
+ */ |
+public class GCMListener extends MultiplexingGcmListener.AbstractListener { |
+ /** |
+ * Receiver for broadcasts by the multiplexed GCM service. It forwards them to |
+ * GCMListener. |
+ * |
+ * This class is public so that it can be instantiated by the Android runtime. |
+ */ |
+ public static class Receiver extends MultiplexingGcmListener.AbstractListener.Receiver { |
+ @Override |
+ protected Class<?> getServiceClass() { |
+ return GCMListener.class; |
+ } |
+ } |
+ |
+ private static final String TAG = "GCMListener"; |
+ |
+ public GCMListener() { |
+ super(TAG); |
+ } |
+ |
+ @Override |
+ protected void onRegistered(final String registrationId) { |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override public void run() { |
+ // TODO(johnme): Get app ID. |
+ GCMDriver.onRegisterFinished("unknown-app-id", registrationId); |
+ } |
+ }); |
+ } |
+ |
+ @Override |
+ protected void onUnregistered(String registrationId) { |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override public void run() { |
+ // TODO(johnme): Get app ID. |
+ GCMDriver.onUnregisterFinished("unknown-app-id"); |
+ } |
+ }); |
+ } |
+ |
+ @Override |
+ protected void onMessage(final Intent intent) { |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override public void run() { |
+ // TODO(johnme): Get app ID. |
+ GCMDriver.onMessageReceived("unknown-app-id", intent.getExtras()); |
+ } |
+ }); |
+ } |
+ |
+ @Override |
+ protected void onDeletedMessages(int total) { |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override public void run() { |
+ // TODO(johnme): Get app ID. |
+ GCMDriver.onMessagesDeleted("unknown-app-id"); |
+ } |
+ }); |
+ } |
+} |