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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundScheduler.java

Issue 1985923002: Wireframe scheduler implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback per DewittJ Created 4 years, 7 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: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundScheduler.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundScheduler.java b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundScheduler.java
new file mode 100644
index 0000000000000000000000000000000000000000..0195202c90e5066c191b5beb616ed62ba19637d6
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundScheduler.java
@@ -0,0 +1,61 @@
+// Copyright 2016 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.chrome.browser.offlinepages;
+
+import android.content.Context;
+import android.os.Bundle;
+
+import com.google.android.gms.gcm.GcmNetworkManager;
+import com.google.android.gms.gcm.OneoffTask;
+import com.google.android.gms.gcm.Task;
+
+import org.chromium.chrome.browser.ChromeBackgroundService;
+
+import java.util.Date;
+
+/**
+ * The background scheduler class is for setting GCM Network Manager tasks.
+ */
+public class BackgroundScheduler {
+ /** Bundle key for the timestamp in milliseconds when the request started. */
+ private static final String DATE_TAG = "Date";
+ private static final long ONE_WEEK_IN_SECONDS = 60 * 60 * 24 * 7;
+
+ /**
+ * For the given Triggering conditions, start a new GCM Network Manager request.
+ */
+ public static void schedule(Context context) {
+ // Get the GCM Network Scheduler.
+ GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context);
+
+ // TODO(petewil): Today this puts timestamp, add triggering conditions into bundle.
Bernhard Bauer 2016/05/26 11:17:44 Nit: I can't parse this sentence :)
Pete Williamson 2016/05/26 17:02:45 OK, try again, I rephrased it,hopefully with bette
+ // Triggering conditions will include network state and charging requirements, maybe
+ // also battery percentage.
+ Bundle taskExtras = new Bundle();
+ Date now = new Date();
Bernhard Bauer 2016/05/26 11:17:44 I don't exactly know what you are going to use thi
Pete Williamson 2016/05/26 17:02:45 This is to mark the starting point of an elapsed t
Bernhard Bauer 2016/05/27 12:36:15 OK, yeah, I would use SystemClock.elapsedRealtime(
Pete Williamson 2016/05/27 17:57:58 Done. I'll need to be careful to check for negati
Bernhard Bauer 2016/05/31 14:15:26 AFAICT, your tasks are currently not persisted acr
Pete Williamson 2016/05/31 14:30:15 FYI: Our tasks are persisted across reboots. We p
Bernhard Bauer 2016/05/31 14:57:31 Uh, the default for one-off tasks is to be _not_ p
+ taskExtras.putLong(DATE_TAG, now.getTime());
Bernhard Bauer 2016/05/26 11:17:44 Hm... this creates the bundle, but BackgroundSched
Pete Williamson 2016/05/26 17:02:45 We want to keep BackgroundSchedulerBridge at thin
Bernhard Bauer 2016/05/27 12:36:15 Yeah, it doesn't have to be in BackgroundScheduler
Pete Williamson 2016/05/27 17:57:58 Good idea. I'm working on a test changelist right
+
+ // Create a task.
Bernhard Bauer 2016/05/26 11:17:44 Nit: some of these comments are bordering on no in
Pete Williamson 2016/05/26 17:02:45 Comment removed. Yep, sorry, that's my personal s
+ Task task = new OneoffTask.Builder()
+ .setService(ChromeBackgroundService.class)
+ .setExecutionWindow(0, ONE_WEEK_IN_SECONDS)
+ .setTag(OfflinePageUtils.TASK_TAG)
+ .setUpdateCurrent(true)
+ .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
+ .setRequiresCharging(false)
+ .setExtras(taskExtras)
+ .build();
+
+ // Schedule the task.
+ gcmNetworkManager.schedule(task);
+ }
+
+ /**
+ * Cancel any outstanding GCM Network Manager requests.
+ */
+ public static void unschedule(Context context) {
+ // TODO(petewil): Take our task off the task queue.
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698