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

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

Issue 2914703002: [Offline Prefetch] Backoff support for PrefetchBackgroundTask (Closed)
Patch Set: Fix test Created 3 years, 6 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
« no previous file with comments | « no previous file | chrome/android/java_sources.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/prefetch/PrefetchBackgroundTask.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/prefetch/PrefetchBackgroundTask.java b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/prefetch/PrefetchBackgroundTask.java
index 9f894c8c814c2d2ce2f7df8d003972826844403a..3d1741b3cdb055a8f590b3b3b24d133c34253ce1 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/prefetch/PrefetchBackgroundTask.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/prefetch/PrefetchBackgroundTask.java
@@ -35,8 +35,12 @@ import java.util.concurrent.TimeUnit;
*/
@JNINamespace("offline_pages::prefetch")
public class PrefetchBackgroundTask implements BackgroundTask {
+ public static final long DEFAULT_START_DELAY_SECONDS = 15 * 60;
+
private static final String TAG = "OPPrefetchBGTask";
+ private static BackgroundTaskScheduler sSchedulerInstance;
+
private long mNativeTask = 0;
private TaskFinishedCallback mTaskFinishedCallback = null;
@@ -50,6 +54,13 @@ public class PrefetchBackgroundTask implements BackgroundTask {
mProfile = profile;
}
+ static BackgroundTaskScheduler getScheduler() {
+ if (sSchedulerInstance != null) {
+ return sSchedulerInstance;
+ }
+ return BackgroundTaskSchedulerFactory.getScheduler();
+ }
+
/**
* Schedules the default 'NWake' task for the prefetching service.
*
@@ -57,13 +68,13 @@ public class PrefetchBackgroundTask implements BackgroundTask {
* TODO(dewittj): Handle skipping work if the battery percentage is too low.
*/
@CalledByNative
- public static void scheduleTask() {
- BackgroundTaskScheduler scheduler = BackgroundTaskSchedulerFactory.getScheduler();
+ public static void scheduleTask(int additionalDelaySeconds) {
TaskInfo taskInfo =
TaskInfo.createOneOffTask(TaskIds.OFFLINE_PAGES_PREFETCH_JOB_ID,
PrefetchBackgroundTask.class,
// Minimum time to wait
- TimeUnit.MINUTES.toMillis(15),
+ TimeUnit.SECONDS.toMillis(
+ DEFAULT_START_DELAY_SECONDS + additionalDelaySeconds),
// Maximum time to wait. After this interval the event will fire
// regardless of whether the conditions are right.
TimeUnit.DAYS.toMillis(7))
@@ -71,7 +82,7 @@ public class PrefetchBackgroundTask implements BackgroundTask {
.setIsPersisted(true)
.setUpdateCurrent(true)
.build();
- scheduler.schedule(ContextUtils.getApplicationContext(), taskInfo);
+ getScheduler().schedule(ContextUtils.getApplicationContext(), taskInfo);
}
/**
@@ -79,8 +90,7 @@ public class PrefetchBackgroundTask implements BackgroundTask {
*/
@CalledByNative
public static void cancelTask() {
- BackgroundTaskScheduler scheduler = BackgroundTaskSchedulerFactory.getScheduler();
- scheduler.cancel(
+ getScheduler().cancel(
ContextUtils.getApplicationContext(), TaskIds.OFFLINE_PAGES_PREFETCH_JOB_ID);
}
@@ -160,8 +170,28 @@ public class PrefetchBackgroundTask implements BackgroundTask {
}
}
+ @VisibleForTesting
+ static void setSchedulerForTesting(BackgroundTaskScheduler scheduler) {
+ sSchedulerInstance = scheduler;
+ }
+
+ @VisibleForTesting
+ void setTaskReschedulingForTesting(boolean reschedule, boolean backoff) {
+ if (mNativeTask == 0) return;
+ nativeSetTaskReschedulingForTesting(mNativeTask, reschedule, backoff);
+ }
+
+ @VisibleForTesting
+ void signalTaskFinishedForTesting() {
+ if (mNativeTask == 0) return;
+ nativeSignalTaskFinishedForTesting(mNativeTask);
+ }
+
@VisibleForTesting
native boolean nativeStartPrefetchTask(Profile profile);
@VisibleForTesting
native boolean nativeOnStopTask(long nativePrefetchBackgroundTask);
+ native void nativeSetTaskReschedulingForTesting(
+ long nativePrefetchBackgroundTask, boolean reschedule, boolean backoff);
+ native void nativeSignalTaskFinishedForTesting(long nativePrefetchBackgroundTask);
}
« no previous file with comments | « no previous file | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698