OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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.chrome.browser.offlinepages; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.os.Bundle; |
| 9 |
| 10 /** |
| 11 * Handles servicing of background offlining requests coming via the GcmNetworkM
anager. |
| 12 */ |
| 13 public class BackgroundOfflinerTask implements BackgroundSchedulerBridge.Process
ingDoneCallback { |
| 14 private static final String TAG = "BackgroundTask"; |
| 15 |
| 16 /** |
| 17 * Triggers processing of background offlining requests. This is called whe
n |
| 18 * system conditions are appropriate for background offlining, typically fro
m the |
| 19 * GcmTaskService onRunTask() method. In response, we will start the |
| 20 * task processing by passing the call along to the C++ RequestCoordinator. |
| 21 * Also starts UMA collection. |
| 22 * |
| 23 * @returns true for success |
| 24 */ |
| 25 public static boolean startBackgroundRequests(Context context, Bundle bundle
) { |
| 26 BackgroundOfflinerTask task = new BackgroundOfflinerTask(); |
| 27 task.processBackgroundRequests(bundle); |
| 28 |
| 29 // Gather UMA data to measure how often the user's machine is amenable t
o background |
| 30 // loading when we wake to do a task. |
| 31 OfflinePageUtils.recordWakeupUMA(context); |
| 32 |
| 33 return true; |
| 34 } |
| 35 |
| 36 /** |
| 37 * Triggers processing of background offlining requests. |
| 38 */ |
| 39 private void processBackgroundRequests(Bundle bundle) { |
| 40 // TODO(petewil): Nothing is holding the Wake Lock. We need some soluti
on to |
| 41 // keep hold of it. Options discussed so far are having a fresh set of
functions |
| 42 // to grab and release a countdown latch, or holding onto the wake lock
ourselves, |
| 43 // or grabbing the wake lock and then starting chrome and running startP
rocessing |
| 44 // on the UI thread. |
| 45 |
| 46 // TODO(petewil): Decode the TriggerConditions from the bundle. |
| 47 |
| 48 // Pass the activation on to the bridge to the C++ RequestCoordinator. |
| 49 // Callback will hold onto the reference keeping this instance alive. |
| 50 BackgroundSchedulerBridge.startProcessing(this); |
| 51 } |
| 52 |
| 53 /** |
| 54 * Callback function which indicates completion of background work. |
| 55 * @param result - true if work was actually done (used for UMA). |
| 56 */ |
| 57 @Override |
| 58 public void onProcessingDone(boolean result) { |
| 59 |
| 60 } |
| 61 } |
OLD | NEW |