| 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.Log; |
| 12 import org.chromium.base.VisibleForTesting; | 12 import org.chromium.base.VisibleForTesting; |
| 13 import org.chromium.chrome.browser.ChromeBackgroundServiceWaiter; | 13 import org.chromium.chrome.browser.ChromeBackgroundServiceWaiter; |
| 14 import org.chromium.chrome.browser.offlinepages.interfaces.BackgroundSchedulerPr
ocessor; | 14 import org.chromium.chrome.browser.offlinepages.interfaces.BackgroundSchedulerPr
ocessor; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Handles servicing of background offlining requests coming via the GcmNetworkM
anager. | 17 * Handles servicing of background offlining requests coming via the GcmNetworkM
anager. |
| 18 */ | 18 */ |
| 19 public class BackgroundOfflinerTask { | 19 public class BackgroundOfflinerTask { |
| 20 private static final String TAG = "BGOfflinerTask"; | 20 private static final String TAG = "BGOfflinerTask"; |
| 21 private static final long DEFER_START_SECONDS = 5 * 60; |
| 21 | 22 |
| 22 public BackgroundOfflinerTask(BackgroundSchedulerProcessor bridge) { | 23 public BackgroundOfflinerTask(BackgroundSchedulerProcessor bridge) { |
| 23 mBridge = bridge; | 24 mBridge = bridge; |
| 24 } | 25 } |
| 25 | 26 |
| 26 private final BackgroundSchedulerProcessor mBridge; | 27 private final BackgroundSchedulerProcessor mBridge; |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * Triggers processing of background offlining requests. This is called whe
n | 30 * Triggers processing of background offlining requests. This is called whe
n |
| 30 * system conditions are appropriate for background offlining, typically fro
m the | 31 * system conditions are appropriate for background offlining, typically fro
m the |
| 31 * GcmTaskService onRunTask() method. In response, we will start the | 32 * GcmTaskService onRunTask() method. In response, we will start the |
| 32 * task processing by passing the call along to the C++ RequestCoordinator. | 33 * task processing by passing the call along to the C++ RequestCoordinator. |
| 33 * Also starts UMA collection. | 34 * Also starts UMA collection. |
| 34 * | 35 * |
| 35 * @returns true for success | 36 * @returns true for success |
| 36 */ | 37 */ |
| 37 public boolean startBackgroundRequests(Context context, Bundle bundle, | 38 public boolean startBackgroundRequests(Context context, Bundle bundle, |
| 38 ChromeBackgroundServiceWaiter waiter)
{ | 39 ChromeBackgroundServiceWaiter waiter)
{ |
| 40 // Set up backup scheduled task in case processing is killed before Requ
estCoordinator |
| 41 // has a chance to reschedule base on remaining work. |
| 42 BackgroundScheduler.schedule(context, DEFER_START_SECONDS); |
| 43 |
| 44 // Now initiate processing. |
| 39 processBackgroundRequests(bundle, OfflinePageUtils.getDeviceConditions(c
ontext), waiter); | 45 processBackgroundRequests(bundle, OfflinePageUtils.getDeviceConditions(c
ontext), waiter); |
| 40 | 46 |
| 41 // Gather UMA data to measure how often the user's machine is amenable t
o background | 47 // Gather UMA data to measure how often the user's machine is amenable t
o background |
| 42 // loading when we wake to do a task. | 48 // loading when we wake to do a task. |
| 43 long taskScheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(bun
dle); | 49 long taskScheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(bun
dle); |
| 44 OfflinePageUtils.recordWakeupUMA(context, taskScheduledTimeMillis); | 50 OfflinePageUtils.recordWakeupUMA(context, taskScheduledTimeMillis); |
| 45 | 51 |
| 46 return true; | 52 return true; |
| 47 } | 53 } |
| 48 | 54 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 73 // Release the wake lock. | 79 // Release the wake lock. |
| 74 Log.d(TAG, "onProcessingDone"); | 80 Log.d(TAG, "onProcessingDone"); |
| 75 waiter.onWaitDone(); | 81 waiter.onWaitDone(); |
| 76 } | 82 } |
| 77 }; | 83 }; |
| 78 | 84 |
| 79 // Pass the activation on to the bridge to the C++ RequestCoordinator. | 85 // Pass the activation on to the bridge to the C++ RequestCoordinator. |
| 80 mBridge.startProcessing(deviceConditions, callback); | 86 mBridge.startProcessing(deviceConditions, callback); |
| 81 } | 87 } |
| 82 } | 88 } |
| OLD | NEW |