Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4478)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java

Issue 2030773002: Add unit tests for the Background Scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback per DougArnett Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java
index 424111ac620695dbe80d51906a4708ce171d27ad..2441b097ab38b40a1f9311669ed57cbf88f1423b 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundOfflinerTask.java
@@ -7,12 +7,21 @@ package org.chromium.chrome.browser.offlinepages;
import android.content.Context;
import android.os.Bundle;
+import org.chromium.base.VisibleForTesting;
+import org.chromium.chrome.browser.offlinepages.interfaces.SchedulerBridge;
+
/**
* Handles servicing of background offlining requests coming via the GcmNetworkManager.
*/
-public class BackgroundOfflinerTask implements BackgroundSchedulerBridge.ProcessingDoneCallback {
+public class BackgroundOfflinerTask implements SchedulerBridge.ProcessingDoneCallback {
private static final String TAG = "BackgroundTask";
+ public BackgroundOfflinerTask(SchedulerBridge bridge) {
+ mBridge = bridge;
+ }
+
+ private final SchedulerBridge mBridge;
+
/**
* Triggers processing of background offlining requests. This is called when
* system conditions are appropriate for background offlining, typically from the
@@ -22,14 +31,13 @@ public class BackgroundOfflinerTask implements BackgroundSchedulerBridge.Process
*
* @returns true for success
*/
- public static boolean startBackgroundRequests(Context context, Bundle bundle) {
- BackgroundOfflinerTask task = new BackgroundOfflinerTask();
- task.processBackgroundRequests(bundle);
+ public boolean startBackgroundRequests(Context context, Bundle bundle) {
+ processBackgroundRequests(bundle);
// Gather UMA data to measure how often the user's machine is amenable to background
// loading when we wake to do a task.
- long millisSinceBootTask = bundle.getLong(BackgroundScheduler.DATE_TAG);
- OfflinePageUtils.recordWakeupUMA(context, millisSinceBootTask);
+ long millisTaskStart = TaskExtrasPacker.unpackTimeFromBundle(bundle);
dougarnett 2016/06/03 21:51:53 usually see Millis as suffix. Also, isn't this the
Pete Williamson 2016/06/03 23:52:29 Done.
+ OfflinePageUtils.recordWakeupUMA(context, millisTaskStart);
return true;
}
@@ -37,7 +45,10 @@ public class BackgroundOfflinerTask implements BackgroundSchedulerBridge.Process
/**
* Triggers processing of background offlining requests.
*/
- private void processBackgroundRequests(Bundle bundle) {
+ // TODO(petewil): Change back to private when UMA works in the test, and test
+ // startBackgroundRequests instead of this method.
+ @VisibleForTesting
+ public void processBackgroundRequests(Bundle bundle) {
// TODO(petewil): Nothing is holding the Wake Lock. We need some solution to
// keep hold of it. Options discussed so far are having a fresh set of functions
// to grab and release a countdown latch, or holding onto the wake lock ourselves,
@@ -48,7 +59,7 @@ public class BackgroundOfflinerTask implements BackgroundSchedulerBridge.Process
// Pass the activation on to the bridge to the C++ RequestCoordinator.
// Callback will hold onto the reference keeping this instance alive.
- BackgroundSchedulerBridge.startProcessing(this);
+ mBridge.startProcessing(this);
}
/**

Powered by Google App Engine
This is Rietveld 408576698