| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 org.chromium.base.annotations.CalledByNative; | 7 import org.chromium.base.annotations.CalledByNative; |
| 8 import org.chromium.components.offline_items_collection.ContentId; |
| 8 | 9 |
| 9 /** | 10 /** |
| 10 * A generic class representing a download item. The item can be either download
ed through the | 11 * A generic class representing a download item. The item can be either download
ed through the |
| 11 * Android DownloadManager, or through Chrome's network stack. | 12 * Android DownloadManager, or through Chrome's network stack. |
| 12 * | 13 * |
| 13 * This represents the native DownloadItem at a specific point in time -- the na
tive side | 14 * This represents the native DownloadItem at a specific point in time -- the na
tive side |
| 14 * DownloadManager must be queried for the correct status. | 15 * DownloadManager must be queried for the correct status. |
| 15 */ | 16 */ |
| 16 public class DownloadItem { | 17 public class DownloadItem { |
| 17 public static final int INDETERMINATE_DOWNLOAD_PERCENTAGE = -1; | 18 public static final int INDETERMINATE_DOWNLOAD_PERCENTAGE = -1; |
| 18 static final long INVALID_DOWNLOAD_ID = -1L; | 19 static final long INVALID_DOWNLOAD_ID = -1L; |
| 19 | 20 |
| 21 private final ContentId mContentId = new ContentId(); |
| 20 private boolean mUseAndroidDownloadManager; | 22 private boolean mUseAndroidDownloadManager; |
| 21 private DownloadInfo mDownloadInfo; | 23 private DownloadInfo mDownloadInfo; |
| 22 private long mDownloadId = INVALID_DOWNLOAD_ID; | 24 private long mDownloadId = INVALID_DOWNLOAD_ID; |
| 23 private long mStartTime; | 25 private long mStartTime; |
| 24 private boolean mHasBeenExternallyRemoved; | 26 private boolean mHasBeenExternallyRemoved; |
| 25 | 27 |
| 26 public DownloadItem(boolean useAndroidDownloadManager, DownloadInfo info) { | 28 public DownloadItem(boolean useAndroidDownloadManager, DownloadInfo info) { |
| 27 mUseAndroidDownloadManager = useAndroidDownloadManager; | 29 mUseAndroidDownloadManager = useAndroidDownloadManager; |
| 28 mDownloadInfo = info; | 30 mDownloadInfo = info; |
| 31 if (mDownloadInfo != null) mContentId.namespace = mDownloadInfo.getConte
ntId().namespace; |
| 32 mContentId.id = getId(); |
| 29 } | 33 } |
| 30 | 34 |
| 31 /** | 35 /** |
| 32 * Sets the system download ID retrieved from Android DownloadManager. | 36 * Sets the system download ID retrieved from Android DownloadManager. |
| 33 * | 37 * |
| 34 * @param downloadId ID from the Android DownloadManager. | 38 * @param downloadId ID from the Android DownloadManager. |
| 35 */ | 39 */ |
| 36 public void setSystemDownloadId(long downloadId) { | 40 public void setSystemDownloadId(long downloadId) { |
| 37 mDownloadId = downloadId; | 41 mDownloadId = downloadId; |
| 42 |
| 43 // Update our ContentId in case it changed. |
| 44 mContentId.id = getId(); |
| 38 } | 45 } |
| 39 | 46 |
| 40 /** | 47 /** |
| 41 * @return whether the download item has a valid system download ID. | 48 * @return whether the download item has a valid system download ID. |
| 42 */ | 49 */ |
| 43 public boolean hasSystemDownloadId() { | 50 public boolean hasSystemDownloadId() { |
| 44 return mDownloadId != INVALID_DOWNLOAD_ID; | 51 return mDownloadId != INVALID_DOWNLOAD_ID; |
| 45 } | 52 } |
| 46 | 53 |
| 47 /** | 54 /** |
| 48 * @return System download ID from the Android DownloadManager. | 55 * @return System download ID from the Android DownloadManager. |
| 49 */ | 56 */ |
| 50 public long getSystemDownloadId() { | 57 public long getSystemDownloadId() { |
| 51 return mDownloadId; | 58 return mDownloadId; |
| 52 } | 59 } |
| 53 | 60 |
| 54 /** | 61 /** |
| 62 * @return A {@link ContentId} that represents this downloaded item. The id
will match |
| 63 * {@link #getId()}. |
| 64 */ |
| 65 public ContentId getContentId() { |
| 66 return mContentId; |
| 67 } |
| 68 |
| 69 /** |
| 55 * @return String ID that uniquely identifies the download. | 70 * @return String ID that uniquely identifies the download. |
| 56 */ | 71 */ |
| 57 public String getId() { | 72 public String getId() { |
| 58 if (mUseAndroidDownloadManager) { | 73 if (mUseAndroidDownloadManager) { |
| 59 return String.valueOf(mDownloadId); | 74 return String.valueOf(mDownloadId); |
| 60 } | 75 } |
| 61 return mDownloadInfo.getDownloadGuid(); | 76 return mDownloadInfo.getDownloadGuid(); |
| 62 } | 77 } |
| 63 | 78 |
| 64 /** | 79 /** |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return downloadItem; | 139 return downloadItem; |
| 125 } | 140 } |
| 126 | 141 |
| 127 /** | 142 /** |
| 128 * @return Whether or not the download has an indeterminate percentage. | 143 * @return Whether or not the download has an indeterminate percentage. |
| 129 */ | 144 */ |
| 130 public boolean isIndeterminate() { | 145 public boolean isIndeterminate() { |
| 131 return getDownloadInfo().getPercentCompleted() == INDETERMINATE_DOWNLOAD
_PERCENTAGE; | 146 return getDownloadInfo().getPercentCompleted() == INDETERMINATE_DOWNLOAD
_PERCENTAGE; |
| 132 } | 147 } |
| 133 } | 148 } |
| OLD | NEW |