| 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 7f31dbf249289257e275c50429a70be6af242913..0e148501584a2c5a952aea941241d19ae8644d16 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
|
| @@ -137,6 +137,15 @@ public class DownloadManagerService extends BroadcastReceiver implements
|
| // Flag to track if we need to post a task to update download notifications.
|
| private boolean mIsUIUpdateScheduled;
|
| private int mAutoResumptionLimit = -1;
|
| + private DownloadManagerRequestInterceptor mDownloadManagerRequestInterceptor;
|
| +
|
| + /**
|
| + * Interface to intercept download request to Android DownloadManager. This is implemented by
|
| + * tests so that we don't need to actually enqueue a download into the Android DownloadManager.
|
| + */
|
| + static interface DownloadManagerRequestInterceptor {
|
| + void interceptDownloadRequest(DownloadItem item, boolean notifyComplete);
|
| + }
|
|
|
| /**
|
| * Class representing progress of a download.
|
| @@ -243,10 +252,13 @@ public class DownloadManagerService extends BroadcastReceiver implements
|
| }
|
|
|
| @VisibleForTesting
|
| - protected DownloadManagerService(Context context,
|
| - DownloadNotifier downloadNotifier,
|
| - Handler handler,
|
| - long updateDelayInMillis) {
|
| + void setDownloadManagerRequestInterceptor(DownloadManagerRequestInterceptor interceptor) {
|
| + mDownloadManagerRequestInterceptor = interceptor;
|
| + }
|
| +
|
| + @VisibleForTesting
|
| + protected DownloadManagerService(Context context, DownloadNotifier downloadNotifier,
|
| + Handler handler, long updateDelayInMillis) {
|
| mContext = context;
|
| mSharedPrefs = ContextUtils.getAppSharedPreferences();
|
| // Clean up unused shared prefs. TODO(qinmin): remove this after M61.
|
| @@ -855,6 +867,10 @@ public class DownloadManagerService extends BroadcastReceiver implements
|
| */
|
| public void enqueueDownloadManagerRequest(
|
| final DownloadItem item, boolean notifyCompleted) {
|
| + if (mDownloadManagerRequestInterceptor != null) {
|
| + mDownloadManagerRequestInterceptor.interceptDownloadRequest(item, notifyCompleted);
|
| + return;
|
| + }
|
| EnqueueDownloadRequestTask task = new EnqueueDownloadRequestTask(item);
|
| task.execute(notifyCompleted);
|
| }
|
| @@ -891,10 +907,12 @@ public class DownloadManagerService extends BroadcastReceiver implements
|
| request.setMimeType(info.getMimeType());
|
| try {
|
| if (notifyCompleted) {
|
| - // Set downloaded file destination to /sdcard/Download or, should it be
|
| - // set to one of several Environment.DIRECTORY* dirs depending on mimetype?
|
| - request.setDestinationInExternalPublicDir(
|
| - Environment.DIRECTORY_DOWNLOADS, info.getFileName());
|
| + if (info.getFileName() != null) {
|
| + // Set downloaded file destination to /sdcard/Download or, should it be
|
| + // set to one of several Environment.DIRECTORY* dirs depending on mimetype?
|
| + request.setDestinationInExternalPublicDir(
|
| + Environment.DIRECTORY_DOWNLOADS, info.getFileName());
|
| + }
|
| } else {
|
| File dir = new File(mContext.getExternalFilesDir(null), DOWNLOAD_DIRECTORY);
|
| if (dir.mkdir() || dir.isDirectory()) {
|
|
|