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

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

Issue 2714463002: [android] Add JobScheduler-based BackgroundTaskScheduler. (Closed)
Patch Set: Clean up background section of documentation Created 3 years, 10 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.components.background_task_scheduler;
6
7 import android.content.Context;
8 import android.support.annotation.AnyThread;
9 import android.support.annotation.MainThread;
10
11 /**
12 * Entry point for callbacks from {@link BackgroundTaskScheduler}. Any classes i mplementing
13 * this interface must have a public which takes no arguments.
David Trainor- moved to gerrit 2017/02/24 07:19:48 the word constructor should be in here somewhere :
nyquist 2017/02/24 23:41:11 :-p Done.
14 * The callbacks will be executed on the main thread, which means that execution logic must be
15 * offloaded to another {@link Thread}, {@link android.os.Handler} or {@link and roid.os.AsyncTask}.
16 */
17 public interface BackgroundTask {
18 /**
19 * Callback to invoke whenever background processing has finished after firs t returning true
20 * from {@link #onStartTask(Context, TaskParameters, TaskFinishedCallback)}.
21 */
22 interface TaskFinishedCallback {
23 /**
24 * Callback to inform the {@link BackgroundTaskScheduler} that the backg round processing
25 * now has finished. When this callback is invoked, the system will stop holding a wakelock.
26 * @param needsReSchedule whether this task must be rescheduled.
David Trainor- moved to gerrit 2017/02/24 07:19:48 ReSchedule -> Reschedule everywhere?
nyquist 2017/02/24 23:41:11 Done.
27 */
28 @AnyThread
29 void taskFinished(boolean needsReSchedule);
30 }
31
32 /**
33 * Callback from {@link BackgroundTaskScheduler} when your task should start processing.
34 * It is invoked on the main thread, and if your task finishes quickly, you should return false
35 * from this method when you are done processing. If this is a long-running task, you should
36 * return true from this method, and instead invoke the {@link TaskFinishedC allback} when the
37 * processing is finished on some other {@link Thread}, {@link android.os.Ha ndler} or
38 * {@link android.os.AsyncTask}. While this method is running the system hol ds a wakelock. If
39 * false is returned from this method, the wakelock is immediately released, but if this method
40 * returns true, the wakelock is not released until either the {@link TaskFi nishedCallback} is
41 * invoked, or the system calls {@link #onStopTask(Context, TaskParameters)} .
42 * @param context the current context.
Peter Beverloo 2017/02/24 18:07:09 micro nit: A blank line between the documentation
nyquist 2017/02/24 23:41:11 Very much agreed. Followed through for everything
43 * @param taskParameters the data passed in as {@link TaskInfo} when the tas k was scheduled.
44 * @param callback if the task needs to continue processing after returning from the call to
45 * {@link #onStartTask(Context, TaskParameters, TaskFinished Callback)}, this
46 * callback must be invoked when the processing has finished .
47 * @return true if the task needs to continue processing work. False if ther e is no more work.
48 * @see TaskInfo
49 */
50 @MainThread
51 boolean onStartTask(
52 Context context, TaskParameters taskParameters, TaskFinishedCallback callback);
53
54 /**
55 * Callback from {@link BackgroundTaskScheduler} when the system has determi ned that the
56 * execution of the task must stop immediately, even before the {@link TaskF inishedCallback}
57 * has been invoked. This will typically happen whenever the required condit ions for the task
58 * are no longer met. See {@link TaskInfo}. A wakelock is held by the system while this callback
59 * is invoked, and immediately released after this method returns.
60 * @param context the current context.
61 * @param taskParameters the data passed in as {@link TaskInfo} when the tas k was scheduled.
62 * @return true if the task needs to be rescheduled according to the resched uling criteria
63 * specified when the task was scheduled initially. False if the taskshould not be rescheduled.
64 * Regardless of the value returned, your task must stop executing.
65 * @see TaskInfo
66 */
67 @MainThread
68 boolean onStopTask(Context context, TaskParameters taskParameters);
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698