diff options
author | nyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-14 10:24:26 +0000 |
---|---|---|
committer | nyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-14 10:24:26 +0000 |
commit | fe37ec4a5c8e15bff478e9da9b85fccfadd35bd4 (patch) | |
tree | 962e98aef20ba6a377857bc0080d64848767f74c /sync/android | |
parent | 710d45e84031c7ce7b2d37c6ff45fd67f99845b1 (diff) | |
download | chromium_src-fe37ec4a5c8e15bff478e9da9b85fccfadd35bd4.zip chromium_src-fe37ec4a5c8e15bff478e9da9b85fccfadd35bd4.tar.gz chromium_src-fe37ec4a5c8e15bff478e9da9b85fccfadd35bd4.tar.bz2 |
Add functionality to enable GCM.
Whenever Chrome uses GCM it has to be enabled. This adds the
functionality to do so to the ChromeSigninController, since using GCM is
mostly used together with a signed in user.
BUG=272584
Review URL: https://chromiumcodereview.appspot.com/23156002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217522 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/android')
-rw-r--r-- | sync/android/java/src/org/chromium/sync/signin/ChromeSigninController.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/sync/android/java/src/org/chromium/sync/signin/ChromeSigninController.java b/sync/android/java/src/org/chromium/sync/signin/ChromeSigninController.java index a9a1b82..03805ec 100644 --- a/sync/android/java/src/org/chromium/sync/signin/ChromeSigninController.java +++ b/sync/android/java/src/org/chromium/sync/signin/ChromeSigninController.java @@ -6,10 +6,12 @@ package org.chromium.sync.signin; import android.accounts.Account; import android.content.Context; +import android.os.AsyncTask; import android.preference.PreferenceManager; import android.util.Log; import com.google.common.annotations.VisibleForTesting; +import com.google.ipc.invalidation.external.client.contrib.MultiplexingGcmListener; import org.chromium.base.ObserverList; @@ -34,6 +36,8 @@ public class ChromeSigninController { private final ObserverList<Listener> mListeners = new ObserverList<Listener>(); + private boolean mGcmInitialized; + private ChromeSigninController(Context context) { mApplicationContext = context.getApplicationContext(); } @@ -100,4 +104,29 @@ public class ChromeSigninController { public void removeListener(Listener listener) { mListeners.removeObserver(listener); } + + /** + * Registers for Google Cloud Messaging (GCM) if there is no existing registration. + */ + public void ensureGcmIsInitialized() { + if (mGcmInitialized) return; + mGcmInitialized = true; + new AsyncTask<Void, Void, Void>() { + @Override + protected Void doInBackground(Void... arg0) { + try { + String regId = MultiplexingGcmListener.initializeGcm(mApplicationContext); + if (!regId.isEmpty()) + Log.d(TAG, "Already registered with GCM"); + } catch (IllegalStateException exception) { + Log.w(TAG, "Application manifest does not correctly configure GCM; " + + "sync notifications will not work", exception); + } catch (UnsupportedOperationException exception) { + Log.w(TAG, "Device does not support GCM; sync notifications will not work", + exception); + } + return null; + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } } |