Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4296)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadManagerService.java

Issue 2117343007: Show download error message if sdcard is not available (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean up document dir if no sdcard is found Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ac7d3413bf3a5129a4ecc47d2be8bf3384a4f933 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
@@ -1010,41 +1010,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 +1422,56 @@ 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 static void onDownloadItemCanceled(String fileName, boolean isExternalStorageMissing) {
+ DownloadManagerService service = getDownloadManagerService(
+ ContextUtils.getApplicationContext());
+ int reason = isExternalStorageMissing ? DownloadManager.ERROR_DEVICE_NOT_FOUND
+ : DownloadManager.ERROR_FILE_ALREADY_EXISTS;
+ service.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) {}

Powered by Google App Engine
This is Rietveld 408576698