Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/BackgroundSyncLauncher.java

Issue 1324173002: [Background Sync] Use GcmNetworkManager to start the browser for sync events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@bgsync-fix-background5
Patch Set: Update remaining AndroidManifest.xml templates Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/BackgroundSyncLauncher.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/BackgroundSyncLauncher.java b/content/public/android/java/src/org/chromium/content/browser/BackgroundSyncLauncher.java
index bad267185182d208dcaf14efc6b12dae6704278a..510a5b461a899cfeaff545ec63b27982e6520df2 100644
--- a/content/public/android/java/src/org/chromium/content/browser/BackgroundSyncLauncher.java
+++ b/content/public/android/java/src/org/chromium/content/browser/BackgroundSyncLauncher.java
@@ -9,6 +9,10 @@ import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
+import com.google.android.gms.gcm.GcmNetworkManager;
+import com.google.android.gms.gcm.OneoffTask;
+import com.google.android.gms.gcm.Task;
+
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
@@ -28,6 +32,8 @@ public class BackgroundSyncLauncher {
// BackgroundSyncLauncherAndroid, if any. If it is non-null then the browser is running.
private static BackgroundSyncLauncher sInstance;
+ private GcmNetworkManager mScheduler;
+
/**
* Create a BackgroundSyncLauncher object, which is owned by C++.
* @param context The app context.
@@ -58,6 +64,26 @@ public class BackgroundSyncLauncher {
*/
public static interface ShouldLaunchCallback { public void run(Boolean shouldLaunch); }
+ private void scheduleLaunchTask() {
jkarlin 2015/09/02 18:16:36 It appears that this can be called multiple times,
iclelland 2015/09/02 20:04:48 If it is called when there is already a task sched
jkarlin 2015/09/03 11:11:57 Acknowledged.
+ // Google Play Services may not be up to date, if the application was not installed through
+ // the Play Store. In this case, scheduling the task will fail silently.
+ // TODO(iclelland): Check whether the Play Services client library matches the requirements
+ // in the manifest, and respond appropriately if it does not.
+ OneoffTask oneoff = new OneoffTask.Builder()
+ .setService(BackgroundSyncLauncherService.class)
+ .setTag("BackgroundSync Event")
+ .setExecutionWindow(0, 0)
+ .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
+ .setPersisted(true)
+ .setUpdateCurrent(true)
+ .build();
+ mScheduler.schedule(oneoff);
+ }
+
+ private void removeScheduledTasks() {
+ mScheduler.cancelAllTasks(BackgroundSyncLauncherService.class);
+ }
+
/**
* Returns whether the browser should be launched when the device next goes online.
* This is set by C++ and reset to false each time {@link BackgroundSyncLauncher}'s singleton is
@@ -101,6 +127,11 @@ public class BackgroundSyncLauncher {
return null;
}
}.execute();
+ if (shouldLaunch) {
+ scheduleLaunchTask();
+ } else {
+ removeScheduledTasks();
+ }
}
/**
@@ -112,6 +143,7 @@ public class BackgroundSyncLauncher {
}
private BackgroundSyncLauncher(Context context) {
+ mScheduler = GcmNetworkManager.getInstance(context);
setLaunchWhenNextOnline(context, false);
}
-}
+}

Powered by Google App Engine
This is Rietveld 408576698