| Index: components/offline_items_collection/core/android/java/src/org/chromium/components/offline_items_collection/OfflineItem.java
|
| diff --git a/components/offline_items_collection/core/android/java/src/org/chromium/components/offline_items_collection/OfflineItem.java b/components/offline_items_collection/core/android/java/src/org/chromium/components/offline_items_collection/OfflineItem.java
|
| index c4d734d78baf6af413003f76532d3e683c1891b9..000f0a2e08f471497c843343abe305a58a91f696 100644
|
| --- a/components/offline_items_collection/core/android/java/src/org/chromium/components/offline_items_collection/OfflineItem.java
|
| +++ b/components/offline_items_collection/core/android/java/src/org/chromium/components/offline_items_collection/OfflineItem.java
|
| @@ -15,6 +15,57 @@ import org.chromium.base.annotations.SuppressFBWarnings;
|
| */
|
| @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
| public class OfflineItem {
|
| + /**
|
| + * This class is the Java counterpart to the C++ OfflineItemProgress
|
| + * (components/offline_items_collection/core/offline_item.h) class.
|
| + */
|
| + public static class Progress {
|
| + public final long value;
|
| + public final Long max;
|
| + @OfflineItemProgressUnit
|
| + public final int unit;
|
| +
|
| + public Progress(long value, Long max, int unit) {
|
| + this.value = value;
|
| + this.max = max;
|
| + this.unit = unit;
|
| + }
|
| +
|
| + /** Helper method to create an indeterminate progress. */
|
| + public static Progress createIndeterminateProgress() {
|
| + return new Progress(0, null, OfflineItemProgressUnit.PERCENTAGE);
|
| + }
|
| +
|
| + /** Whether the progress is indeterminate. */
|
| + public boolean isIndeterminate() {
|
| + return max == null;
|
| + }
|
| +
|
| + /** Returns the percentage value. Should not be called on an indeterminate progress. */
|
| + public int getPercentage() {
|
| + assert max != null;
|
| + return max == 0 ? 100 : (int) (value * 100 / max);
|
| + }
|
| +
|
| + @Override
|
| + public boolean equals(Object obj) {
|
| + if (obj instanceof Progress) {
|
| + Progress other = (Progress) obj;
|
| + return value == other.value && unit == other.unit
|
| + && (max == other.max || (max != null && max.equals(other.max)));
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + @Override
|
| + public int hashCode() {
|
| + int result = (int) value;
|
| + result = 31 * result + (max == null ? 0 : max.hashCode());
|
| + result = 31 * result + unit;
|
| + return result;
|
| + }
|
| + }
|
| +
|
| public ContentId id;
|
|
|
| // Display metadata.
|
| @@ -42,7 +93,7 @@ public class OfflineItem {
|
| public boolean isResumable;
|
| public boolean allowMetered;
|
| public long receivedBytes;
|
| - public int percentCompleted;
|
| + public Progress progress;
|
| public long timeRemainingMs;
|
|
|
| public OfflineItem() {
|
|
|