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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/TaskExtrasPacker.java

Issue 2697493002: [Offline pages] Implementation of OfflineBackgroundTask using background_task_scheduler (Closed)
Patch Set: Fixing compilation issues, addressing feedback Created 3 years, 9 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 android.annotation.TargetApi;
8 import android.os.Build;
9 import android.os.Bundle; 7 import android.os.Bundle;
10 import android.os.PersistableBundle;
11 8
12 import org.chromium.chrome.browser.ChromeBackgroundService; 9 import org.chromium.chrome.browser.ChromeBackgroundService;
13 10
14 /** 11 /**
15 * Class to put our custom task information into the task bundle. 12 * Class to put our custom task information into the task bundle.
16 */ 13 */
17 public class TaskExtrasPacker { 14 public class TaskExtrasPacker {
18 /** Bundle key for the timestamp in milliseconds when the request started. * / 15 /** Bundle key for the timestamp in milliseconds when the request started. * /
19 public static final String SCHEDULED_TIME_TAG = "ScheduleTime"; 16 public static final String SCHEDULED_TIME_TAG = "ScheduleTime";
20 17
21 // Trigger condition tags. 18 // Trigger condition tags.
22 private static final String POWER_CONNECTED_TAG = "PowerConnected"; 19 private static final String POWER_CONNECTED_TAG = "PowerConnected";
23 private static final String BATTERY_PERCENTAGE_TAG = "BatteryPercentage"; 20 private static final String BATTERY_PERCENTAGE_TAG = "BatteryPercentage";
24 private static final String UNMETERED_NETWORK_TAG = "UnmeteredNetwork"; 21 private static final String UNMETERED_NETWORK_TAG = "UnmeteredNetwork";
25 22
26 /** Puts requirement to hold a wakelock in the bundle. */ 23 /** Puts requirement to hold a wakelock in the bundle. */
27 public static void packHoldWakelock(Bundle bundle) { 24 public static void packHoldWakelock(Bundle bundle) {
28 bundle.putBoolean(ChromeBackgroundService.HOLD_WAKELOCK, true); 25 bundle.putBoolean(ChromeBackgroundService.HOLD_WAKELOCK, true);
29 } 26 }
30 27
31 /** Puts current time into the input bundle. */ 28 /** Puts current time into the input bundle. */
32 public static void packTimeInBundle(Bundle bundle) { 29 public static void packTimeInBundle(Bundle bundle) {
33 bundle.putLong(SCHEDULED_TIME_TAG, System.currentTimeMillis()); 30 bundle.putLong(SCHEDULED_TIME_TAG, System.currentTimeMillis());
34 } 31 }
35 32
36 /** Puts current time into the input bundle. */
37 @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
Pete Williamson 2017/02/28 20:17:48 How come we don't need these anymore? Just curiuo
fgorski 2017/02/28 21:24:09 The consumed component abstracts that and we get t
38 public static void packTimeInBundle(PersistableBundle bundle) {
39 bundle.putLong(SCHEDULED_TIME_TAG, System.currentTimeMillis());
40 }
41
42 /** Extracts the time we put into the bundle. */ 33 /** Extracts the time we put into the bundle. */
43 public static long unpackTimeFromBundle(Bundle bundle) { 34 public static long unpackTimeFromBundle(Bundle bundle) {
44 return bundle.getLong(SCHEDULED_TIME_TAG); 35 return bundle.getLong(SCHEDULED_TIME_TAG);
45 } 36 }
46 37
47 /** Extracts the time we put into the bundle. */
48 @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
49 public static long unpackTimeFromBundle(PersistableBundle bundle) {
50 return bundle.getLong(SCHEDULED_TIME_TAG);
51 }
52
53 /** Puts trigger conditions into the input bundle. */ 38 /** Puts trigger conditions into the input bundle. */
54 public static void packTriggerConditionsInBundle(Bundle bundle, TriggerCondi tions conditions) { 39 public static void packTriggerConditionsInBundle(Bundle bundle, TriggerCondi tions conditions) {
55 bundle.putBoolean(POWER_CONNECTED_TAG, conditions.requirePowerConnected( )); 40 bundle.putBoolean(POWER_CONNECTED_TAG, conditions.requirePowerConnected( ));
56 bundle.putInt(BATTERY_PERCENTAGE_TAG, conditions.getMinimumBatteryPercen tage()); 41 bundle.putInt(BATTERY_PERCENTAGE_TAG, conditions.getMinimumBatteryPercen tage());
57 bundle.putBoolean(UNMETERED_NETWORK_TAG, conditions.requireUnmeteredNetw ork()); 42 bundle.putBoolean(UNMETERED_NETWORK_TAG, conditions.requireUnmeteredNetw ork());
58 } 43 }
59 44
60 /** Puts trigger conditions into the input bundle. */
61 @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
62 public static void packTriggerConditionsInBundle(
63 PersistableBundle bundle, TriggerConditions conditions) {
64 bundle.putBoolean(POWER_CONNECTED_TAG, conditions.requirePowerConnected( ));
65 bundle.putInt(BATTERY_PERCENTAGE_TAG, conditions.getMinimumBatteryPercen tage());
66 bundle.putBoolean(UNMETERED_NETWORK_TAG, conditions.requireUnmeteredNetw ork());
67 }
68
69 /** Extracts the trigger conditions we put into the bundle. */ 45 /** Extracts the trigger conditions we put into the bundle. */
70 public static TriggerConditions unpackTriggerConditionsFromBundle(Bundle bun dle) { 46 public static TriggerConditions unpackTriggerConditionsFromBundle(Bundle bun dle) {
71 boolean requirePowerConnected = bundle.getBoolean(POWER_CONNECTED_TAG, t rue); 47 boolean requirePowerConnected = bundle.getBoolean(POWER_CONNECTED_TAG, t rue);
72 int minimumBatteryPercentage = bundle.getInt(BATTERY_PERCENTAGE_TAG, 100 ); 48 int minimumBatteryPercentage = bundle.getInt(BATTERY_PERCENTAGE_TAG, 100 );
73 boolean requireUnmeteredNetwork = bundle.getBoolean(UNMETERED_NETWORK_TA G, true); 49 boolean requireUnmeteredNetwork = bundle.getBoolean(UNMETERED_NETWORK_TA G, true);
74 return new TriggerConditions( 50 return new TriggerConditions(
75 requirePowerConnected, minimumBatteryPercentage, requireUnmetere dNetwork); 51 requirePowerConnected, minimumBatteryPercentage, requireUnmetere dNetwork);
76 } 52 }
77
78 /** Extracts the trigger conditions we put into the bundle. */
79 @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
80 public static TriggerConditions unpackTriggerConditionsFromBundle(Persistabl eBundle bundle) {
81 boolean requirePowerConnected = bundle.getBoolean(POWER_CONNECTED_TAG, t rue);
82 int minimumBatteryPercentage = bundle.getInt(BATTERY_PERCENTAGE_TAG, 100 );
83 boolean requireUnmeteredNetwork = bundle.getBoolean(UNMETERED_NETWORK_TA G, true);
84 return new TriggerConditions(
85 requirePowerConnected, minimumBatteryPercentage, requireUnmetere dNetwork);
86 }
87 } 53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698