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

Unified Diff: components/offline_items_collection/core/android/java/src/org/chromium/components/offline_items_collection/OfflineItem.java

Issue 2861863002: offline_items_collection : Added helper class to determine progress (Closed)
Patch Set: comments Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
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() {

Powered by Google App Engine
This is Rietveld 408576698