Chromium Code Reviews| 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; | |
| 8 | |
| 7 import org.chromium.base.annotations.CalledByNative; | 9 import org.chromium.base.annotations.CalledByNative; |
| 8 import org.chromium.components.offline_items_collection.ContentId; | 10 import org.chromium.components.offline_items_collection.ContentId; |
| 9 import org.chromium.components.offline_items_collection.LegacyHelpers; | 11 import org.chromium.components.offline_items_collection.LegacyHelpers; |
| 10 import org.chromium.components.offline_items_collection.OfflineItem; | 12 import org.chromium.components.offline_items_collection.OfflineItem; |
| 11 import org.chromium.components.offline_items_collection.OfflineItemState; | 13 import org.chromium.components.offline_items_collection.OfflineItemState; |
| 14 import org.chromium.components.offline_items_collection.OfflineItemVisuals; | |
| 12 import org.chromium.content_public.browser.DownloadState; | 15 import org.chromium.content_public.browser.DownloadState; |
| 13 | 16 |
| 14 /** | 17 /** |
| 15 * Class representing the state of a single download. | 18 * Class representing the state of a single download. |
| 16 */ | 19 */ |
| 17 public final class DownloadInfo { | 20 public final class DownloadInfo { |
| 18 private final String mUrl; | 21 private final String mUrl; |
| 19 private final String mUserAgent; | 22 private final String mUserAgent; |
| 20 private final String mMimeType; | 23 private final String mMimeType; |
| 21 private final String mCookie; | 24 private final String mCookie; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 35 private final boolean mIsPaused; | 38 private final boolean mIsPaused; |
| 36 private final boolean mIsOffTheRecord; | 39 private final boolean mIsOffTheRecord; |
| 37 private final boolean mIsOfflinePage; | 40 private final boolean mIsOfflinePage; |
| 38 private final int mState; | 41 private final int mState; |
| 39 private final long mLastAccessTime; | 42 private final long mLastAccessTime; |
| 40 | 43 |
| 41 // New variables to assist with the migration to OfflineItems. | 44 // New variables to assist with the migration to OfflineItems. |
| 42 private final ContentId mContentId; | 45 private final ContentId mContentId; |
| 43 private final boolean mIsOpenable; | 46 private final boolean mIsOpenable; |
| 44 private final boolean mIsTransient; | 47 private final boolean mIsTransient; |
| 48 private final Bitmap mIcon; | |
| 45 | 49 |
| 46 private DownloadInfo(Builder builder) { | 50 private DownloadInfo(Builder builder) { |
| 47 mUrl = builder.mUrl; | 51 mUrl = builder.mUrl; |
| 48 mUserAgent = builder.mUserAgent; | 52 mUserAgent = builder.mUserAgent; |
| 49 mMimeType = builder.mMimeType; | 53 mMimeType = builder.mMimeType; |
| 50 mCookie = builder.mCookie; | 54 mCookie = builder.mCookie; |
| 51 mFileName = builder.mFileName; | 55 mFileName = builder.mFileName; |
| 52 mDescription = builder.mDescription; | 56 mDescription = builder.mDescription; |
| 53 mFilePath = builder.mFilePath; | 57 mFilePath = builder.mFilePath; |
| 54 mReferrer = builder.mReferrer; | 58 mReferrer = builder.mReferrer; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 67 mState = builder.mState; | 71 mState = builder.mState; |
| 68 mLastAccessTime = builder.mLastAccessTime; | 72 mLastAccessTime = builder.mLastAccessTime; |
| 69 | 73 |
| 70 if (builder.mContentId != null) { | 74 if (builder.mContentId != null) { |
| 71 mContentId = builder.mContentId; | 75 mContentId = builder.mContentId; |
| 72 } else { | 76 } else { |
| 73 mContentId = LegacyHelpers.buildLegacyContentId(mIsOfflinePage, mDow nloadGuid); | 77 mContentId = LegacyHelpers.buildLegacyContentId(mIsOfflinePage, mDow nloadGuid); |
| 74 } | 78 } |
| 75 mIsOpenable = builder.mIsOpenable; | 79 mIsOpenable = builder.mIsOpenable; |
| 76 mIsTransient = builder.mIsTransient; | 80 mIsTransient = builder.mIsTransient; |
| 81 mIcon = builder.mIcon; | |
| 77 } | 82 } |
| 78 | 83 |
| 79 public String getUrl() { | 84 public String getUrl() { |
| 80 return mUrl; | 85 return mUrl; |
| 81 } | 86 } |
| 82 | 87 |
| 83 public String getUserAgent() { | 88 public String getUserAgent() { |
| 84 return mUserAgent; | 89 return mUserAgent; |
| 85 } | 90 } |
| 86 | 91 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 } | 180 } |
| 176 | 181 |
| 177 public boolean getIsOpenable() { | 182 public boolean getIsOpenable() { |
| 178 return mIsOpenable; | 183 return mIsOpenable; |
| 179 } | 184 } |
| 180 | 185 |
| 181 public boolean getIsTransient() { | 186 public boolean getIsTransient() { |
| 182 return mIsTransient; | 187 return mIsTransient; |
| 183 } | 188 } |
| 184 | 189 |
| 190 public Bitmap getIcon() { | |
| 191 return mIcon; | |
| 192 } | |
| 193 | |
| 185 /** | 194 /** |
| 186 * Helper method to build a {@link DownloadInfo} from an {@link OfflineItem} . | 195 * Helper method to build a {@link DownloadInfo} from an {@link OfflineItem} . |
| 187 * @param item The {@link OfflineItem} to mimic. | 196 * @param item The {@link OfflineItem} to mimic. |
| 188 * @return A {@link DownloadInfo} containing the relevant fields from {@ code item}. | 197 * @return A {@link DownloadInfo} containing the relevant fields from {@ code item}. |
| 189 */ | 198 */ |
| 190 public static DownloadInfo fromOfflineItem(OfflineItem item) { | 199 public static DownloadInfo fromOfflineItem(OfflineItem item, OfflineItemVisu als visuals) { |
| 191 int state; | 200 int state; |
| 192 switch (item.state) { | 201 switch (item.state) { |
| 193 case OfflineItemState.COMPLETE: | 202 case OfflineItemState.COMPLETE: |
| 194 state = DownloadState.COMPLETE; | 203 state = DownloadState.COMPLETE; |
| 195 break; | 204 break; |
| 196 case OfflineItemState.CANCELLED: | 205 case OfflineItemState.CANCELLED: |
| 197 state = DownloadState.CANCELLED; | 206 state = DownloadState.CANCELLED; |
| 198 break; | 207 break; |
| 199 case OfflineItemState.INTERRUPTED: | 208 case OfflineItemState.INTERRUPTED: |
| 200 state = DownloadState.INTERRUPTED; | 209 state = DownloadState.INTERRUPTED; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 218 .setLastAccessTime(item.lastAccessedTimeMs) | 227 .setLastAccessTime(item.lastAccessedTimeMs) |
| 219 .setIsOpenable(item.isOpenable) | 228 .setIsOpenable(item.isOpenable) |
| 220 .setOriginalUrl(item.originalUrl) | 229 .setOriginalUrl(item.originalUrl) |
| 221 .setIsOffTheRecord(item.isOffTheRecord) | 230 .setIsOffTheRecord(item.isOffTheRecord) |
| 222 .setState(state) | 231 .setState(state) |
| 223 .setIsPaused(item.state == OfflineItemState.PAUSED) | 232 .setIsPaused(item.state == OfflineItemState.PAUSED) |
| 224 .setIsResumable(item.isResumable) | 233 .setIsResumable(item.isResumable) |
| 225 .setBytesReceived(item.receivedBytes) | 234 .setBytesReceived(item.receivedBytes) |
| 226 .setPercentCompleted(item.percentCompleted) | 235 .setPercentCompleted(item.percentCompleted) |
| 227 .setTimeRemainingInMillis(item.timeRemainingMs) | 236 .setTimeRemainingInMillis(item.timeRemainingMs) |
| 237 .setIcon(visuals != null ? visuals.icon : null) | |
|
nyquist
2017/04/13 05:08:24
Do you find this way just as easy to read as:
.set
David Trainor- moved to gerrit
2017/04/13 07:20:23
Happy to change :).
| |
| 228 .build(); | 238 .build(); |
| 229 } | 239 } |
| 230 | 240 |
| 231 /** | 241 /** |
| 232 * Helper class for building the DownloadInfo object. | 242 * Helper class for building the DownloadInfo object. |
| 233 */ | 243 */ |
| 234 public static class Builder { | 244 public static class Builder { |
| 235 private String mUrl; | 245 private String mUrl; |
| 236 private String mUserAgent; | 246 private String mUserAgent; |
| 237 private String mMimeType; | 247 private String mMimeType; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 250 private long mTimeRemainingInMillis; | 260 private long mTimeRemainingInMillis; |
| 251 private boolean mIsResumable = true; | 261 private boolean mIsResumable = true; |
| 252 private boolean mIsPaused; | 262 private boolean mIsPaused; |
| 253 private boolean mIsOffTheRecord; | 263 private boolean mIsOffTheRecord; |
| 254 private boolean mIsOfflinePage; | 264 private boolean mIsOfflinePage; |
| 255 private int mState = DownloadState.IN_PROGRESS; | 265 private int mState = DownloadState.IN_PROGRESS; |
| 256 private long mLastAccessTime; | 266 private long mLastAccessTime; |
| 257 private ContentId mContentId; | 267 private ContentId mContentId; |
| 258 private boolean mIsOpenable = true; | 268 private boolean mIsOpenable = true; |
| 259 private boolean mIsTransient; | 269 private boolean mIsTransient; |
| 270 private Bitmap mIcon; | |
| 260 | 271 |
| 261 public Builder setUrl(String url) { | 272 public Builder setUrl(String url) { |
| 262 mUrl = url; | 273 mUrl = url; |
| 263 return this; | 274 return this; |
| 264 } | 275 } |
| 265 | 276 |
| 266 public Builder setUserAgent(String userAgent) { | 277 public Builder setUserAgent(String userAgent) { |
| 267 mUserAgent = userAgent; | 278 mUserAgent = userAgent; |
| 268 return this; | 279 return this; |
| 269 } | 280 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 public Builder setIsOpenable(boolean isOpenable) { | 388 public Builder setIsOpenable(boolean isOpenable) { |
| 378 mIsOpenable = isOpenable; | 389 mIsOpenable = isOpenable; |
| 379 return this; | 390 return this; |
| 380 } | 391 } |
| 381 | 392 |
| 382 public Builder setIsTransient(boolean isTransient) { | 393 public Builder setIsTransient(boolean isTransient) { |
| 383 mIsTransient = isTransient; | 394 mIsTransient = isTransient; |
| 384 return this; | 395 return this; |
| 385 } | 396 } |
| 386 | 397 |
| 398 public Builder setIcon(Bitmap icon) { | |
| 399 mIcon = icon; | |
| 400 return this; | |
| 401 } | |
| 402 | |
| 387 public DownloadInfo build() { | 403 public DownloadInfo build() { |
| 388 return new DownloadInfo(this); | 404 return new DownloadInfo(this); |
| 389 } | 405 } |
| 390 | 406 |
| 391 /** | 407 /** |
| 392 * Create a builder from the DownloadInfo object. | 408 * Create a builder from the DownloadInfo object. |
| 393 * @param downloadInfo DownloadInfo object from which builder fields are populated. | 409 * @param downloadInfo DownloadInfo object from which builder fields are populated. |
| 394 * @return A builder initialized with fields from downloadInfo object. | 410 * @return A builder initialized with fields from downloadInfo object. |
| 395 */ | 411 */ |
| 396 public static Builder fromDownloadInfo(final DownloadInfo downloadInfo) { | 412 public static Builder fromDownloadInfo(final DownloadInfo downloadInfo) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 409 .setHasUserGesture(downloadInfo.hasUserGesture()) | 425 .setHasUserGesture(downloadInfo.hasUserGesture()) |
| 410 .setContentDisposition(downloadInfo.getContentDisposition()) | 426 .setContentDisposition(downloadInfo.getContentDisposition()) |
| 411 .setIsGETRequest(downloadInfo.isGETRequest()) | 427 .setIsGETRequest(downloadInfo.isGETRequest()) |
| 412 .setPercentCompleted(downloadInfo.getPercentCompleted()) | 428 .setPercentCompleted(downloadInfo.getPercentCompleted()) |
| 413 .setTimeRemainingInMillis(downloadInfo.getTimeRemainingInMil lis()) | 429 .setTimeRemainingInMillis(downloadInfo.getTimeRemainingInMil lis()) |
| 414 .setIsResumable(downloadInfo.isResumable()) | 430 .setIsResumable(downloadInfo.isResumable()) |
| 415 .setIsPaused(downloadInfo.isPaused()) | 431 .setIsPaused(downloadInfo.isPaused()) |
| 416 .setIsOffTheRecord(downloadInfo.isOffTheRecord()) | 432 .setIsOffTheRecord(downloadInfo.isOffTheRecord()) |
| 417 .setIsOfflinePage(downloadInfo.isOfflinePage()) | 433 .setIsOfflinePage(downloadInfo.isOfflinePage()) |
| 418 .setState(downloadInfo.state()) | 434 .setState(downloadInfo.state()) |
| 419 .setLastAccessTime(downloadInfo.getLastAccessTime()); | 435 .setLastAccessTime(downloadInfo.getLastAccessTime()) |
| 436 .setIcon(downloadInfo.getIcon()); | |
| 420 return builder; | 437 return builder; |
| 421 } | 438 } |
| 422 } | 439 } |
| 423 | 440 |
| 424 @CalledByNative | 441 @CalledByNative |
| 425 private static DownloadInfo createDownloadInfo(String downloadGuid, String f ileName, | 442 private static DownloadInfo createDownloadInfo(String downloadGuid, String f ileName, |
| 426 String filePath, String url, String mimeType, long bytesReceived, bo olean isIncognito, | 443 String filePath, String url, String mimeType, long bytesReceived, bo olean isIncognito, |
| 427 int state, int percentCompleted, boolean isPaused, boolean hasUserGe sture, | 444 int state, int percentCompleted, boolean isPaused, boolean hasUserGe sture, |
| 428 boolean isResumable, String originalUrl, String referrerUrl, long ti meRemainingInMs, | 445 boolean isResumable, String originalUrl, String referrerUrl, long ti meRemainingInMs, |
| 429 long lastAccessTime) { | 446 long lastAccessTime) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 443 .setOriginalUrl(originalUrl) | 460 .setOriginalUrl(originalUrl) |
| 444 .setPercentCompleted(percentCompleted) | 461 .setPercentCompleted(percentCompleted) |
| 445 .setReferrer(referrerUrl) | 462 .setReferrer(referrerUrl) |
| 446 .setState(state) | 463 .setState(state) |
| 447 .setTimeRemainingInMillis(timeRemainingInMs) | 464 .setTimeRemainingInMillis(timeRemainingInMs) |
| 448 .setLastAccessTime(lastAccessTime) | 465 .setLastAccessTime(lastAccessTime) |
| 449 .setUrl(url) | 466 .setUrl(url) |
| 450 .build(); | 467 .build(); |
| 451 } | 468 } |
| 452 } | 469 } |
| OLD | NEW |