Chromium Code Reviews| 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"; | |
| 18 | 21 |
| 19 public BackgroundOfflinerTask(BackgroundSchedulerProcessor bridge) { | 22 public BackgroundOfflinerTask(BackgroundSchedulerProcessor bridge) { |
| 20 mBridge = bridge; | 23 mBridge = bridge; |
| 21 } | 24 } |
| 22 | 25 |
| 23 private final BackgroundSchedulerProcessor mBridge; | 26 private final BackgroundSchedulerProcessor mBridge; |
| 24 | 27 |
| 25 /** | 28 /** |
| 26 * Triggers processing of background offlining requests. This is called whe n | 29 * Triggers processing of background offlining requests. This is called whe n |
| 27 * system conditions are appropriate for background offlining, typically fro m the | 30 * system conditions are appropriate for background offlining, typically fro m the |
| 28 * GcmTaskService onRunTask() method. In response, we will start the | 31 * GcmTaskService onRunTask() method. In response, we will start the |
| 29 * task processing by passing the call along to the C++ RequestCoordinator. | 32 * task processing by passing the call along to the C++ RequestCoordinator. |
| 30 * Also starts UMA collection. | 33 * Also starts UMA collection. |
| 31 * | 34 * |
| 32 * @returns true for success | 35 * @returns true for success |
| 33 */ | 36 */ |
| 34 public boolean startBackgroundRequests(Context context, Bundle bundle) { | 37 public boolean startBackgroundRequests(Context context, Bundle bundle, |
| 38 ChromeBackgroundServiceWaiter waiter) { | |
| 39 mWaiter = waiter; | |
| 35 processBackgroundRequests(bundle); | 40 processBackgroundRequests(bundle); |
| 36 | 41 |
| 37 // Gather UMA data to measure how often the user's machine is amenable t o background | 42 // 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. | 43 // loading when we wake to do a task. |
| 39 long taskScheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(bun dle); | 44 long taskScheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(bun dle); |
| 40 OfflinePageUtils.recordWakeupUMA(context, taskScheduledTimeMillis); | 45 OfflinePageUtils.recordWakeupUMA(context, taskScheduledTimeMillis); |
| 41 | 46 |
| 42 return true; | 47 return true; |
| 43 } | 48 } |
| 44 | 49 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 57 | 62 |
| 58 // TODO(petewil): Decode the TriggerConditions from the bundle. | 63 // TODO(petewil): Decode the TriggerConditions from the bundle. |
| 59 | 64 |
| 60 Callback<Boolean> callback = new Callback<Boolean>() { | 65 Callback<Boolean> callback = new Callback<Boolean>() { |
| 61 /** | 66 /** |
| 62 * Callback function which indicates completion of background work. | 67 * Callback function which indicates completion of background work. |
| 63 * @param result - true if work was actually done (used for UMA). | 68 * @param result - true if work was actually done (used for UMA). |
| 64 */ | 69 */ |
| 65 @Override | 70 @Override |
| 66 public void onResult(Boolean result) { | 71 public void onResult(Boolean result) { |
| 67 // TODO(petewil): Release the wake lock. | 72 // Release the wake lock. |
| 73 Log.d(TAG, "onProcessingDone"); | |
| 74 mWaiter.onWaitDone(); | |
| 68 } | 75 } |
| 69 }; | 76 }; |
| 70 | 77 |
| 71 // Pass the activation on to the bridge to the C++ RequestCoordinator. | 78 // Pass the activation on to the bridge to the C++ RequestCoordinator. |
| 72 mBridge.startProcessing(callback); | 79 mBridge.startProcessing(callback); |
| 73 } | 80 } |
| 81 | |
| 82 private ChromeBackgroundServiceWaiter mWaiter; | |
|
dougarnett
2016/06/13 21:53:35
members before methods
Pete Williamson
2016/06/13 23:23:10
Done.
| |
| 74 } | 83 } |
| OLD | NEW |