Chromium Code Reviews| 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; |
|
dewittj
2016/05/20 21:52:30
This should not be stored here, it's probably bett
Pete Williamson
2016/05/23 19:36:30
Done, but then I deleted the function.
|
| + 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) { |
|
dewittj
2016/05/20 21:52:31
It's not clear that you really /need/ a bridge at
Pete Williamson
2016/05/23 19:36:30
Good point, now that you showed me how to get a co
|
| + 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) { |
| + return nativeStartProcessing(context, callback); |
| } |
| @CalledByNative |
| private static void schedule() { |
| - // TODO(dougarnett): call GcmNetworkManager to schedule for |
| - // OfflinePageUtils.TASK_TAG. |
| + BackgroundScheduler.schedule(sContext); |
|
dewittj
2016/05/20 21:52:30
Instead, pass a Context in here or use the applica
Pete Williamson
2016/05/23 19:36:30
Done.
|
| } |
| @CalledByNative |
| private static void unschedule() { |
| - // TODO(dougarnett): call GcmNetworkManager to unschedule for |
| - // OfflinePageUtils.TASK_TAG. |
| + BackgroundScheduler.unschedule(sContext); |
|
dewittj
2016/05/20 21:52:30
same.
Pete Williamson
2016/05/23 19:36:30
Done.
|
| } |
| 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; |
| } |