Chromium Code Reviews| 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; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 * | 85 * |
| 86 * @param context the current context. | 86 * @param context the current context. |
| 87 * @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. |
| 88 */ | 88 */ |
| 89 public void cancel(Context context, int taskId) { | 89 public void cancel(Context context, int taskId) { |
| 90 ThreadUtils.assertOnUiThread(); | 90 ThreadUtils.assertOnUiThread(); |
| 91 BackgroundTaskSchedulerPrefs.removeScheduledTask(taskId); | 91 BackgroundTaskSchedulerPrefs.removeScheduledTask(taskId); |
| 92 mSchedulerDelegate.cancel(context, taskId); | 92 mSchedulerDelegate.cancel(context, taskId); |
| 93 } | 93 } |
| 94 | 94 |
| 95 /** | |
| 96 * Checks whether OS was upgraded and triggers rescheduling if it is necessa ry. | |
| 97 * Rescheduling is necessary if type of background task scheduler delegate i s different for a | |
| 98 * new version of the OS. | |
| 99 * | |
| 100 * @param context the current context. | |
| 101 */ | |
| 102 public void checkForOSUpgrade(Context context) { | |
| 103 int oldSdkInt = BackgroundTaskSchedulerPrefs.getLastSdkVersion(); | |
| 104 int newSdkInt = Build.VERSION.SDK_INT; | |
| 105 // No OS upgrade detected. | |
| 106 if (oldSdkInt == newSdkInt) return; | |
| 107 | |
| 108 // Save the current SDK version to preferences. | |
| 109 BackgroundTaskSchedulerPrefs.setLastSdkVersion(newSdkInt); | |
| 110 | |
| 111 // OS upgrade detected within the same delegate type. No is upgrade nece ssary. | |
| 112 if ((oldSdkInt < Build.VERSION_CODES.M && newSdkInt < Build.VERSION_CODE S.M) | |
|
nyquist
2017/04/18 22:41:08
Do we want to extract the conditional out to somet
fgorski
2017/04/20 22:36:07
Done.
| |
| 113 || (oldSdkInt >= Build.VERSION_CODES.M && newSdkInt >= Build.VER SION_CODES.M)) { | |
|
nyquist
2017/04/18 22:41:08
Maybe stupid question, but if oldSdkInt was someho
fgorski
2017/04/20 22:36:07
I proposed some changes that work, but I am not ve
nyquist
2017/04/25 20:43:56
Yeah, I'm not sure if that is necessary. It feels
| |
| 114 return; | |
| 115 } | |
| 116 | |
| 117 // Explicitly invoke create old delegate type to cancel all scheduled ta sks. | |
|
nyquist
2017/04/18 22:41:08
Something seems to be off with this sentence: "inv
fgorski
2017/04/20 22:36:07
Done.
| |
| 118 // All preference entries are kept until reschedule call, which removes then then. | |
| 119 BackgroundTaskSchedulerDelegate oldDelegate = | |
| 120 new BackgroundTaskSchedulerGcmNetworkManager(); | |
| 121 Set<Integer> scheduledTaskIds = BackgroundTaskSchedulerPrefs.getSchedule dTaskIds(); | |
| 122 for (int taskId : scheduledTaskIds) { | |
| 123 oldDelegate.cancel(context, taskId); | |
| 124 } | |
| 125 | |
| 126 reschedule(context); | |
| 127 } | |
| 128 | |
| 95 public void reschedule(Context context) { | 129 public void reschedule(Context context) { |
| 96 Set<String> scheduledTasksClassNames = BackgroundTaskSchedulerPrefs.getS cheduledTasks(); | 130 Set<String> scheduledTasksClassNames = BackgroundTaskSchedulerPrefs.getS cheduledTasks(); |
| 97 BackgroundTaskSchedulerPrefs.removeAllTasks(); | 131 BackgroundTaskSchedulerPrefs.removeAllTasks(); |
| 98 for (String className : scheduledTasksClassNames) { | 132 for (String className : scheduledTasksClassNames) { |
| 99 BackgroundTask task = getBackgroundTaskFromClassName(className); | 133 BackgroundTask task = getBackgroundTaskFromClassName(className); |
| 100 if (task == null) { | 134 if (task == null) { |
| 101 Log.w(TAG, "Cannot reschedule task for: " + className); | 135 Log.w(TAG, "Cannot reschedule task for: " + className); |
| 102 continue; | 136 continue; |
| 103 } | 137 } |
| 104 | 138 |
| 105 task.reschedule(context); | 139 task.reschedule(context); |
| 106 } | 140 } |
| 107 } | 141 } |
| 108 } | 142 } |
| OLD | NEW |