1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.components.gcm_driver;
7 import android.content.Intent;
9 import com.google.ipc.invalidation.external.client.contrib.MultiplexingGcmListener;
11 import org.chromium.base.ThreadUtils;
14 * Receives GCM registration events and messages rebroadcast by MultiplexingGcmListener.
16 public class GCMListener extends MultiplexingGcmListener.AbstractListener {
18 * Receiver for broadcasts by the multiplexed GCM service. It forwards them to
21 * This class is public so that it can be instantiated by the Android runtime.
23 public static class Receiver extends MultiplexingGcmListener.AbstractListener.Receiver {
25 protected Class<?> getServiceClass() {
26 return GCMListener.class;
30 private static final String TAG = "GCMListener";
32 // Used as a fallback since GCM doesn't yet give us the app ID.
33 // TODO(johnme): Get real app IDs from GCM, and remove this.
34 private static final String UNKNOWN_APP_ID = "push#https://www.gcmlistenerfake.com#0";
36 public GCMListener() {
41 protected void onRegistered(final String registrationId) {
42 ThreadUtils.runOnUiThread(new Runnable() {
43 @Override public void run() {
44 GCMDriver.onRegisterFinished(UNKNOWN_APP_ID, registrationId);
50 protected void onUnregistered(String registrationId) {
51 ThreadUtils.runOnUiThread(new Runnable() {
52 @Override public void run() {
53 GCMDriver.onUnregisterFinished(UNKNOWN_APP_ID);
59 protected void onMessage(final Intent intent) {
60 ThreadUtils.runOnUiThread(new Runnable() {
61 @Override public void run() {
62 GCMDriver.onMessageReceived(getApplicationContext(), UNKNOWN_APP_ID,
69 protected void onDeletedMessages(int total) {
70 ThreadUtils.runOnUiThread(new Runnable() {
71 @Override public void run() {
72 GCMDriver.onMessagesDeleted(getApplicationContext(), UNKNOWN_APP_ID);