| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.offlinepages; | 5 package org.chromium.chrome.browser.offlinepages; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.os.Bundle; | 8 import android.os.Bundle; |
| 9 | 9 |
| 10 import org.chromium.base.Callback; | 10 import org.chromium.base.Callback; |
| 11 import org.chromium.base.Log; |
| 11 import org.chromium.base.VisibleForTesting; | 12 import org.chromium.base.VisibleForTesting; |
| 13 import org.chromium.chrome.browser.ChromeBackgroundServiceWaiter; |
| 12 import org.chromium.chrome.browser.offlinepages.interfaces.BackgroundSchedulerPr
ocessor; | 14 import org.chromium.chrome.browser.offlinepages.interfaces.BackgroundSchedulerPr
ocessor; |
| 13 | 15 |
| 14 /** | 16 /** |
| 15 * Handles servicing of background offlining requests coming via the GcmNetworkM
anager. | 17 * Handles servicing of background offlining requests coming via the GcmNetworkM
anager. |
| 16 */ | 18 */ |
| 17 public class BackgroundOfflinerTask { | 19 public class BackgroundOfflinerTask { |
| 20 private static final String TAG = "BGOfflinerTask"; |
| 21 |
| 22 /** Interface to use to report task completion. */ |
| 23 private ChromeBackgroundServiceWaiter mWaiter; |
| 18 | 24 |
| 19 public BackgroundOfflinerTask(BackgroundSchedulerProcessor bridge) { | 25 public BackgroundOfflinerTask(BackgroundSchedulerProcessor bridge) { |
| 20 mBridge = bridge; | 26 mBridge = bridge; |
| 21 } | 27 } |
| 22 | 28 |
| 23 private final BackgroundSchedulerProcessor mBridge; | 29 private final BackgroundSchedulerProcessor mBridge; |
| 24 | 30 |
| 25 /** | 31 /** |
| 26 * Triggers processing of background offlining requests. This is called whe
n | 32 * Triggers processing of background offlining requests. This is called whe
n |
| 27 * system conditions are appropriate for background offlining, typically fro
m the | 33 * system conditions are appropriate for background offlining, typically fro
m the |
| 28 * GcmTaskService onRunTask() method. In response, we will start the | 34 * GcmTaskService onRunTask() method. In response, we will start the |
| 29 * task processing by passing the call along to the C++ RequestCoordinator. | 35 * task processing by passing the call along to the C++ RequestCoordinator. |
| 30 * Also starts UMA collection. | 36 * Also starts UMA collection. |
| 31 * | 37 * |
| 32 * @returns true for success | 38 * @returns true for success |
| 33 */ | 39 */ |
| 34 public boolean startBackgroundRequests(Context context, Bundle bundle) { | 40 public boolean startBackgroundRequests(Context context, Bundle bundle, |
| 41 ChromeBackgroundServiceWaiter waiter)
{ |
| 42 mWaiter = waiter; |
| 35 processBackgroundRequests(bundle); | 43 processBackgroundRequests(bundle); |
| 36 | 44 |
| 37 // Gather UMA data to measure how often the user's machine is amenable t
o background | 45 // Gather UMA data to measure how often the user's machine is amenable t
o background |
| 38 // loading when we wake to do a task. | 46 // loading when we wake to do a task. |
| 39 long taskScheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(bun
dle); | 47 long taskScheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(bun
dle); |
| 40 OfflinePageUtils.recordWakeupUMA(context, taskScheduledTimeMillis); | 48 OfflinePageUtils.recordWakeupUMA(context, taskScheduledTimeMillis); |
| 41 | 49 |
| 42 return true; | 50 return true; |
| 43 } | 51 } |
| 44 | 52 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 57 | 65 |
| 58 // TODO(petewil): Decode the TriggerConditions from the bundle. | 66 // TODO(petewil): Decode the TriggerConditions from the bundle. |
| 59 | 67 |
| 60 Callback<Boolean> callback = new Callback<Boolean>() { | 68 Callback<Boolean> callback = new Callback<Boolean>() { |
| 61 /** | 69 /** |
| 62 * Callback function which indicates completion of background work. | 70 * Callback function which indicates completion of background work. |
| 63 * @param result - true if work was actually done (used for UMA). | 71 * @param result - true if work was actually done (used for UMA). |
| 64 */ | 72 */ |
| 65 @Override | 73 @Override |
| 66 public void onResult(Boolean result) { | 74 public void onResult(Boolean result) { |
| 67 // TODO(petewil): Release the wake lock. | 75 // Release the wake lock. |
| 76 Log.d(TAG, "onProcessingDone"); |
| 77 mWaiter.onWaitDone(); |
| 68 } | 78 } |
| 69 }; | 79 }; |
| 70 | 80 |
| 71 // Pass the activation on to the bridge to the C++ RequestCoordinator. | 81 // Pass the activation on to the bridge to the C++ RequestCoordinator. |
| 72 mBridge.startProcessing(callback); | 82 mBridge.startProcessing(callback); |
| 73 } | 83 } |
| 74 } | 84 } |
| OLD | NEW |