OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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.components.background_task_scheduler; | 5 package org.chromium.components.background_task_scheduler; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.os.Build; | 9 import android.os.Build; |
10 import android.support.annotation.Nullable; | 10 import android.support.annotation.Nullable; |
11 | 11 |
12 import org.chromium.base.Log; | 12 import org.chromium.base.Log; |
13 import org.chromium.base.ThreadUtils; | 13 import org.chromium.base.ThreadUtils; |
14 | 14 |
15 import java.lang.reflect.Constructor; | 15 import java.lang.reflect.Constructor; |
16 import java.util.Set; | |
16 | 17 |
17 /** | 18 /** |
18 * A BackgroundTaskScheduler which is used to schedule jobs that run in the back ground. | 19 * A BackgroundTaskScheduler which is used to schedule jobs that run in the back ground. |
19 * It is backed by system APIs ({@link android.app.job.JobScheduler}) on newer p latforms | 20 * It is backed by system APIs ({@link android.app.job.JobScheduler}) on newer p latforms |
20 * and by GCM ({@link com.google.android.gms.gcm.GcmNetworkManager}) on older pl atforms. | 21 * and by GCM ({@link com.google.android.gms.gcm.GcmNetworkManager}) on older pl atforms. |
21 * | 22 * |
22 * To get an instance of this class, use {@link BackgroundTaskSchedulerFactory#g etScheduler()}. | 23 * To get an instance of this class, use {@link BackgroundTaskSchedulerFactory#g etScheduler()}. |
23 */ | 24 */ |
24 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 25 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
25 public class BackgroundTaskScheduler { | 26 public class BackgroundTaskScheduler { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 * Cancels the task specified by the task ID. | 84 * Cancels the task specified by the task ID. |
84 * | 85 * |
85 * @param context the current context. | 86 * @param context the current context. |
86 * @param taskId the ID of the task to cancel. See {@link TaskIds} for a lis t. | 87 * @param taskId the ID of the task to cancel. See {@link TaskIds} for a lis t. |
87 */ | 88 */ |
88 public void cancel(Context context, int taskId) { | 89 public void cancel(Context context, int taskId) { |
89 ThreadUtils.assertOnUiThread(); | 90 ThreadUtils.assertOnUiThread(); |
90 BackgroundTaskSchedulerPrefs.removeScheduledTask(taskId); | 91 BackgroundTaskSchedulerPrefs.removeScheduledTask(taskId); |
91 mSchedulerDelegate.cancel(context, taskId); | 92 mSchedulerDelegate.cancel(context, taskId); |
92 } | 93 } |
94 | |
95 public void reschedule(Context context) { | |
96 Set<String> scheduledTasksClassNames = BackgroundTaskSchedulerPrefs.getS cheduledTasks(); | |
97 BackgroundTaskSchedulerPrefs.removeAllTasks(); | |
nyquist
2017/04/18 22:33:03
So, conceptually we could do this before or after
fgorski
2017/04/20 19:09:58
I did it to avoid updating the prefs entry from bo
nyquist
2017/04/25 20:44:05
I think what we have now is fine.
| |
98 for (String className : scheduledTasksClassNames) { | |
99 BackgroundTask task = getBackgroundTaskFromClassName(className); | |
100 if (task == null) { | |
101 Log.w(TAG, "Cannot reschedule task for: " + className); | |
102 continue; | |
103 } | |
104 | |
105 task.reschedule(context); | |
106 } | |
107 } | |
93 } | 108 } |
OLD | NEW |