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

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

Issue 2772853002: Fix an issue that OMA download is not intercepted on Android (Closed)
Patch Set: Created 3 years, 9 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 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()) {

Powered by Google App Engine
This is Rietveld 408576698