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

Side by Side Diff: components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerPrefs.java

Issue 2814653003: [Android] BackgroundTaskScheduler reschedule implementation (Closed)
Patch Set: Rebasing Created 3 years, 7 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
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.content.SharedPreferences; 7 import android.content.SharedPreferences;
8 8
9 import org.chromium.base.ContextUtils; 9 import org.chromium.base.ContextUtils;
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 String[] entryParts = entry.split(ENTRY_SEPARATOR); 67 String[] entryParts = entry.split(ENTRY_SEPARATOR);
68 if (entryParts.length != 2 || entryParts[0] == null || entryParts[0] .isEmpty()) { 68 if (entryParts.length != 2 || entryParts[0] == null || entryParts[0] .isEmpty()) {
69 continue; 69 continue;
70 } 70 }
71 scheduledTasksClassNames.add(entryParts[0]); 71 scheduledTasksClassNames.add(entryParts[0]);
72 } 72 }
73 73
74 return scheduledTasksClassNames; 74 return scheduledTasksClassNames;
75 } 75 }
76 76
77 /** Removes all scheduled tasks from shared preferences store. */
78 public static void removeAllTasks() {
79 ContextUtils.getAppSharedPreferences().edit().remove(KEY_SCHEDULED_TASKS ).apply();
80 }
81
77 private static void updateScheduledTasks(SharedPreferences prefs, Set<String > tasks) { 82 private static void updateScheduledTasks(SharedPreferences prefs, Set<String > tasks) {
78 SharedPreferences.Editor editor = prefs.edit(); 83 SharedPreferences.Editor editor = prefs.edit();
79 editor.putStringSet(KEY_SCHEDULED_TASKS, tasks); 84 editor.putStringSet(KEY_SCHEDULED_TASKS, tasks);
80 editor.apply(); 85 editor.apply();
81 } 86 }
82 87
83 /** 88 /**
84 * Converts a task info to a shared preference entry in the format: 89 * Converts a task info to a shared preference entry in the format:
85 * BACKGROUND_TASK_CLASS_NAME:TASK_ID. 90 * BACKGROUND_TASK_CLASS_NAME:TASK_ID.
86 * Task ID is necessary to be able to remove the entries from the shared pre ferences. 91 * Task ID is necessary to be able to remove the entries from the shared pre ferences.
87 */ 92 */
88 private static String toSharedPreferenceEntry(TaskInfo taskInfo) { 93 private static String toSharedPreferenceEntry(TaskInfo taskInfo) {
89 return taskInfo.getBackgroundTaskClass().getName() + ENTRY_SEPARATOR + t askInfo.getTaskId(); 94 return taskInfo.getBackgroundTaskClass().getName() + ENTRY_SEPARATOR + t askInfo.getTaskId();
90 } 95 }
91 } 96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698