| 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; |
| 13 import org.chromium.components.offline_items_collection.OfflineItemState; | 14 import org.chromium.components.offline_items_collection.OfflineItemState; |
| 14 import org.chromium.components.offline_items_collection.OfflineItemVisuals; | 15 import org.chromium.components.offline_items_collection.OfflineItemVisuals; |
| 15 import org.chromium.content_public.browser.DownloadState; | 16 import org.chromium.content_public.browser.DownloadState; |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * Class representing the state of a single download. | 19 * Class representing the state of a single download. |
| 19 */ | 20 */ |
| 20 public final class DownloadInfo { | 21 public final class DownloadInfo { |
| 21 private final String mUrl; | 22 private final String mUrl; |
| 22 private final String mUserAgent; | 23 private final String mUserAgent; |
| 23 private final String mMimeType; | 24 private final String mMimeType; |
| 24 private final String mCookie; | 25 private final String mCookie; |
| 25 private final String mFileName; | 26 private final String mFileName; |
| 26 private final String mDescription; | 27 private final String mDescription; |
| 27 private final String mFilePath; | 28 private final String mFilePath; |
| 28 private final String mReferrer; | 29 private final String mReferrer; |
| 29 private final String mOriginalUrl; | 30 private final String mOriginalUrl; |
| 30 private final long mBytesReceived; | 31 private final long mBytesReceived; |
| 31 private final String mDownloadGuid; | 32 private final String mDownloadGuid; |
| 32 private final boolean mHasUserGesture; | 33 private final boolean mHasUserGesture; |
| 33 private final String mContentDisposition; | 34 private final String mContentDisposition; |
| 34 private final boolean mIsGETRequest; | 35 private final boolean mIsGETRequest; |
| 35 private final int mPercentCompleted; | 36 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; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 mPercentCompleted = builder.mPercentCompleted; |
| 68 mProgress = builder.mProgress; |
| 66 mTimeRemainingInMillis = builder.mTimeRemainingInMillis; | 69 mTimeRemainingInMillis = builder.mTimeRemainingInMillis; |
| 67 mIsResumable = builder.mIsResumable; | 70 mIsResumable = builder.mIsResumable; |
| 68 mIsPaused = builder.mIsPaused; | 71 mIsPaused = builder.mIsPaused; |
| 69 mIsOffTheRecord = builder.mIsOffTheRecord; | 72 mIsOffTheRecord = builder.mIsOffTheRecord; |
| 70 mIsOfflinePage = builder.mIsOfflinePage; | 73 mIsOfflinePage = builder.mIsOfflinePage; |
| 71 mState = builder.mState; | 74 mState = builder.mState; |
| 72 mLastAccessTime = builder.mLastAccessTime; | 75 mLastAccessTime = builder.mLastAccessTime; |
| 73 | 76 |
| 74 if (builder.mContentId != null) { | 77 if (builder.mContentId != null) { |
| 75 mContentId = builder.mContentId; | 78 mContentId = builder.mContentId; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 return mContentDisposition; | 140 return mContentDisposition; |
| 138 } | 141 } |
| 139 | 142 |
| 140 /** | 143 /** |
| 141 * @return percent completed as an integer, -1 if there is no download progr
ess. | 144 * @return percent completed as an integer, -1 if there is no download progr
ess. |
| 142 */ | 145 */ |
| 143 public int getPercentCompleted() { | 146 public int getPercentCompleted() { |
| 144 return mPercentCompleted; | 147 return mPercentCompleted; |
| 145 } | 148 } |
| 146 | 149 |
| 150 public Progress getProgress() { |
| 151 return mProgress; |
| 152 } |
| 153 |
| 147 /** | 154 /** |
| 148 * @return Remaining download time in milliseconds or -1 if it is unknown. | 155 * @return Remaining download time in milliseconds or -1 if it is unknown. |
| 149 */ | 156 */ |
| 150 public long getTimeRemainingInMillis() { | 157 public long getTimeRemainingInMillis() { |
| 151 return mTimeRemainingInMillis; | 158 return mTimeRemainingInMillis; |
| 152 } | 159 } |
| 153 | 160 |
| 154 public boolean isResumable() { | 161 public boolean isResumable() { |
| 155 return mIsResumable; | 162 return mIsResumable; |
| 156 } | 163 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 .setDescription(item.description) | 232 .setDescription(item.description) |
| 226 .setIsTransient(item.isTransient) | 233 .setIsTransient(item.isTransient) |
| 227 .setLastAccessTime(item.lastAccessedTimeMs) | 234 .setLastAccessTime(item.lastAccessedTimeMs) |
| 228 .setIsOpenable(item.isOpenable) | 235 .setIsOpenable(item.isOpenable) |
| 229 .setOriginalUrl(item.originalUrl) | 236 .setOriginalUrl(item.originalUrl) |
| 230 .setIsOffTheRecord(item.isOffTheRecord) | 237 .setIsOffTheRecord(item.isOffTheRecord) |
| 231 .setState(state) | 238 .setState(state) |
| 232 .setIsPaused(item.state == OfflineItemState.PAUSED) | 239 .setIsPaused(item.state == OfflineItemState.PAUSED) |
| 233 .setIsResumable(item.isResumable) | 240 .setIsResumable(item.isResumable) |
| 234 .setBytesReceived(item.receivedBytes) | 241 .setBytesReceived(item.receivedBytes) |
| 235 .setPercentCompleted(item.percentCompleted) | 242 .setProgress(item.progress) |
| 236 .setTimeRemainingInMillis(item.timeRemainingMs) | 243 .setTimeRemainingInMillis(item.timeRemainingMs) |
| 237 .setIcon(visuals == null ? null : visuals.icon) | 244 .setIcon(visuals == null ? null : visuals.icon) |
| 238 .build(); | 245 .build(); |
| 239 } | 246 } |
| 240 | 247 |
| 241 /** | 248 /** |
| 242 * Helper class for building the DownloadInfo object. | 249 * Helper class for building the DownloadInfo object. |
| 243 */ | 250 */ |
| 244 public static class Builder { | 251 public static class Builder { |
| 245 private String mUrl; | 252 private String mUrl; |
| 246 private String mUserAgent; | 253 private String mUserAgent; |
| 247 private String mMimeType; | 254 private String mMimeType; |
| 248 private String mCookie; | 255 private String mCookie; |
| 249 private String mFileName; | 256 private String mFileName; |
| 250 private String mDescription; | 257 private String mDescription; |
| 251 private String mFilePath; | 258 private String mFilePath; |
| 252 private String mReferrer; | 259 private String mReferrer; |
| 253 private String mOriginalUrl; | 260 private String mOriginalUrl; |
| 254 private long mBytesReceived; | 261 private long mBytesReceived; |
| 255 private boolean mIsGETRequest; | 262 private boolean mIsGETRequest; |
| 256 private String mDownloadGuid; | 263 private String mDownloadGuid; |
| 257 private boolean mHasUserGesture; | 264 private boolean mHasUserGesture; |
| 258 private String mContentDisposition; | 265 private String mContentDisposition; |
| 259 private int mPercentCompleted = -1; | 266 private int mPercentCompleted = -1; |
| 267 private Progress mProgress; |
| 260 private long mTimeRemainingInMillis; | 268 private long mTimeRemainingInMillis; |
| 261 private boolean mIsResumable = true; | 269 private boolean mIsResumable = true; |
| 262 private boolean mIsPaused; | 270 private boolean mIsPaused; |
| 263 private boolean mIsOffTheRecord; | 271 private boolean mIsOffTheRecord; |
| 264 private boolean mIsOfflinePage; | 272 private boolean mIsOfflinePage; |
| 265 private int mState = DownloadState.IN_PROGRESS; | 273 private int mState = DownloadState.IN_PROGRESS; |
| 266 private long mLastAccessTime; | 274 private long mLastAccessTime; |
| 267 private ContentId mContentId; | 275 private ContentId mContentId; |
| 268 private boolean mIsOpenable = true; | 276 private boolean mIsOpenable = true; |
| 269 private boolean mIsTransient; | 277 private boolean mIsTransient; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 mContentDisposition = contentDisposition; | 346 mContentDisposition = contentDisposition; |
| 339 return this; | 347 return this; |
| 340 } | 348 } |
| 341 | 349 |
| 342 public Builder setPercentCompleted(int percentCompleted) { | 350 public Builder setPercentCompleted(int percentCompleted) { |
| 343 assert percentCompleted <= 100; | 351 assert percentCompleted <= 100; |
| 344 mPercentCompleted = percentCompleted; | 352 mPercentCompleted = percentCompleted; |
| 345 return this; | 353 return this; |
| 346 } | 354 } |
| 347 | 355 |
| 356 public Builder setProgress(OfflineItem.Progress progress) { |
| 357 mProgress = progress; |
| 358 if (mProgress.max != 0) { |
| 359 mPercentCompleted = (int) (progress.value / progress.max); |
| 360 } |
| 361 return this; |
| 362 } |
| 363 |
| 348 public Builder setTimeRemainingInMillis(long timeRemainingInMillis) { | 364 public Builder setTimeRemainingInMillis(long timeRemainingInMillis) { |
| 349 mTimeRemainingInMillis = timeRemainingInMillis; | 365 mTimeRemainingInMillis = timeRemainingInMillis; |
| 350 return this; | 366 return this; |
| 351 } | 367 } |
| 352 | 368 |
| 353 public Builder setIsResumable(boolean isResumable) { | 369 public Builder setIsResumable(boolean isResumable) { |
| 354 mIsResumable = isResumable; | 370 mIsResumable = isResumable; |
| 355 return this; | 371 return this; |
| 356 } | 372 } |
| 357 | 373 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 .setDescription(downloadInfo.getDescription()) | 435 .setDescription(downloadInfo.getDescription()) |
| 420 .setFilePath(downloadInfo.getFilePath()) | 436 .setFilePath(downloadInfo.getFilePath()) |
| 421 .setReferrer(downloadInfo.getReferrer()) | 437 .setReferrer(downloadInfo.getReferrer()) |
| 422 .setOriginalUrl(downloadInfo.getOriginalUrl()) | 438 .setOriginalUrl(downloadInfo.getOriginalUrl()) |
| 423 .setBytesReceived(downloadInfo.getBytesReceived()) | 439 .setBytesReceived(downloadInfo.getBytesReceived()) |
| 424 .setDownloadGuid(downloadInfo.getDownloadGuid()) | 440 .setDownloadGuid(downloadInfo.getDownloadGuid()) |
| 425 .setHasUserGesture(downloadInfo.hasUserGesture()) | 441 .setHasUserGesture(downloadInfo.hasUserGesture()) |
| 426 .setContentDisposition(downloadInfo.getContentDisposition()) | 442 .setContentDisposition(downloadInfo.getContentDisposition()) |
| 427 .setIsGETRequest(downloadInfo.isGETRequest()) | 443 .setIsGETRequest(downloadInfo.isGETRequest()) |
| 428 .setPercentCompleted(downloadInfo.getPercentCompleted()) | 444 .setPercentCompleted(downloadInfo.getPercentCompleted()) |
| 445 .setProgress(downloadInfo.getProgress()) |
| 429 .setTimeRemainingInMillis(downloadInfo.getTimeRemainingInMil
lis()) | 446 .setTimeRemainingInMillis(downloadInfo.getTimeRemainingInMil
lis()) |
| 430 .setIsResumable(downloadInfo.isResumable()) | 447 .setIsResumable(downloadInfo.isResumable()) |
| 431 .setIsPaused(downloadInfo.isPaused()) | 448 .setIsPaused(downloadInfo.isPaused()) |
| 432 .setIsOffTheRecord(downloadInfo.isOffTheRecord()) | 449 .setIsOffTheRecord(downloadInfo.isOffTheRecord()) |
| 433 .setIsOfflinePage(downloadInfo.isOfflinePage()) | 450 .setIsOfflinePage(downloadInfo.isOfflinePage()) |
| 434 .setState(downloadInfo.state()) | 451 .setState(downloadInfo.state()) |
| 435 .setLastAccessTime(downloadInfo.getLastAccessTime()) | 452 .setLastAccessTime(downloadInfo.getLastAccessTime()) |
| 436 .setIcon(downloadInfo.getIcon()); | 453 .setIcon(downloadInfo.getIcon()); |
| 437 return builder; | 454 return builder; |
| 438 } | 455 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 460 .setOriginalUrl(originalUrl) | 477 .setOriginalUrl(originalUrl) |
| 461 .setPercentCompleted(percentCompleted) | 478 .setPercentCompleted(percentCompleted) |
| 462 .setReferrer(referrerUrl) | 479 .setReferrer(referrerUrl) |
| 463 .setState(state) | 480 .setState(state) |
| 464 .setTimeRemainingInMillis(timeRemainingInMs) | 481 .setTimeRemainingInMillis(timeRemainingInMs) |
| 465 .setLastAccessTime(lastAccessTime) | 482 .setLastAccessTime(lastAccessTime) |
| 466 .setUrl(url) | 483 .setUrl(url) |
| 467 .build(); | 484 .build(); |
| 468 } | 485 } |
| 469 } | 486 } |
| OLD | NEW |