Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadManagerService.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadManagerService.java b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadManagerService.java |
| index 2bf826b235235a682baeea548f84955fc15f6098..388cc0aa03b4029b25ea2f148a76e60efc874a7a 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadManagerService.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadManagerService.java |
| @@ -190,6 +190,7 @@ public class DownloadManagerService extends BroadcastReceiver implements |
| * Creates DownloadManagerService. |
| */ |
| @SuppressFBWarnings("LI_LAZY_INIT") // Findbugs doesn't see this is only UI thread. |
| + @CalledByNative |
| public static DownloadManagerService getDownloadManagerService(final Context context) { |
| ThreadUtils.assertOnUiThread(); |
| assert context == context.getApplicationContext(); |
| @@ -1010,41 +1011,14 @@ public class DownloadManagerService extends BroadcastReceiver implements |
| * @param reason Reason of failure reported by android DownloadManager |
| */ |
| protected void onDownloadFailed(String fileName, int reason) { |
| - String reasonString = mContext.getString( |
| - R.string.download_failed_reason_unknown_error, fileName); |
| - switch (reason) { |
| - case DownloadManager.ERROR_FILE_ALREADY_EXISTS: |
| - reasonString = mContext.getString( |
| - R.string.download_failed_reason_file_already_exists, fileName); |
| - break; |
| - case DownloadManager.ERROR_FILE_ERROR: |
| - reasonString = mContext.getString( |
| - R.string.download_failed_reason_file_system_error, fileName); |
| - break; |
| - case DownloadManager.ERROR_INSUFFICIENT_SPACE: |
| - reasonString = mContext.getString( |
| - R.string.download_failed_reason_insufficient_space, fileName); |
| - break; |
| - case DownloadManager.ERROR_CANNOT_RESUME: |
| - case DownloadManager.ERROR_HTTP_DATA_ERROR: |
| - reasonString = mContext.getString( |
| - R.string.download_failed_reason_network_failures, fileName); |
| - break; |
| - case DownloadManager.ERROR_TOO_MANY_REDIRECTS: |
| - case DownloadManager.ERROR_UNHANDLED_HTTP_CODE: |
| - reasonString = mContext.getString( |
| - R.string.download_failed_reason_server_issues, fileName); |
| - break; |
| - case DownloadManager.ERROR_DEVICE_NOT_FOUND: |
| - reasonString = mContext.getString( |
| - R.string.download_failed_reason_storage_not_found, fileName); |
| - break; |
| - case DownloadManager.ERROR_UNKNOWN: |
| - default: |
| - break; |
| + String failureMessage = getDownloadFailureMessage(fileName, reason); |
| + if (mDownloadSnackbarController.getSnackbarManager() != null) { |
| + mDownloadSnackbarController.onDownloadFailed( |
| + failureMessage, |
| + reason == DownloadManager.ERROR_FILE_ALREADY_EXISTS); |
| + } else { |
| + Toast.makeText(mContext, failureMessage, Toast.LENGTH_SHORT).show(); |
| } |
| - mDownloadSnackbarController.onDownloadFailed( |
| - reasonString, reason == DownloadManager.ERROR_FILE_ALREADY_EXISTS); |
| } |
| /** |
| @@ -1449,6 +1423,54 @@ public class DownloadManagerService extends BroadcastReceiver implements |
| } |
| } |
| + /** |
| + * Called when a download is canceled before download target is determined. |
| + * |
| + * @param fileName Name of the download file. |
| + * @param reason Reason of failure reported by android DownloadManager. |
| + */ |
| + @CalledByNative |
| + private void onDownloadCanceled(String fileName, boolean isExternalStorageMissing) { |
|
Yaron
2016/07/07 19:24:23
If you make this static you can avoid the double r
qinmin
2016/07/07 21:09:47
Done.
|
| + int reason = isExternalStorageMissing ? DownloadManager.ERROR_DEVICE_NOT_FOUND |
|
asanka
2016/07/07 21:12:48
Nit: DEVICE_NOT_FOUND implies something much worse
qinmin
2016/07/07 22:49:37
Yes, the naming is really confusing. According to
|
| + : DownloadManager.ERROR_FILE_ALREADY_EXISTS; |
| + onDownloadFailed(fileName, reason); |
| + } |
| + |
| + /** |
| + * Get the message to display when a download fails. |
| + * |
| + * @param fileName Name of the download file. |
| + * @param reason Reason of failure reported by android DownloadManager. |
| + */ |
| + private String getDownloadFailureMessage(String fileName, int reason) { |
| + switch (reason) { |
| + case DownloadManager.ERROR_FILE_ALREADY_EXISTS: |
| + return mContext.getString( |
| + R.string.download_failed_reason_file_already_exists, fileName); |
| + case DownloadManager.ERROR_FILE_ERROR: |
| + return mContext.getString( |
| + R.string.download_failed_reason_file_system_error, fileName); |
| + case DownloadManager.ERROR_INSUFFICIENT_SPACE: |
| + return mContext.getString( |
| + R.string.download_failed_reason_insufficient_space, fileName); |
| + case DownloadManager.ERROR_CANNOT_RESUME: |
| + case DownloadManager.ERROR_HTTP_DATA_ERROR: |
| + return mContext.getString( |
| + R.string.download_failed_reason_network_failures, fileName); |
| + case DownloadManager.ERROR_TOO_MANY_REDIRECTS: |
| + case DownloadManager.ERROR_UNHANDLED_HTTP_CODE: |
| + return mContext.getString( |
| + R.string.download_failed_reason_server_issues, fileName); |
| + case DownloadManager.ERROR_DEVICE_NOT_FOUND: |
| + return mContext.getString( |
| + R.string.download_failed_reason_storage_not_found, fileName); |
| + case DownloadManager.ERROR_UNKNOWN: |
| + default: |
| + return mContext.getString( |
| + R.string.download_failed_reason_unknown_error, fileName); |
| + } |
| + } |
| + |
| @Override |
| public void onMaxBandwidthChanged(double maxBandwidthMbps) {} |