Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.offlinepages; | 5 package org.chromium.chrome.browser.offlinepages; |
|
dewittj
2016/06/03 22:02:46
nit: mention offline pages in CL description
Pete Williamson
2016/06/03 23:42:11
Done.
| |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.os.Bundle; | 8 import android.os.Bundle; |
| 9 import android.os.SystemClock; | |
| 10 | 9 |
| 11 import com.google.android.gms.gcm.GcmNetworkManager; | 10 import com.google.android.gms.gcm.GcmNetworkManager; |
| 12 import com.google.android.gms.gcm.OneoffTask; | 11 import com.google.android.gms.gcm.OneoffTask; |
| 13 import com.google.android.gms.gcm.Task; | 12 import com.google.android.gms.gcm.Task; |
| 14 | 13 |
| 15 import org.chromium.chrome.browser.ChromeBackgroundService; | 14 import org.chromium.chrome.browser.ChromeBackgroundService; |
| 16 | 15 |
| 17 /** | 16 /** |
| 18 * The background scheduler class is for setting GCM Network Manager tasks. | 17 * The background scheduler class is for setting GCM Network Manager tasks. |
| 19 */ | 18 */ |
| 20 public class BackgroundScheduler { | 19 public class BackgroundScheduler { |
| 21 /** Bundle key for the timestamp in milliseconds when the request started. * / | 20 /** Bundle key for the timestamp in milliseconds when the request started. * / |
| 22 public static final String DATE_TAG = "Date"; | 21 public static final String DATE_TAG = "Date"; |
| 23 private static final long ONE_WEEK_IN_SECONDS = 60 * 60 * 24 * 7; | 22 private static final long ONE_WEEK_IN_SECONDS = 60 * 60 * 24 * 7; |
| 24 | 23 |
| 25 /** | 24 /** |
| 26 * For the given Triggering conditions, start a new GCM Network Manager requ est. | 25 * For the given Triggering conditions, start a new GCM Network Manager requ est. |
| 27 */ | 26 */ |
| 28 public static void schedule(Context context) { | 27 public static void schedule(Context context) { |
| 29 // Get the GCM Network Scheduler. | 28 // Get the GCM Network Scheduler. |
| 30 GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(cont ext); | 29 GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(cont ext); |
| 31 | 30 |
| 32 // TODO(petewil): Move the bundle packing and unpacking into a new Sched ulerBridge | 31 // TODO(petewil): Move the bundle packing and unpacking into a new Sched ulerBridge |
| 33 // class which can be mocked, and calls the static BackgroundSchdeulerBr idge. | 32 // class which can be mocked, and calls the static BackgroundSchdeulerBr idge. |
| 34 // TODO(petewil): Add the triggering conditions into the argument bundle . | 33 // TODO(petewil): Add the triggering conditions into the argument bundle . |
| 35 // Triggering conditions will include network state and charging require ments, maybe | 34 // Triggering conditions will include network state and charging require ments, maybe |
| 36 // also battery percentage. | 35 // also battery percentage. |
| 37 Bundle taskExtras = new Bundle(); | 36 Bundle taskExtras = new Bundle(); |
| 38 taskExtras.putLong(DATE_TAG, SystemClock.elapsedRealtime()); | 37 taskExtras.putLong(DATE_TAG, System.currentTimeMillis()); |
| 39 | 38 |
| 40 Task task = new OneoffTask.Builder() | 39 Task task = new OneoffTask.Builder() |
| 41 .setService(ChromeBackgroundService.class) | 40 .setService(ChromeBackgroundService.class) |
| 42 .setExecutionWindow(0, ONE_WEEK_IN_SECONDS) | 41 .setExecutionWindow(0, ONE_WEEK_IN_SECONDS) |
| 43 .setTag(OfflinePageUtils.TASK_TAG) | 42 .setTag(OfflinePageUtils.TASK_TAG) |
| 44 .setUpdateCurrent(true) | 43 .setUpdateCurrent(true) |
| 45 .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED) | 44 .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED) |
| 46 .setRequiresCharging(false) | 45 .setRequiresCharging(false) |
| 47 .setExtras(taskExtras) | 46 .setExtras(taskExtras) |
| 47 .setPersisted(true) | |
| 48 .build(); | 48 .build(); |
| 49 | 49 |
| 50 gcmNetworkManager.schedule(task); | 50 gcmNetworkManager.schedule(task); |
| 51 } | 51 } |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Cancel any outstanding GCM Network Manager requests. | 54 * Cancel any outstanding GCM Network Manager requests. |
| 55 */ | 55 */ |
| 56 public static void unschedule(Context context) { | 56 public static void unschedule(Context context) { |
| 57 // TODO(petewil): Take our task off the task queue. | 57 // TODO(petewil): Take our task off the task queue. |
| 58 } | 58 } |
| 59 } | 59 } |
| OLD | NEW |