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

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

Issue 1985923002: Wireframe scheduler implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address BackgroundTask CR feedback from DougArnett Created 4 years, 7 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/BackgroundSchedulerBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundSchedulerBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundSchedulerBridge.java
index c3a5ba036967e4cb5a2901ddb3f25df4c6432bc5..0eadb91eda7d25436ecd502bd84ff57e4d8143f0 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundSchedulerBridge.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundSchedulerBridge.java
@@ -4,6 +4,10 @@
package org.chromium.chrome.browser.offlinepages;
+import android.content.Context;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.profiles.Profile;
@@ -15,6 +19,18 @@ import org.chromium.chrome.browser.profiles.Profile;
*/
@JNINamespace("offline_pages::android")
public class BackgroundSchedulerBridge {
+ /**
+ * Retrieves the BackgroundSchedulerBridge for the given profile, creating it the first time
+ * getForProfile is called for a given profile.
+ *
+ * @param profile The profile associated with the BackgroundSchedulerBridge to get.
+ * @param context The android context.
+ */
+ public static BackgroundSchedulerBridge getForProfile(Profile profile, Context context) {
+ ThreadUtils.assertOnUiThread();
+ sContext = context;
+ return nativeGetBackgroundSchedulerBridgeForProfile(profile);
+ }
/**
* Callback used to determine when request processing is done.
@@ -24,6 +40,38 @@ public class BackgroundSchedulerBridge {
void onProcessingDone(boolean result);
}
+ /**
+ * Creates a background scheduler bridge for a given profile.
+ * Accessible by the package for testability.
+ */
+ @VisibleForTesting
+ BackgroundSchedulerBridge(long nativeBackgroundSchedulerBridge) {
+ mNativeBackgroundSchedulerBridge = nativeBackgroundSchedulerBridge;
+ }
+
+ /**
+ * Called by the native BackgroundSchedulerBridge so that it can cache the new Java
+ * BackgroundSchedulerBridge with a pointer to the native bridge.
+ */
+ @CalledByNative
+ private static BackgroundSchedulerBridge create(long nativeBackgroundSchedulerBridge) {
+ return new BackgroundSchedulerBridge(nativeBackgroundSchedulerBridge);
+ }
+
+ /**
+ * Clears the "long" value which is actually a native pointer to the native
+ * BackgroundSchedulerBridge.
+ */
+ @CalledByNative
+ private void backgroundSchedulerBridgeDestroyed() {
+ ThreadUtils.assertOnUiThread();
+ assert mNativeBackgroundSchedulerBridge != 0;
+
+ mNativeBackgroundSchedulerBridge = 0;
+ }
+
+ private long mNativeBackgroundSchedulerBridge;
+
// Starts processing of one or more queued background requests.
// Returns whether processing was started and that caller should
// expect a callback (once processing has completed or terminated).
@@ -33,23 +81,27 @@ public class BackgroundSchedulerBridge {
// TODO(dougarnett): consider adding policy check api to let caller
// separately determine if not allowed by policy.
public static boolean startProcessing(
- Profile profile, ProcessingDoneCallback callback) {
- return nativeStartProcessing(profile, callback);
+ Context context, ProcessingDoneCallback callback) {
dougarnett 2016/05/20 18:09:56 Are we missing CalledByNative static method that r
Pete Williamson 2016/05/20 19:42:24 onProcessingDone receives the callback on the Java
dougarnett 2016/05/20 22:17:32 Yes, great. So indeed no need for Java instance fo
+ return nativeStartProcessing(context, callback);
}
@CalledByNative
private static void schedule() {
- // TODO(dougarnett): call GcmNetworkManager to schedule for
- // OfflinePageUtils.TASK_TAG.
+ BackgroundScheduler.schedule(sContext);
}
@CalledByNative
private static void unschedule() {
- // TODO(dougarnett): call GcmNetworkManager to unschedule for
- // OfflinePageUtils.TASK_TAG.
+ BackgroundScheduler.unschedule(sContext);
}
private static native boolean nativeStartProcessing(
- Profile profile, ProcessingDoneCallback callback);
+ Context context, ProcessingDoneCallback callback);
+ // Warning, function name must be on the next line, don't wrap it to the line below, or JNI
+ // won't find it when building the _jni.h file.
+ private static native BackgroundSchedulerBridge nativeGetBackgroundSchedulerBridgeForProfile(
+ Profile profile);
+
+ private static Context sContext;
}

Powered by Google App Engine
This is Rietveld 408576698