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 org.chromium.base.Callback; | 7 import org.chromium.base.Callback; |
8 import org.chromium.base.ContextUtils; | 8 import org.chromium.base.ContextUtils; |
9 import org.chromium.base.annotations.CalledByNative; | 9 import org.chromium.base.annotations.CalledByNative; |
10 import org.chromium.base.annotations.JNINamespace; | 10 import org.chromium.base.annotations.JNINamespace; |
11 | 11 |
| 12 import java.util.concurrent.TimeUnit; |
| 13 |
12 /** | 14 /** |
13 * Provides Java scheduling support from native offlining code as | 15 * Provides Java scheduling support from native offlining code as |
14 * well as JNI interface to tell native code to start processing | 16 * well as JNI interface to tell native code to start processing |
15 * queued requests. | 17 * queued requests. |
16 */ | 18 */ |
17 @JNINamespace("offline_pages::android") | 19 @JNINamespace("offline_pages::android") |
18 public class BackgroundSchedulerBridge { | 20 public class BackgroundSchedulerBridge { |
19 // Starts processing of one or more queued background requests. | 21 // Starts processing of one or more queued background requests. |
20 // Returns whether processing was started and that caller should | 22 // Returns whether processing was started and that caller should |
21 // expect a callback (once processing has completed or terminated). | 23 // expect a callback (once processing has completed or terminated). |
(...skipping 13 matching lines...) Expand all Loading... |
35 * Stops scheduled processing. | 37 * Stops scheduled processing. |
36 * @return true, as it always expects to be rescheduled. | 38 * @return true, as it always expects to be rescheduled. |
37 */ | 39 */ |
38 public static boolean stopScheduledProcessing() { | 40 public static boolean stopScheduledProcessing() { |
39 nativeStopScheduledProcessing(); | 41 nativeStopScheduledProcessing(); |
40 return true; | 42 return true; |
41 } | 43 } |
42 | 44 |
43 @CalledByNative | 45 @CalledByNative |
44 private static void schedule(TriggerConditions triggerConditions) { | 46 private static void schedule(TriggerConditions triggerConditions) { |
45 BackgroundScheduler.getInstance(ContextUtils.getApplicationContext()) | 47 BackgroundScheduler.getInstance().schedule(triggerConditions); |
46 .schedule(triggerConditions); | |
47 } | 48 } |
48 | 49 |
49 @CalledByNative | 50 @CalledByNative |
50 private static void backupSchedule(TriggerConditions triggerConditions, long
delayInSeconds) { | 51 private static void backupSchedule(TriggerConditions triggerConditions, long
delayInSeconds) { |
51 BackgroundScheduler.getInstance(ContextUtils.getApplicationContext()) | 52 BackgroundScheduler.getInstance().scheduleBackup( |
52 .scheduleBackup(triggerConditions, delayInSeconds); | 53 triggerConditions, TimeUnit.SECONDS.toMillis(delayInSeconds)); |
53 } | 54 } |
54 | 55 |
55 @CalledByNative | 56 @CalledByNative |
56 private static void unschedule() { | 57 private static void unschedule() { |
57 BackgroundScheduler.getInstance(ContextUtils.getApplicationContext()).ca
ncel(); | 58 BackgroundScheduler.getInstance().cancel(); |
58 } | 59 } |
59 | 60 |
60 @CalledByNative | 61 @CalledByNative |
61 private static boolean getPowerConditions() { | 62 private static boolean getPowerConditions() { |
62 return DeviceConditions.isPowerConnected(ContextUtils.getApplicationCont
ext()); | 63 return DeviceConditions.isPowerConnected(ContextUtils.getApplicationCont
ext()); |
63 } | 64 } |
64 | 65 |
65 @CalledByNative | 66 @CalledByNative |
66 private static int getBatteryConditions() { | 67 private static int getBatteryConditions() { |
67 return DeviceConditions.getBatteryPercentage(ContextUtils.getApplication
Context()); | 68 return DeviceConditions.getBatteryPercentage(ContextUtils.getApplication
Context()); |
(...skipping 14 matching lines...) Expand all Loading... |
82 return new TriggerConditions( | 83 return new TriggerConditions( |
83 requirePowerConnected, minimumBatteryPercentage, requireUnmetere
dNetwork); | 84 requirePowerConnected, minimumBatteryPercentage, requireUnmetere
dNetwork); |
84 } | 85 } |
85 | 86 |
86 /** Instructs the native RequestCoordinator to start processing. */ | 87 /** Instructs the native RequestCoordinator to start processing. */ |
87 private static native boolean nativeStartScheduledProcessing(boolean powerCo
nnected, | 88 private static native boolean nativeStartScheduledProcessing(boolean powerCo
nnected, |
88 int batteryPercentage, int netConnectionType, Callback<Boolean> call
back); | 89 int batteryPercentage, int netConnectionType, Callback<Boolean> call
back); |
89 /** Instructs the native RequestCoordinator to stop processing. */ | 90 /** Instructs the native RequestCoordinator to stop processing. */ |
90 private static native void nativeStopScheduledProcessing(); | 91 private static native void nativeStopScheduledProcessing(); |
91 } | 92 } |
OLD | NEW |