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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/BackgroundSchedulerBridge.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 unified diff | Download patch
OLDNEW
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 org.chromium.base.ContextUtils; 7 import org.chromium.base.ContextUtils;
8 import org.chromium.base.annotations.CalledByNative; 8 import org.chromium.base.annotations.CalledByNative;
9 import org.chromium.base.annotations.JNINamespace; 9 import org.chromium.base.annotations.JNINamespace;
10 import org.chromium.chrome.browser.offlinepages.interfaces.SchedulerBridge;
10 11
11 /** 12 /**
12 * Provides Java scheduling support from native offlining code as 13 * Provides Java scheduling support from native offlining code as
13 * well as JNI interface to tell native code to start processing 14 * well as JNI interface to tell native code to start processing
14 * queued requests. 15 * queued requests.
15 */ 16 */
16 @JNINamespace("offline_pages::android") 17 @JNINamespace("offline_pages::android")
17 public class BackgroundSchedulerBridge { 18 public class BackgroundSchedulerBridge {
18 /**
19 * Callback used to determine when request processing is done.
20 */
21 public interface ProcessingDoneCallback {
22 @CalledByNative("ProcessingDoneCallback")
23 void onProcessingDone(boolean result);
24 }
25
26 // Starts processing of one or more queued background requests. 19 // Starts processing of one or more queued background requests.
27 // Returns whether processing was started and that caller should 20 // Returns whether processing was started and that caller should
28 // expect a callback (once processing has completed or terminated). 21 // expect a callback (once processing has completed or terminated).
29 // If processing was already active or not able to process for 22 // If processing was already active or not able to process for
30 // some other reason, returns false and this calling instance will 23 // some other reason, returns false and this calling instance will
31 // not receive a callback. 24 // not receive a callback.
32 // TODO(dougarnett): consider adding policy check api to let caller 25 // TODO(dougarnett): consider adding policy check api to let caller
33 // separately determine if not allowed by policy. 26 // separately determine if not allowed by policy.
34 public static boolean startProcessing(ProcessingDoneCallback callback) { 27 public static boolean startProcessing(
28 SchedulerBridge.ProcessingDoneCallback callback) {
35 return nativeStartProcessing(callback); 29 return nativeStartProcessing(callback);
36 } 30 }
37 31
38 @CalledByNative 32 @CalledByNative
39 private static void schedule() { 33 private static void schedule() {
40 BackgroundScheduler.schedule(ContextUtils.getApplicationContext()); 34 BackgroundScheduler.schedule(ContextUtils.getApplicationContext());
41 } 35 }
42 36
43 @CalledByNative 37 @CalledByNative
44 private static void unschedule() { 38 private static void unschedule() {
45 BackgroundScheduler.unschedule(ContextUtils.getApplicationContext()); 39 BackgroundScheduler.unschedule(ContextUtils.getApplicationContext());
46 } 40 }
47 41
48 private static native boolean nativeStartProcessing(ProcessingDoneCallback c allback); 42 /**
43 * This interface defines the JNI callback available to native code. It must exactly match the
44 * {@link SchedulerBridge.ProcessingDoneCallback} interface (which is not ti ed to JNI and may be
45 * use for unit testing). Due to JNI restrictions, the interface for this c allback must be
46 * declared in the same java file, so there is only one XXX_jni.h file to in clude on the C++
47 * side (Otherwise, we get the JNI function RegisterNativesImpl multiply def ined, and can't
48 * compile). This interface is exactly the same as the one in SchedulerBridg e, and we're using
49 * duck typing to make sure the callback can work.
50 */
51 public interface ProcessingDoneCallback {
52 @CalledByNative("ProcessingDoneCallback")
53 void onProcessingDone(boolean result);
54 }
55
56 private static native boolean nativeStartProcessing(
57 SchedulerBridge.ProcessingDoneCallback callback);
49 } 58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698