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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java

Issue 2697493002: [Offline pages] Implementation of OfflineBackgroundTask using background_task_scheduler (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java
index bc362d82e5d32afb44895cf0600268e407c3b075..b8684786c3c42109991dc5d5d8fd764854a054a4 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java
@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.offlinepages;
import android.content.Context;
import android.os.Bundle;
+import android.os.PersistableBundle;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.Callback;
@@ -38,13 +39,33 @@ public class BackgroundOfflinerTask {
*/
public void startBackgroundRequests(
Context context, Bundle bundle, final ChromeBackgroundServiceWaiter waiter) {
+ TriggerConditions triggerConditions =
+ TaskExtrasPacker.unpackTriggerConditionsFromBundle(bundle);
+ // Set up backup scheduled task in case processing is killed before RequestCoordinator
+ // has a chance to reschedule base on remaining work.
+ BackgroundScheduler.getInstance(context).scheduleBackup(
+ triggerConditions, DEFER_START_SECONDS);
+ long taskScheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(bundle);
// Complete the wait if background request processing was not started.
// If background processing was started, completion is going to be handled by callback.
- if (!startBackgroundRequestsImpl(context, bundle, waiter)) {
+ if (!startBackgroundRequestsImpl(
+ context, triggerConditions, taskScheduledTimeMillis, createCallback(waiter))) {
waiter.onWaitDone();
}
}
+ /** TODO(fgorski): add documentation
Pete Williamson 2017/02/21 18:43:43 Let's add the doc now instead of later. Why do we
+ * When result is true we are going to be doing work...
+ */
+ public boolean startBackgroundRequests(
+ Context context, PersistableBundle bundle, Callback<Boolean> callback) {
+ // TODO(fgorski): I may not need the backup job... which is handled by the BGJobScheduler
+ // already
+ TriggerConditions conditions = TaskExtrasPacker.unpackTriggerConditionsFromBundle(bundle);
+ long taskScheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(bundle);
+ return startBackgroundRequestsImpl(context, conditions, taskScheduledTimeMillis, callback);
+ }
+
/**
* Triggers processing of background offlining requests. This is called when
* system conditions are appropriate for background offlining, typically from the
@@ -52,21 +73,16 @@ public class BackgroundOfflinerTask {
* task processing by passing the call along to the C++ RequestCoordinator.
* Also starts UMA collection.
*
- * @returns true for success
+ * @returns Whether processing will be carried out and completion will be indicated through a
+ * callback.
*/
- private boolean startBackgroundRequestsImpl(
- Context context, Bundle bundle, final ChromeBackgroundServiceWaiter waiter) {
- // Set up backup scheduled task in case processing is killed before RequestCoordinator
- // has a chance to reschedule base on remaining work.
- TriggerConditions previousTriggerConditions =
- TaskExtrasPacker.unpackTriggerConditionsFromBundle(bundle);
- BackgroundScheduler.getInstance(context).scheduleBackup(
- previousTriggerConditions, DEFER_START_SECONDS);
-
+ private boolean startBackgroundRequestsImpl(Context context,
+ TriggerConditions triggerConditions, long taskScheduledTimeMillis,
+ Callback<Boolean> callback) {
DeviceConditions currentConditions = OfflinePageUtils.getDeviceConditions(context);
if (!currentConditions.isPowerConnected()
&& currentConditions.getBatteryPercentage()
- < previousTriggerConditions.getMinimumBatteryPercentage()) {
+ < triggerConditions.getMinimumBatteryPercentage()) {
Log.d(TAG, "Battery percentage is lower than minimum to start processing");
return false;
}
@@ -78,10 +94,9 @@ public class BackgroundOfflinerTask {
// Gather UMA data to measure how often the user's machine is amenable to background
// loading when we wake to do a task.
- long taskScheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(bundle);
OfflinePageUtils.recordWakeupUMA(context, taskScheduledTimeMillis);
- return mBridge.startScheduledProcessing(currentConditions, createCallback(waiter));
+ return mBridge.startScheduledProcessing(currentConditions, callback);
}
private Callback<Boolean> createCallback(final ChromeBackgroundServiceWaiter waiter) {

Powered by Google App Engine
This is Rietveld 408576698