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

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

Issue 2799533002: Use file Uri to launch intent for download on M and below (Closed)
Patch Set: nit Created 3 years, 8 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
« no previous file with comments | « base/android/java/src/org/chromium/base/FileUtils.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
index c4014ba4f7c0c90e3b77a663faed2fab9a29d02e..3c28280f3b5e6b38ebc87ce51edc14c9644b37ec 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
@@ -23,8 +23,8 @@ import android.text.TextUtils;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus;
-import org.chromium.base.ContentUriUtils;
import org.chromium.base.ContextUtils;
+import org.chromium.base.FileUtils;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram;
@@ -459,23 +459,15 @@ public class DownloadUtils {
public static Uri getUriForItem(File file) {
Uri uri = null;
- // #getContentUriFromFile causes a disk read when it calls into FileProvider#getUriForFile.
- // Obtaining a content URI is on the critical path for creating a share intent after the
- // user taps on the share button, so even if we were to run this method on a background
- // thread we would have to wait. As it depends on user-selected items, we cannot
- // know/preload which URIs we need until the user presses share.
+ // FileUtils.getUriForFile() causes a disk read when it calls into
+ // FileProvider#getUriForFile. Obtaining a content URI is on the critical path for creating
+ // a share intent after the user taps on the share button, so even if we were to run this
+ // method on a background thread we would have to wait. As it depends on user-selected
+ // items, we cannot know/preload which URIs we need until the user presses share.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
- try {
- // Try to obtain a content:// URI, which is preferred to a file:// URI so that
- // receiving apps don't attempt to determine the file's mime type (which often fails).
- uri = ContentUriUtils.getContentUriFromFile(file);
- } catch (IllegalArgumentException e) {
- Log.e(TAG, "Could not create content uri: " + e);
- }
+ uri = FileUtils.getUriForFile(file);
StrictMode.setThreadPolicy(oldPolicy);
- if (uri == null) uri = Uri.fromFile(file);
-
return uri;
}
@@ -509,7 +501,11 @@ public class DownloadUtils {
// Check if any apps can open the file.
try {
- Intent viewIntent = createViewIntentForDownloadItem(getUriForItem(file), mimeType);
+ // TODO(qinmin): Move this to an AsyncTask so we don't need to temper with strict mode.
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
+ Uri uri = ApiCompatibilityUtils.getUriForDownloadedFile(file);
+ StrictMode.setThreadPolicy(oldPolicy);
+ Intent viewIntent = createViewIntentForDownloadItem(uri, mimeType);
context.startActivity(viewIntent);
service.updateLastAccessTime(downloadGuid, isOffTheRecord);
return true;
« no previous file with comments | « base/android/java/src/org/chromium/base/FileUtils.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698