Commit 2f694fda authored by Ian Wells's avatar Ian Wells Committed by Commit Bot

Schedule background task when changing some offline prefetching settings

Causes the background task to be scheduled when limitless prefetching is enabled
and when the prefetch testing header value is changed. There is a five-second
delay built in when the background task is scheduled this way; this gives the
user a chance to change both limitless and the testing header before the task
starts.

Bug: 954252
Change-Id: Ib21e8e0fd4dca29226c2b3e2080da1afe7650ed8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1574139Reviewed-by: default avatarCarlos Knippschild <carlosk@chromium.org>
Reviewed-by: default avatarDan H <harringtond@chromium.org>
Commit-Queue: Ian Wells <iwells@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654608}
parent d45c8260
......@@ -20,6 +20,7 @@ import org.chromium.components.background_task_scheduler.TaskInfo;
@JNINamespace("offline_pages::prefetch")
public class PrefetchBackgroundTaskScheduler {
public static final long DEFAULT_START_DELAY_SECONDS = 15 * 60;
public static final long LIMITLESS_START_DELAY_SECONDS = 5;
/**
* Schedules the default 'NWake' task for the prefetching service. This task will normally be
......@@ -49,7 +50,8 @@ public class PrefetchBackgroundTaskScheduler {
private static void scheduleTaskInternal(
int additionalDelaySeconds, boolean limitlessPrefetching, String gcmToken) {
final long minimumTimeSeconds =
(limitlessPrefetching ? 0 : DEFAULT_START_DELAY_SECONDS) + additionalDelaySeconds;
(limitlessPrefetching ? LIMITLESS_START_DELAY_SECONDS : DEFAULT_START_DELAY_SECONDS)
+ additionalDelaySeconds;
TaskInfo.Builder taskInfoBuilder =
TaskInfo.createOneOffTask(TaskIds.OFFLINE_PAGES_PREFETCH_JOB_ID,
PrefetchBackgroundTask.class,
......
......@@ -162,7 +162,9 @@ public class PrefetchBackgroundTaskUnitTest {
TaskInfo scheduledTask =
mFakeTaskScheduler.getTaskInfo(TaskIds.OFFLINE_PAGES_PREFETCH_JOB_ID);
assertNotNull(scheduledTask);
assertEquals(TimeUnit.SECONDS.toMillis(additionalDelaySeconds),
assertEquals(TimeUnit.SECONDS.toMillis(
PrefetchBackgroundTaskScheduler.LIMITLESS_START_DELAY_SECONDS
+ additionalDelaySeconds),
scheduledTask.getOneOffInfo().getWindowStartTimeMs());
assertEquals(true, scheduledTask.isPersisted());
assertEquals(TaskInfo.NetworkType.ANY, scheduledTask.getRequiredNetworkType());
......
......@@ -231,6 +231,29 @@ cr.define('offlineInternals', function() {
browserProxy.getLoggingState().then(updateLogStatus);
}
/**
* Calls scheduleNwake and indicates how long the scheduled delay will be.
*/
function ensureBackgroundTaskScheduledWithDelay() {
browserProxy.scheduleNwake()
.then((result) => {
// The delays in these messages should correspond to the scheduling
// delays defined in PrefetchBackgroundTaskScheduler.java.
if ($('limitless-prefetching-checkbox').checked) {
setPrefetchResult(
result +
' (Limitless mode enabled; background task scheduled to run' +
' in a few seconds.)');
} else {
setPrefetchResult(
result +
' (Limitless mode disabled; background task scheduled to run' +
' in several minutes.)');
}
})
.catch(prefetchResultError);
}
function initialize() {
const incognito = loadTimeData.getBoolean('isIncognito');
['delete-selected-pages', 'delete-selected-requests', 'model-checkbox',
......@@ -314,10 +337,14 @@ cr.define('offlineInternals', function() {
};
$('limitless-prefetching-checkbox').onchange = (evt) => {
browserProxy.setLimitlessPrefetchingEnabled(evt.target.checked);
if (evt.target.checked) {
ensureBackgroundTaskScheduledWithDelay();
}
};
// Helper for setting prefetch testing header from a radio button.
const setPrefetchTestingHeader = function(evt) {
browserProxy.setPrefetchTestingHeaderValue(evt.target.value);
ensureBackgroundTaskScheduledWithDelay();
};
$('testing-header-default').onchange = setPrefetchTestingHeader;
$('testing-header-enable').onchange = setPrefetchTestingHeader;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment