OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.download; | 5 package org.chromium.chrome.browser.download; |
6 | 6 |
7 import android.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
8 | 8 |
9 import org.chromium.base.annotations.CalledByNative; | 9 import org.chromium.base.annotations.CalledByNative; |
10 import org.chromium.components.offline_items_collection.ContentId; | 10 import org.chromium.components.offline_items_collection.ContentId; |
11 import org.chromium.components.offline_items_collection.LegacyHelpers; | 11 import org.chromium.components.offline_items_collection.LegacyHelpers; |
12 import org.chromium.components.offline_items_collection.OfflineItem; | 12 import org.chromium.components.offline_items_collection.OfflineItem; |
| 13 import org.chromium.components.offline_items_collection.OfflineItem.Progress; |
| 14 import org.chromium.components.offline_items_collection.OfflineItemProgressUnit; |
13 import org.chromium.components.offline_items_collection.OfflineItemState; | 15 import org.chromium.components.offline_items_collection.OfflineItemState; |
14 import org.chromium.components.offline_items_collection.OfflineItemVisuals; | 16 import org.chromium.components.offline_items_collection.OfflineItemVisuals; |
15 import org.chromium.content_public.browser.DownloadState; | 17 import org.chromium.content_public.browser.DownloadState; |
16 | 18 |
17 /** | 19 /** |
18 * Class representing the state of a single download. | 20 * Class representing the state of a single download. |
19 */ | 21 */ |
20 public final class DownloadInfo { | 22 public final class DownloadInfo { |
21 private final String mUrl; | 23 private final String mUrl; |
22 private final String mUserAgent; | 24 private final String mUserAgent; |
23 private final String mMimeType; | 25 private final String mMimeType; |
24 private final String mCookie; | 26 private final String mCookie; |
25 private final String mFileName; | 27 private final String mFileName; |
26 private final String mDescription; | 28 private final String mDescription; |
27 private final String mFilePath; | 29 private final String mFilePath; |
28 private final String mReferrer; | 30 private final String mReferrer; |
29 private final String mOriginalUrl; | 31 private final String mOriginalUrl; |
30 private final long mBytesReceived; | 32 private final long mBytesReceived; |
31 private final String mDownloadGuid; | 33 private final String mDownloadGuid; |
32 private final boolean mHasUserGesture; | 34 private final boolean mHasUserGesture; |
33 private final String mContentDisposition; | 35 private final String mContentDisposition; |
34 private final boolean mIsGETRequest; | 36 private final boolean mIsGETRequest; |
35 private final int mPercentCompleted; | 37 private final Progress mProgress; |
36 private final long mTimeRemainingInMillis; | 38 private final long mTimeRemainingInMillis; |
37 private final boolean mIsResumable; | 39 private final boolean mIsResumable; |
38 private final boolean mIsPaused; | 40 private final boolean mIsPaused; |
39 private final boolean mIsOffTheRecord; | 41 private final boolean mIsOffTheRecord; |
40 private final boolean mIsOfflinePage; | 42 private final boolean mIsOfflinePage; |
41 private final int mState; | 43 private final int mState; |
42 private final long mLastAccessTime; | 44 private final long mLastAccessTime; |
43 | 45 |
44 // New variables to assist with the migration to OfflineItems. | 46 // New variables to assist with the migration to OfflineItems. |
45 private final ContentId mContentId; | 47 private final ContentId mContentId; |
46 private final boolean mIsOpenable; | 48 private final boolean mIsOpenable; |
47 private final boolean mIsTransient; | 49 private final boolean mIsTransient; |
48 private final Bitmap mIcon; | 50 private final Bitmap mIcon; |
49 | 51 |
50 private DownloadInfo(Builder builder) { | 52 private DownloadInfo(Builder builder) { |
51 mUrl = builder.mUrl; | 53 mUrl = builder.mUrl; |
52 mUserAgent = builder.mUserAgent; | 54 mUserAgent = builder.mUserAgent; |
53 mMimeType = builder.mMimeType; | 55 mMimeType = builder.mMimeType; |
54 mCookie = builder.mCookie; | 56 mCookie = builder.mCookie; |
55 mFileName = builder.mFileName; | 57 mFileName = builder.mFileName; |
56 mDescription = builder.mDescription; | 58 mDescription = builder.mDescription; |
57 mFilePath = builder.mFilePath; | 59 mFilePath = builder.mFilePath; |
58 mReferrer = builder.mReferrer; | 60 mReferrer = builder.mReferrer; |
59 mOriginalUrl = builder.mOriginalUrl; | 61 mOriginalUrl = builder.mOriginalUrl; |
60 mBytesReceived = builder.mBytesReceived; | 62 mBytesReceived = builder.mBytesReceived; |
61 mDownloadGuid = builder.mDownloadGuid; | 63 mDownloadGuid = builder.mDownloadGuid; |
62 mHasUserGesture = builder.mHasUserGesture; | 64 mHasUserGesture = builder.mHasUserGesture; |
63 mIsGETRequest = builder.mIsGETRequest; | 65 mIsGETRequest = builder.mIsGETRequest; |
64 mContentDisposition = builder.mContentDisposition; | 66 mContentDisposition = builder.mContentDisposition; |
65 mPercentCompleted = builder.mPercentCompleted; | 67 mProgress = builder.mProgress; |
66 mTimeRemainingInMillis = builder.mTimeRemainingInMillis; | 68 mTimeRemainingInMillis = builder.mTimeRemainingInMillis; |
67 mIsResumable = builder.mIsResumable; | 69 mIsResumable = builder.mIsResumable; |
68 mIsPaused = builder.mIsPaused; | 70 mIsPaused = builder.mIsPaused; |
69 mIsOffTheRecord = builder.mIsOffTheRecord; | 71 mIsOffTheRecord = builder.mIsOffTheRecord; |
70 mIsOfflinePage = builder.mIsOfflinePage; | 72 mIsOfflinePage = builder.mIsOfflinePage; |
71 mState = builder.mState; | 73 mState = builder.mState; |
72 mLastAccessTime = builder.mLastAccessTime; | 74 mLastAccessTime = builder.mLastAccessTime; |
73 | 75 |
74 if (builder.mContentId != null) { | 76 if (builder.mContentId != null) { |
75 mContentId = builder.mContentId; | 77 mContentId = builder.mContentId; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 132 } |
131 | 133 |
132 public boolean hasUserGesture() { | 134 public boolean hasUserGesture() { |
133 return mHasUserGesture; | 135 return mHasUserGesture; |
134 } | 136 } |
135 | 137 |
136 public String getContentDisposition() { | 138 public String getContentDisposition() { |
137 return mContentDisposition; | 139 return mContentDisposition; |
138 } | 140 } |
139 | 141 |
140 /** | 142 public Progress getProgress() { |
141 * @return percent completed as an integer, -1 if there is no download progr
ess. | 143 return mProgress; |
142 */ | |
143 public int getPercentCompleted() { | |
144 return mPercentCompleted; | |
145 } | 144 } |
146 | 145 |
147 /** | 146 /** |
148 * @return Remaining download time in milliseconds or -1 if it is unknown. | 147 * @return Remaining download time in milliseconds or -1 if it is unknown. |
149 */ | 148 */ |
150 public long getTimeRemainingInMillis() { | 149 public long getTimeRemainingInMillis() { |
151 return mTimeRemainingInMillis; | 150 return mTimeRemainingInMillis; |
152 } | 151 } |
153 | 152 |
154 public boolean isResumable() { | 153 public boolean isResumable() { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 .setDescription(item.description) | 224 .setDescription(item.description) |
226 .setIsTransient(item.isTransient) | 225 .setIsTransient(item.isTransient) |
227 .setLastAccessTime(item.lastAccessedTimeMs) | 226 .setLastAccessTime(item.lastAccessedTimeMs) |
228 .setIsOpenable(item.isOpenable) | 227 .setIsOpenable(item.isOpenable) |
229 .setOriginalUrl(item.originalUrl) | 228 .setOriginalUrl(item.originalUrl) |
230 .setIsOffTheRecord(item.isOffTheRecord) | 229 .setIsOffTheRecord(item.isOffTheRecord) |
231 .setState(state) | 230 .setState(state) |
232 .setIsPaused(item.state == OfflineItemState.PAUSED) | 231 .setIsPaused(item.state == OfflineItemState.PAUSED) |
233 .setIsResumable(item.isResumable) | 232 .setIsResumable(item.isResumable) |
234 .setBytesReceived(item.receivedBytes) | 233 .setBytesReceived(item.receivedBytes) |
235 .setPercentCompleted(item.percentCompleted) | 234 .setProgress(item.progress) |
236 .setTimeRemainingInMillis(item.timeRemainingMs) | 235 .setTimeRemainingInMillis(item.timeRemainingMs) |
237 .setIcon(visuals == null ? null : visuals.icon) | 236 .setIcon(visuals == null ? null : visuals.icon) |
238 .build(); | 237 .build(); |
239 } | 238 } |
240 | 239 |
241 /** | 240 /** |
242 * Helper class for building the DownloadInfo object. | 241 * Helper class for building the DownloadInfo object. |
243 */ | 242 */ |
244 public static class Builder { | 243 public static class Builder { |
245 private String mUrl; | 244 private String mUrl; |
246 private String mUserAgent; | 245 private String mUserAgent; |
247 private String mMimeType; | 246 private String mMimeType; |
248 private String mCookie; | 247 private String mCookie; |
249 private String mFileName; | 248 private String mFileName; |
250 private String mDescription; | 249 private String mDescription; |
251 private String mFilePath; | 250 private String mFilePath; |
252 private String mReferrer; | 251 private String mReferrer; |
253 private String mOriginalUrl; | 252 private String mOriginalUrl; |
254 private long mBytesReceived; | 253 private long mBytesReceived; |
255 private boolean mIsGETRequest; | 254 private boolean mIsGETRequest; |
256 private String mDownloadGuid; | 255 private String mDownloadGuid; |
257 private boolean mHasUserGesture; | 256 private boolean mHasUserGesture; |
258 private String mContentDisposition; | 257 private String mContentDisposition; |
259 private int mPercentCompleted = -1; | 258 private Progress mProgress = Progress.createIndeterminateProgress(); |
260 private long mTimeRemainingInMillis; | 259 private long mTimeRemainingInMillis; |
261 private boolean mIsResumable = true; | 260 private boolean mIsResumable = true; |
262 private boolean mIsPaused; | 261 private boolean mIsPaused; |
263 private boolean mIsOffTheRecord; | 262 private boolean mIsOffTheRecord; |
264 private boolean mIsOfflinePage; | 263 private boolean mIsOfflinePage; |
265 private int mState = DownloadState.IN_PROGRESS; | 264 private int mState = DownloadState.IN_PROGRESS; |
266 private long mLastAccessTime; | 265 private long mLastAccessTime; |
267 private ContentId mContentId; | 266 private ContentId mContentId; |
268 private boolean mIsOpenable = true; | 267 private boolean mIsOpenable = true; |
269 private boolean mIsTransient; | 268 private boolean mIsTransient; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 public Builder setHasUserGesture(boolean hasUserGesture) { | 331 public Builder setHasUserGesture(boolean hasUserGesture) { |
333 mHasUserGesture = hasUserGesture; | 332 mHasUserGesture = hasUserGesture; |
334 return this; | 333 return this; |
335 } | 334 } |
336 | 335 |
337 public Builder setContentDisposition(String contentDisposition) { | 336 public Builder setContentDisposition(String contentDisposition) { |
338 mContentDisposition = contentDisposition; | 337 mContentDisposition = contentDisposition; |
339 return this; | 338 return this; |
340 } | 339 } |
341 | 340 |
342 public Builder setPercentCompleted(int percentCompleted) { | 341 public Builder setProgress(OfflineItem.Progress progress) { |
343 assert percentCompleted <= 100; | 342 mProgress = progress; |
344 mPercentCompleted = percentCompleted; | |
345 return this; | 343 return this; |
346 } | 344 } |
347 | 345 |
348 public Builder setTimeRemainingInMillis(long timeRemainingInMillis) { | 346 public Builder setTimeRemainingInMillis(long timeRemainingInMillis) { |
349 mTimeRemainingInMillis = timeRemainingInMillis; | 347 mTimeRemainingInMillis = timeRemainingInMillis; |
350 return this; | 348 return this; |
351 } | 349 } |
352 | 350 |
353 public Builder setIsResumable(boolean isResumable) { | 351 public Builder setIsResumable(boolean isResumable) { |
354 mIsResumable = isResumable; | 352 mIsResumable = isResumable; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 .setFileName(downloadInfo.getFileName()) | 416 .setFileName(downloadInfo.getFileName()) |
419 .setDescription(downloadInfo.getDescription()) | 417 .setDescription(downloadInfo.getDescription()) |
420 .setFilePath(downloadInfo.getFilePath()) | 418 .setFilePath(downloadInfo.getFilePath()) |
421 .setReferrer(downloadInfo.getReferrer()) | 419 .setReferrer(downloadInfo.getReferrer()) |
422 .setOriginalUrl(downloadInfo.getOriginalUrl()) | 420 .setOriginalUrl(downloadInfo.getOriginalUrl()) |
423 .setBytesReceived(downloadInfo.getBytesReceived()) | 421 .setBytesReceived(downloadInfo.getBytesReceived()) |
424 .setDownloadGuid(downloadInfo.getDownloadGuid()) | 422 .setDownloadGuid(downloadInfo.getDownloadGuid()) |
425 .setHasUserGesture(downloadInfo.hasUserGesture()) | 423 .setHasUserGesture(downloadInfo.hasUserGesture()) |
426 .setContentDisposition(downloadInfo.getContentDisposition()) | 424 .setContentDisposition(downloadInfo.getContentDisposition()) |
427 .setIsGETRequest(downloadInfo.isGETRequest()) | 425 .setIsGETRequest(downloadInfo.isGETRequest()) |
428 .setPercentCompleted(downloadInfo.getPercentCompleted()) | 426 .setProgress(downloadInfo.getProgress()) |
429 .setTimeRemainingInMillis(downloadInfo.getTimeRemainingInMil
lis()) | 427 .setTimeRemainingInMillis(downloadInfo.getTimeRemainingInMil
lis()) |
430 .setIsResumable(downloadInfo.isResumable()) | 428 .setIsResumable(downloadInfo.isResumable()) |
431 .setIsPaused(downloadInfo.isPaused()) | 429 .setIsPaused(downloadInfo.isPaused()) |
432 .setIsOffTheRecord(downloadInfo.isOffTheRecord()) | 430 .setIsOffTheRecord(downloadInfo.isOffTheRecord()) |
433 .setIsOfflinePage(downloadInfo.isOfflinePage()) | 431 .setIsOfflinePage(downloadInfo.isOfflinePage()) |
434 .setState(downloadInfo.state()) | 432 .setState(downloadInfo.state()) |
435 .setLastAccessTime(downloadInfo.getLastAccessTime()) | 433 .setLastAccessTime(downloadInfo.getLastAccessTime()) |
436 .setIcon(downloadInfo.getIcon()); | 434 .setIcon(downloadInfo.getIcon()); |
437 return builder; | 435 return builder; |
438 } | 436 } |
439 } | 437 } |
440 | 438 |
441 @CalledByNative | 439 @CalledByNative |
442 private static DownloadInfo createDownloadInfo(String downloadGuid, String f
ileName, | 440 private static DownloadInfo createDownloadInfo(String downloadGuid, String f
ileName, |
443 String filePath, String url, String mimeType, long bytesReceived, bo
olean isIncognito, | 441 String filePath, String url, String mimeType, long bytesReceived, bo
olean isIncognito, |
444 int state, int percentCompleted, boolean isPaused, boolean hasUserGe
sture, | 442 int state, int percentCompleted, boolean isPaused, boolean hasUserGe
sture, |
445 boolean isResumable, String originalUrl, String referrerUrl, long ti
meRemainingInMs, | 443 boolean isResumable, String originalUrl, String referrerUrl, long ti
meRemainingInMs, |
446 long lastAccessTime) { | 444 long lastAccessTime) { |
447 String remappedMimeType = ChromeDownloadDelegate.remapGenericMimeType( | 445 String remappedMimeType = ChromeDownloadDelegate.remapGenericMimeType( |
448 mimeType, url, fileName); | 446 mimeType, url, fileName); |
| 447 Progress progress = new Progress(percentCompleted, percentCompleted == -
1 ? null : 100L, |
| 448 OfflineItemProgressUnit.PERCENTAGE); |
449 return new DownloadInfo.Builder() | 449 return new DownloadInfo.Builder() |
450 .setBytesReceived(bytesReceived) | 450 .setBytesReceived(bytesReceived) |
451 .setDescription(fileName) | 451 .setDescription(fileName) |
452 .setDownloadGuid(downloadGuid) | 452 .setDownloadGuid(downloadGuid) |
453 .setFileName(fileName) | 453 .setFileName(fileName) |
454 .setFilePath(filePath) | 454 .setFilePath(filePath) |
455 .setHasUserGesture(hasUserGesture) | 455 .setHasUserGesture(hasUserGesture) |
456 .setIsOffTheRecord(isIncognito) | 456 .setIsOffTheRecord(isIncognito) |
457 .setIsPaused(isPaused) | 457 .setIsPaused(isPaused) |
458 .setIsResumable(isResumable) | 458 .setIsResumable(isResumable) |
459 .setMimeType(remappedMimeType) | 459 .setMimeType(remappedMimeType) |
460 .setOriginalUrl(originalUrl) | 460 .setOriginalUrl(originalUrl) |
461 .setPercentCompleted(percentCompleted) | 461 .setProgress(progress) |
462 .setReferrer(referrerUrl) | 462 .setReferrer(referrerUrl) |
463 .setState(state) | 463 .setState(state) |
464 .setTimeRemainingInMillis(timeRemainingInMs) | 464 .setTimeRemainingInMillis(timeRemainingInMs) |
465 .setLastAccessTime(lastAccessTime) | 465 .setLastAccessTime(lastAccessTime) |
466 .setUrl(url) | 466 .setUrl(url) |
467 .build(); | 467 .build(); |
468 } | 468 } |
469 } | 469 } |
OLD | NEW |