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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundJobScheduler.java

Issue 2830843002: [Offline pages] Updates to background scheduling to use BTS (Closed)
Patch Set: Fixing the crash on NCN not being initialized 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 org.chromium.components.background_task_scheduler.BackgroundTaskScheduler Factory;
11 import org.chromium.components.background_task_scheduler.TaskIds;
12 import org.chromium.components.background_task_scheduler.TaskInfo;
13
14 import java.util.concurrent.TimeUnit;
15
16 /**
17 * The background job scheduler class used for scheduling tasks using JobSchedul er.
18 */
19 public class BackgroundJobScheduler extends BackgroundScheduler {
20 public BackgroundJobScheduler(Context context) {
21 super(context);
22 }
23
24 @Override
25 public void cancel() {
26 BackgroundTaskSchedulerFactory.getScheduler().cancel(
27 getContext(), TaskIds.OFFLINE_PAGES_BACKGROUND_JOB_ID);
28 }
29
30 @Override
31 protected void scheduleImpl(TriggerConditions triggerConditions, long delayS tartSeconds,
32 long executionDeadlineSeconds, boolean overwrite) {
33 Bundle taskExtras = new Bundle();
34 TaskExtrasPacker.packTimeInBundle(taskExtras);
35 TaskExtrasPacker.packTriggerConditionsInBundle(taskExtras, triggerCondit ions);
36
37 TaskInfo taskInfo =
38 TaskInfo.createOneOffTask(TaskIds.OFFLINE_PAGES_BACKGROUND_JOB_I D,
39 OfflineBackgroundTask.class,
40 TimeUnit.SECONDS.toMillis(delayStartSeconds),
41 TimeUnit.SECONDS.toMillis(executionDeadlineSecon ds))
42 .setRequiredNetworkType(triggerConditions.requireUnmeter edNetwork()
43 ? TaskInfo.NETWORK_TYPE_UNMETERED
44 : TaskInfo.NETWORK_TYPE_ANY)
45 .setUpdateCurrent(overwrite)
46 .setIsPersisted(true)
47 .setExtras(taskExtras)
48 .setRequiresCharging(triggerConditions.requirePowerConne cted())
49 .build();
50
51 BackgroundTaskSchedulerFactory.getScheduler().schedule(getContext(), tas kInfo);
52 }
53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698