| 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 fed38043cb9426ac4866b021bb3dc752180ae73d..6757ff157d5510cba2a442b3b69aa63f148b8ce4 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
|
| @@ -11,7 +11,6 @@ import org.chromium.base.ApplicationStatus;
|
| import org.chromium.base.Callback;
|
| import org.chromium.base.Log;
|
| import org.chromium.base.SysUtils;
|
| -import org.chromium.base.VisibleForTesting;
|
| import org.chromium.chrome.browser.ChromeBackgroundServiceWaiter;
|
| import org.chromium.chrome.browser.offlinepages.interfaces.BackgroundSchedulerProcessor;
|
|
|
| @@ -37,8 +36,26 @@ public class BackgroundOfflinerTask {
|
| *
|
| * @returns true for success
|
| */
|
| - public boolean startBackgroundRequests(Context context, Bundle bundle,
|
| - ChromeBackgroundServiceWaiter waiter) {
|
| + public void startBackgroundRequests(
|
| + Context context, Bundle bundle, final ChromeBackgroundServiceWaiter waiter) {
|
| + // 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)) {
|
| + waiter.onWaitDone();
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Triggers processing of background offlining requests. This is called when
|
| + * system conditions are appropriate for background offlining, typically from the
|
| + * GcmTaskService onRunTask() method. In response, we will start the
|
| + * task processing by passing the call along to the C++ RequestCoordinator.
|
| + * Also starts UMA collection.
|
| + *
|
| + * @returns true for success
|
| + */
|
| + 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 =
|
| @@ -58,51 +75,23 @@ public class BackgroundOfflinerTask {
|
| return false;
|
| }
|
|
|
| - // Now initiate processing.
|
| - processBackgroundRequests(bundle, currentConditions, waiter);
|
| -
|
| // 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 true;
|
| + return mBridge.startScheduledProcessing(currentConditions, createCallback(waiter));
|
| }
|
|
|
| - /**
|
| - * Triggers processing of background offlining requests.
|
| - */
|
| - // TODO(petewil): Change back to private when UMA works in the test, and test
|
| - // startBackgroundRequests instead of this method.
|
| - @VisibleForTesting
|
| - public void processBackgroundRequests(
|
| - Bundle bundle, DeviceConditions deviceConditions,
|
| - final ChromeBackgroundServiceWaiter waiter) {
|
| - // TODO(petewil): Nothing is holding the Wake Lock. We need some solution to
|
| - // keep hold of it. Options discussed so far are having a fresh set of functions
|
| - // to grab and release a countdown latch, or holding onto the wake lock ourselves,
|
| - // or grabbing the wake lock and then starting chrome and running
|
| - // startScheduledProcessing on the UI thread.
|
| -
|
| - // TODO(petewil): Decode the TriggerConditions from the bundle.
|
| -
|
| - Callback<Boolean> callback = new Callback<Boolean>() {
|
| - /**
|
| - * Callback function which indicates completion of background work.
|
| - * @param result - true if work was actually done (used for UMA).
|
| - */
|
| + private Callback<Boolean> createCallback(final ChromeBackgroundServiceWaiter waiter) {
|
| + return new Callback<Boolean>() {
|
| + /** Callback releasing the wakelock once background work concludes. */
|
| @Override
|
| public void onResult(Boolean result) {
|
| - // Release the wake lock.
|
| Log.d(TAG, "onProcessingDone");
|
| + // Release the wake lock.
|
| waiter.onWaitDone();
|
| }
|
| };
|
| -
|
| - // Pass the activation on to the bridge to the C++ RequestCoordinator.
|
| - if (!mBridge.startScheduledProcessing(deviceConditions, callback)) {
|
| - // Processing not started currently. Let callback know.
|
| - callback.onResult(false);
|
| - }
|
| }
|
| }
|
|
|