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

Side by Side 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: More CR feedback per DougArnett 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 package org.chromium.chrome.browser.offlinepages;
6
7 import android.content.Context;
8 import android.os.Bundle;
9
10 import com.google.android.gms.gcm.GcmNetworkManager;
11 import com.google.android.gms.gcm.OneoffTask;
12 import com.google.android.gms.gcm.Task;
13
14 import org.chromium.chrome.browser.ChromeBackgroundService;
15
16 import java.util.Date;
17
18 /**
19 * The background scheduler class is for setting GCM Network Manager tasks.
20 */
21 public class BackgroundScheduler {
22 /** Bundle key for the timestamp in milliseconds when the request started. * /
23 public static final String DATE_TAG = "Date";
24 private static final long ONE_WEEK_IN_SECONDS = 60 * 60 * 24 * 7;
25
26 /**
27 * For the given Triggering conditions, start a new GCM Network Manager requ est.
28 */
29 public static void schedule(Context context) {
30 // Get the GCM Network Scheduler.
31 GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(cont ext);
32
33 // TODO(petewil): Today this puts timestamp, add triggering conditions i nto bundle.
34 // Triggering conditions will include network state and charging require ments, maybe
35 // also battery percentage.
36 Bundle taskExtras = new Bundle();
37 Date now = new Date();
38 taskExtras.putLong(DATE_TAG, now.getTime());
39
40 // Create a task.
41 Task task = new OneoffTask.Builder()
42 .setService(ChromeBackgroundService.class)
43 .setExecutionWindow(0, ONE_WEEK_IN_SECONDS)
44 .setTag(OfflinePageUtils.TASK_TAG)
45 .setUpdateCurrent(true)
46 .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
47 .setRequiresCharging(false)
48 .setExtras(taskExtras)
49 .build();
50
51 // Schedule the task.
52 gcmNetworkManager.schedule(task);
53 }
54
55 /**
56 * Cancel any outstanding GCM Network Manager requests.
57 */
58 public static void unschedule(Context context) {
59 // TODO(petewil): Take our task off the task queue.
60 }
61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698