summaryrefslogtreecommitdiffstats
path: root/content/public/android/java/src/org/chromium/content/browser/DownloadController.java
diff options
context:
space:
mode:
authorqinmin <qinmin@chromium.org>2016-03-23 18:50:19 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-24 01:51:42 +0000
commit52d7cf606132f69666cc445621db0a0f19e99ecb (patch)
tree93ec5e954caccaff4d54f9d650a3878765a88e85 /content/public/android/java/src/org/chromium/content/browser/DownloadController.java
parentdb7410a13770f6be066a20a78ae2a6320afdc026 (diff)
downloadchromium_src-52d7cf606132f69666cc445621db0a0f19e99ecb.zip
chromium_src-52d7cf606132f69666cc445621db0a0f19e99ecb.tar.gz
chromium_src-52d7cf606132f69666cc445621db0a0f19e99ecb.tar.bz2
Allow interrupted download to auto resume
For android DownloadManager, it can automatically resume download if connectivity changes. However, with chrome network stack, this won't happen automatically. A download initiated on mobile network won't switch to wifi automatically after mobile network is unreachable, e.g. This change solves the problem by automatically resuming a download after network status changes. The resumption logic can be found internally in a PRD: For download initiated in mobile, it can be resumed under wifi or mobile. For download initiated in wifi, it can only be resumed under wifi. Whenenver a download is interrupted, we add it as a resumption candidate if it can be resumed. When network status changes, we check if any candidates can be resumed and start them automatically. BUG=460603 Committed: https://crrev.com/f2af782b65e6d24c839f0044bee018cf60fabc5c Cr-Commit-Position: refs/heads/master@{#382883} Review URL: https://codereview.chromium.org/1800103005 Cr-Commit-Position: refs/heads/master@{#383010}
Diffstat (limited to 'content/public/android/java/src/org/chromium/content/browser/DownloadController.java')
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/DownloadController.java150
1 files changed, 86 insertions, 64 deletions
diff --git a/content/public/android/java/src/org/chromium/content/browser/DownloadController.java b/content/public/android/java/src/org/chromium/content/browser/DownloadController.java
index e1a3d3d..63a5eb7 100644
--- a/content/public/android/java/src/org/chromium/content/browser/DownloadController.java
+++ b/content/public/android/java/src/org/chromium/content/browser/DownloadController.java
@@ -42,6 +42,13 @@ public class DownloadController {
* @param downloadId Id of the download.
*/
void onDownloadCancelled(final DownloadInfo downloadInfo);
+
+ /**
+ * Notify the host application that a download is interrupted.
+ * @param downloadInfo Information about the completed download.
+ * @param isAutoResumable Download can be auto resumed when network becomes available.
+ */
+ void onDownloadInterrupted(final DownloadInfo downloadInfo, boolean isAutoResumable);
}
private static DownloadNotificationService sDownloadNotificationService;
@@ -76,21 +83,20 @@ public class DownloadController {
String filename, long contentLength) {
ContentViewDownloadDelegate downloadDelegate = downloadDelegateFromView(view);
- if (downloadDelegate != null) {
- DownloadInfo downloadInfo = new DownloadInfo.Builder()
- .setUrl(url)
- .setUserAgent(userAgent)
- .setContentDisposition(contentDisposition)
- .setMimeType(mimeType)
- .setCookie(cookie)
- .setReferer(referer)
- .setHasUserGesture(hasUserGesture)
- .setFileName(filename)
- .setContentLength(contentLength)
- .setIsGETRequest(true)
- .build();
- downloadDelegate.requestHttpGetDownload(downloadInfo);
- }
+ if (downloadDelegate == null) return;
+ DownloadInfo downloadInfo = new DownloadInfo.Builder()
+ .setUrl(url)
+ .setUserAgent(userAgent)
+ .setContentDisposition(contentDisposition)
+ .setMimeType(mimeType)
+ .setCookie(cookie)
+ .setReferer(referer)
+ .setHasUserGesture(hasUserGesture)
+ .setFileName(filename)
+ .setContentLength(contentLength)
+ .setIsGETRequest(true)
+ .build();
+ downloadDelegate.requestHttpGetDownload(downloadInfo);
}
/**
@@ -114,26 +120,46 @@ public class DownloadController {
* download. This can be either a POST download or a GET download with authentication.
*/
@CalledByNative
- private void onDownloadCompleted(String url, String mimeType,
- String filename, String path, long contentLength, boolean successful, int downloadId,
- String originalUrl, String refererUrl, boolean hasUserGesture) {
- if (sDownloadNotificationService != null) {
- DownloadInfo downloadInfo = new DownloadInfo.Builder()
- .setUrl(url)
- .setMimeType(mimeType)
- .setFileName(filename)
- .setFilePath(path)
- .setContentLength(contentLength)
- .setIsSuccessful(successful)
- .setDescription(filename)
- .setDownloadId(downloadId)
- .setHasDownloadId(true)
- .setOriginalUrl(originalUrl)
- .setReferer(refererUrl)
- .setHasUserGesture(hasUserGesture)
- .build();
- sDownloadNotificationService.onDownloadCompleted(downloadInfo);
- }
+ private void onDownloadCompleted(String url, String mimeType, String filename, String path,
+ long contentLength, int downloadId, String originalUrl, String refererUrl,
+ boolean hasUserGesture) {
+ if (sDownloadNotificationService == null) return;
+ DownloadInfo downloadInfo = new DownloadInfo.Builder()
+ .setUrl(url)
+ .setMimeType(mimeType)
+ .setFileName(filename)
+ .setFilePath(path)
+ .setContentLength(contentLength)
+ .setDescription(filename)
+ .setDownloadId(downloadId)
+ .setHasDownloadId(true)
+ .setOriginalUrl(originalUrl)
+ .setReferer(refererUrl)
+ .setHasUserGesture(hasUserGesture)
+ .build();
+ sDownloadNotificationService.onDownloadCompleted(downloadInfo);
+ }
+
+ /**
+ * Notifies the download delegate that a download completed and passes along info about the
+ * download. This can be either a POST download or a GET download with authentication.
+ */
+ @CalledByNative
+ private void onDownloadInterrupted(String url, String mimeType, String filename, String path,
+ long contentLength, int downloadId, boolean isResumable, boolean isAutoResumable) {
+ if (sDownloadNotificationService == null) return;
+ DownloadInfo downloadInfo = new DownloadInfo.Builder()
+ .setUrl(url)
+ .setMimeType(mimeType)
+ .setFileName(filename)
+ .setFilePath(path)
+ .setContentLength(contentLength)
+ .setDescription(filename)
+ .setDownloadId(downloadId)
+ .setHasDownloadId(true)
+ .setIsResumable(isResumable)
+ .build();
+ sDownloadNotificationService.onDownloadInterrupted(downloadInfo, isAutoResumable);
}
/**
@@ -142,13 +168,12 @@ public class DownloadController {
*/
@CalledByNative
private void onDownloadCancelled(int downloadId) {
- if (sDownloadNotificationService != null) {
- DownloadInfo downloadInfo = new DownloadInfo.Builder()
- .setDownloadId(downloadId)
- .setHasDownloadId(true)
- .build();
- sDownloadNotificationService.onDownloadCancelled(downloadInfo);
- }
+ if (sDownloadNotificationService == null) return;
+ DownloadInfo downloadInfo = new DownloadInfo.Builder()
+ .setDownloadId(downloadId)
+ .setHasDownloadId(true)
+ .build();
+ sDownloadNotificationService.onDownloadCancelled(downloadInfo);
}
/**
@@ -157,28 +182,25 @@ public class DownloadController {
*/
@CalledByNative
private void onDownloadUpdated(String url, String mimeType, String filename,
- String path, long contentLength, boolean successful, int downloadId,
- int percentCompleted, long timeRemainingInMs, boolean hasUserGesture, boolean isPaused,
- boolean isResumable) {
- if (sDownloadNotificationService != null) {
- DownloadInfo downloadInfo = new DownloadInfo.Builder()
- .setUrl(url)
- .setMimeType(mimeType)
- .setFileName(filename)
- .setFilePath(path)
- .setContentLength(contentLength)
- .setIsSuccessful(successful)
- .setDescription(filename)
- .setDownloadId(downloadId)
- .setHasDownloadId(true)
- .setPercentCompleted(percentCompleted)
- .setTimeRemainingInMillis(timeRemainingInMs)
- .setHasUserGesture(hasUserGesture)
- .setIsPaused(isPaused)
- .setIsResumable(isResumable)
- .build();
- sDownloadNotificationService.onDownloadUpdated(downloadInfo);
- }
+ String path, long contentLength, int downloadId, int percentCompleted,
+ long timeRemainingInMs, boolean hasUserGesture, boolean isPaused, boolean isResumable) {
+ if (sDownloadNotificationService == null) return;
+ DownloadInfo downloadInfo = new DownloadInfo.Builder()
+ .setUrl(url)
+ .setMimeType(mimeType)
+ .setFileName(filename)
+ .setFilePath(path)
+ .setContentLength(contentLength)
+ .setDescription(filename)
+ .setDownloadId(downloadId)
+ .setHasDownloadId(true)
+ .setPercentCompleted(percentCompleted)
+ .setTimeRemainingInMillis(timeRemainingInMs)
+ .setHasUserGesture(hasUserGesture)
+ .setIsPaused(isPaused)
+ .setIsResumable(isResumable)
+ .build();
+ sDownloadNotificationService.onDownloadUpdated(downloadInfo);
}
/**