| Index: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundTask.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundTask.java b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundTask.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b4416e4ccc6228d959d209fc07f8a7eea6d31863
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundTask.java
|
| @@ -0,0 +1,70 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.chrome.browser.offlinepages;
|
| +
|
| +import android.content.Context;
|
| +import android.os.Bundle;
|
| +
|
| +import org.chromium.base.Log;
|
| +import org.chromium.chrome.browser.profiles.Profile;
|
| +
|
| +import java.util.concurrent.CountDownLatch;
|
| +
|
| +/**
|
| + * Handles servicing of background offlining requests coming via the GCMNetworkManager.
|
| + */
|
| +public class BackgroundTask implements BackgroundSchedulerBridge.ProcessingDoneCallback {
|
| + private static final String TAG = "BackgroundTask";
|
| + /**
|
| + * 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.
|
| + *
|
| + * @returns true for success
|
| + */
|
| + public boolean processBackgroundReqeusts(Context context, Bundle bundle) {
|
| + mProcessingDoneLatch = new CountDownLatch(1);
|
| +
|
| + // TODO(petewil): Decode the TriggerConditions from the bundle.
|
| +
|
| + // TODO(petewil): We only have a context. Is this a reasonable way to get a profile?
|
| + Profile profile = Profile.getLastUsedProfile();
|
| + if (profile.isOffTheRecord()) {
|
| + profile = profile.getOriginalProfile();
|
| + }
|
| +
|
| + // Pass the activation on to the bridge to the C++ RequestCoordinator.
|
| + BackgroundSchedulerBridge bridge =
|
| + BackgroundSchedulerBridge.getForProfile(profile, context);
|
| + bridge.startProcessing(context, this);
|
| +
|
| + // Gather UMA data to measure how often the user's machine is amenable to background
|
| + // loading when we wake to do a task.
|
| + OfflinePageUtils.recordWakeupUMA(context);
|
| +
|
| + // Wait for callback async completion before returning. This is important so
|
| + // we don't start the next GCM task until we are done with this one. It also
|
| + // rate limits our pre-render calls, and holds the wake lock for us.
|
| + try {
|
| + // TODO(petewil): Add a timeout here in case pre-rendering hangs.
|
| + mProcessingDoneLatch.await();
|
| + } catch (InterruptedException e) {
|
| + Log.w(TAG, "IncomingTask interrupted, returning to GcmNetworkManager");
|
| + return false;
|
| + }
|
| + return true;
|
| + }
|
| +
|
| + /**
|
| + * Callback function which indicates completion of background work.
|
| + * @param result - TODO(petewil): What is this for again? What does true mean?
|
| + */
|
| + public void onProcessingDone(boolean result) {
|
| + mProcessingDoneLatch.countDown();
|
| + }
|
| +
|
| + private CountDownLatch mProcessingDoneLatch;
|
| +}
|
|
|