OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.components.offline_items_collection; | 5 package org.chromium.components.offline_items_collection; |
6 | 6 |
7 import org.chromium.base.annotations.SuppressFBWarnings; | 7 import org.chromium.base.annotations.SuppressFBWarnings; |
8 | 8 |
9 /** | 9 /** |
10 * This class is the Java counterpart to the C++ OfflineItem | 10 * This class is the Java counterpart to the C++ OfflineItem |
11 * (components/offline_items_collection/core/offline_item.h) class. | 11 * (components/offline_items_collection/core/offline_item.h) class. |
12 * | 12 * |
13 * For all member variable descriptions see the C++ class. | 13 * For all member variable descriptions see the C++ class. |
14 * TODO(dtrainor): Investigate making all class members for this and the C++ cou nterpart const. | 14 * TODO(dtrainor): Investigate making all class members for this and the C++ cou nterpart const. |
15 */ | 15 */ |
16 @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") | 16 @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") |
17 public class OfflineItem { | 17 public class OfflineItem { |
18 /** | |
19 * This class is the Java counterpart to the C++ OfflineItemProgress | |
20 * (components/offline_items_collection/core/offline_item.h) class. | |
21 */ | |
22 public static class Progress { | |
23 public final long value; | |
24 public final Long max; | |
25 @OfflineItemProgressUnit | |
26 public final int unit; | |
27 | |
28 public Progress(long value, Long max, int unit) { | |
29 this.value = value; | |
30 this.max = max; | |
31 this.unit = unit; | |
32 } | |
33 | |
34 /** Helper method to create an indeterminate progress. */ | |
35 public static Progress createIndeterminateProgress() { | |
36 return new Progress(0, null, OfflineItemProgressUnit.PERCENTAGE); | |
37 } | |
38 | |
39 /** Whether the progress is indeterminate. */ | |
40 public boolean isIndeterminate() { | |
41 return max == null; | |
42 } | |
43 | |
44 /** Returns the percentage value. Should not be called on an indetermina te progress. */ | |
45 public int getPercentage() { | |
46 assert max != null; | |
47 return (int) (value * 100 / max); | |
48 } | |
49 | |
50 @Override | |
51 public boolean equals(Object obj) { | |
52 if (obj instanceof Progress) { | |
53 Progress other = (Progress) obj; | |
54 return value == other.value && unit == other.unit | |
55 && (max == other.max || (max != null && max.equals(other .max))); | |
56 } | |
57 return false; | |
58 } | |
59 | |
60 @Override | |
61 public int hashCode() { | |
62 int result = (int) value; | |
63 result = (int) (31 * result + (max == null ? 0 : max)); | |
David Trainor- moved to gerrit
2017/05/09 05:36:01
max.hashCode()?
shaktisahu
2017/05/09 19:04:32
Done.
| |
64 result = 31 * result + unit; | |
65 return result; | |
66 } | |
67 } | |
68 | |
18 public ContentId id; | 69 public ContentId id; |
19 | 70 |
20 // Display metadata. | 71 // Display metadata. |
21 public String title; | 72 public String title; |
22 public String description; | 73 public String description; |
23 @OfflineItemFilter | 74 @OfflineItemFilter |
24 public int filter; | 75 public int filter; |
25 public boolean isTransient; | 76 public boolean isTransient; |
26 | 77 |
27 // Content Metadata. | 78 // Content Metadata. |
28 public long totalSizeBytes; | 79 public long totalSizeBytes; |
29 public boolean externallyRemoved; | 80 public boolean externallyRemoved; |
30 public long creationTimeMs; | 81 public long creationTimeMs; |
31 public long lastAccessedTimeMs; | 82 public long lastAccessedTimeMs; |
32 public boolean isOpenable; | 83 public boolean isOpenable; |
33 | 84 |
34 // Request Metadata. | 85 // Request Metadata. |
35 public String pageUrl; | 86 public String pageUrl; |
36 public String originalUrl; | 87 public String originalUrl; |
37 public boolean isOffTheRecord; | 88 public boolean isOffTheRecord; |
38 | 89 |
39 // In Progress Metadata. | 90 // In Progress Metadata. |
40 @OfflineItemState | 91 @OfflineItemState |
41 public int state; | 92 public int state; |
42 public boolean isResumable; | 93 public boolean isResumable; |
43 public boolean allowMetered; | 94 public boolean allowMetered; |
44 public long receivedBytes; | 95 public long receivedBytes; |
45 public int percentCompleted; | 96 public Progress progress; |
46 public long timeRemainingMs; | 97 public long timeRemainingMs; |
47 | 98 |
48 public OfflineItem() { | 99 public OfflineItem() { |
49 id = new ContentId(); | 100 id = new ContentId(); |
50 filter = OfflineItemFilter.FILTER_OTHER; | 101 filter = OfflineItemFilter.FILTER_OTHER; |
51 state = OfflineItemState.COMPLETE; | 102 state = OfflineItemState.COMPLETE; |
52 } | 103 } |
53 } | 104 } |
OLD | NEW |