| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.app.DownloadManager; | 7 import android.app.DownloadManager; |
| 8 import android.content.ActivityNotFoundException; | 8 import android.content.ActivityNotFoundException; |
| 9 import android.content.BroadcastReceiver; | 9 import android.content.BroadcastReceiver; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 protected boolean addCompletedDownload(DownloadItem downloadItem) { | 599 protected boolean addCompletedDownload(DownloadItem downloadItem) { |
| 600 DownloadInfo downloadInfo = downloadItem.getDownloadInfo(); | 600 DownloadInfo downloadInfo = downloadItem.getDownloadInfo(); |
| 601 String description = downloadInfo.getDescription(); | 601 String description = downloadInfo.getDescription(); |
| 602 if (TextUtils.isEmpty(description)) description = downloadInfo.getFileNa
me(); | 602 if (TextUtils.isEmpty(description)) description = downloadInfo.getFileNa
me(); |
| 603 try { | 603 try { |
| 604 // Exceptions can be thrown when calling this, although it is not | 604 // Exceptions can be thrown when calling this, although it is not |
| 605 // documented on Android SDK page. | 605 // documented on Android SDK page. |
| 606 long downloadId = mDownloadManagerDelegate.addCompletedDownload( | 606 long downloadId = mDownloadManagerDelegate.addCompletedDownload( |
| 607 downloadInfo.getFileName(), description, downloadInfo.getMim
eType(), | 607 downloadInfo.getFileName(), description, downloadInfo.getMim
eType(), |
| 608 downloadInfo.getFilePath(), downloadInfo.getContentLength(), | 608 downloadInfo.getFilePath(), downloadInfo.getContentLength(), |
| 609 downloadInfo.getOriginalUrl(), downloadInfo.getReferer()); | 609 downloadInfo.getOriginalUrl(), downloadInfo.getReferer(), |
| 610 downloadInfo.getDownloadGuid()); |
| 610 downloadItem.setSystemDownloadId(downloadId); | 611 downloadItem.setSystemDownloadId(downloadId); |
| 611 return true; | 612 return true; |
| 612 } catch (RuntimeException e) { | 613 } catch (RuntimeException e) { |
| 613 Log.w(TAG, "Failed to add the download item to DownloadManager: ", e
); | 614 Log.w(TAG, "Failed to add the download item to DownloadManager: ", e
); |
| 614 if (downloadInfo.getFilePath() != null) { | 615 if (downloadInfo.getFilePath() != null) { |
| 615 File file = new File(downloadInfo.getFilePath()); | 616 File file = new File(downloadInfo.getFilePath()); |
| 616 if (!file.delete()) { | 617 if (!file.delete()) { |
| 617 Log.w(TAG, "Failed to remove the unsuccessful download"); | 618 Log.w(TAG, "Failed to remove the unsuccessful download"); |
| 618 } | 619 } |
| 619 } | 620 } |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 public void destroyServiceDelegate() { | 1151 public void destroyServiceDelegate() { |
| 1151 // Lifecycle of DownloadManagerService allows for this call to be ignore
d. | 1152 // Lifecycle of DownloadManagerService allows for this call to be ignore
d. |
| 1152 } | 1153 } |
| 1153 | 1154 |
| 1154 /** | 1155 /** |
| 1155 * Removes a download from the list. | 1156 * Removes a download from the list. |
| 1156 * @param downloadGuid GUID of the download. | 1157 * @param downloadGuid GUID of the download. |
| 1157 * @param isOffTheRecord Whether the download is off the record. | 1158 * @param isOffTheRecord Whether the download is off the record. |
| 1158 */ | 1159 */ |
| 1159 @Override | 1160 @Override |
| 1160 public void removeDownload(String downloadGuid, boolean isOffTheRecord) { | 1161 public void removeDownload(final String downloadGuid, boolean isOffTheRecord
) { |
| 1161 nativeRemoveDownload(getNativeDownloadManagerService(), downloadGuid, is
OffTheRecord); | 1162 nativeRemoveDownload(getNativeDownloadManagerService(), downloadGuid, is
OffTheRecord); |
| 1162 removeDownloadProgress(downloadGuid); | 1163 removeDownloadProgress(downloadGuid); |
| 1164 new AsyncTask<Void, Void, Void>() { |
| 1165 @Override |
| 1166 public Void doInBackground(Void... params) { |
| 1167 mDownloadManagerDelegate.removeCompletedDownload(downloadGuid); |
| 1168 return null; |
| 1169 } |
| 1170 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 1163 } | 1171 } |
| 1164 | 1172 |
| 1165 /** | 1173 /** |
| 1166 * Checks whether the download can be opened by the browser. | 1174 * Checks whether the download can be opened by the browser. |
| 1167 * @param downloadGuid GUID of the download. | 1175 * @param downloadGuid GUID of the download. |
| 1168 * @param isOffTheRecord Whether the download is off the record. | 1176 * @param isOffTheRecord Whether the download is off the record. |
| 1169 * @param mimeType MIME type of the file. | 1177 * @param mimeType MIME type of the file. |
| 1170 * @return Whether the download is openable by the browser. | 1178 * @return Whether the download is openable by the browser. |
| 1171 */ | 1179 */ |
| 1172 @Override | 1180 @Override |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 boolean isNotificationDismissed); | 1683 boolean isNotificationDismissed); |
| 1676 private native void nativePauseDownload(long nativeDownloadManagerService, S
tring downloadGuid, | 1684 private native void nativePauseDownload(long nativeDownloadManagerService, S
tring downloadGuid, |
| 1677 boolean isOffTheRecord); | 1685 boolean isOffTheRecord); |
| 1678 private native void nativeRemoveDownload(long nativeDownloadManagerService,
String downloadGuid, | 1686 private native void nativeRemoveDownload(long nativeDownloadManagerService,
String downloadGuid, |
| 1679 boolean isOffTheRecord); | 1687 boolean isOffTheRecord); |
| 1680 private native void nativeGetAllDownloads( | 1688 private native void nativeGetAllDownloads( |
| 1681 long nativeDownloadManagerService, boolean isOffTheRecord); | 1689 long nativeDownloadManagerService, boolean isOffTheRecord); |
| 1682 private native void nativeCheckForExternallyRemovedDownloads( | 1690 private native void nativeCheckForExternallyRemovedDownloads( |
| 1683 long nativeDownloadManagerService, boolean isOffTheRecord); | 1691 long nativeDownloadManagerService, boolean isOffTheRecord); |
| 1684 } | 1692 } |
| OLD | NEW |