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

Unified Diff: base/android/java/src/org/chromium/base/ContentUriUtils.java

Issue 450003002: Pass display names for uploaded content URI files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 4 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: base/android/java/src/org/chromium/base/ContentUriUtils.java
diff --git a/base/android/java/src/org/chromium/base/ContentUriUtils.java b/base/android/java/src/org/chromium/base/ContentUriUtils.java
index 74c74f4aa6d8073ce78b3fa5ca352f521fe8b549..b806b47d4e877a898c04cb683617f01c75c04662 100644
--- a/base/android/java/src/org/chromium/base/ContentUriUtils.java
+++ b/base/android/java/src/org/chromium/base/ContentUriUtils.java
@@ -6,6 +6,7 @@ package org.chromium.base;
import android.content.ContentResolver;
import android.content.Context;
+import android.database.Cursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.util.Log;
@@ -13,7 +14,7 @@ import android.util.Log;
/**
* This class provides methods to access content URI schemes.
*/
-abstract class ContentUriUtils {
+public abstract class ContentUriUtils {
private static final String TAG = "ContentUriUtils";
// Prevent instantiation.
@@ -71,4 +72,35 @@ abstract class ContentUriUtils {
}
return pfd;
}
+
+ /**
+ * Method to resolve the display name of a content URI.
+ *
+ * @param uri the content URI to be resolved.
+ * @param contentResolver the content resolver to query.
+ * @param columnField the column field to query.
+ * @returns the display name of the @code uri if present in the database
+ * or an empty string otherwise.
+ */
+ public static String getDisplayName(
+ Uri uri, ContentResolver contentResolver, String columnField) {
+ if (contentResolver == null || uri == null) return "";
+ Cursor cursor = null;
+ try {
+ cursor = contentResolver.query(uri, null, null, null, null);
+
+ if (cursor != null && cursor.getCount() >= 1) {
+ cursor.moveToFirst();
+ int index = cursor.getColumnIndex(columnField);
+ if (index > -1) return cursor.getString(index);
+ }
+ } catch (NullPointerException e) {
+ // Some android models don't handle the provider call correctly.
+ // see crbug.com/345393
+ return "";
+ } finally {
+ if (cursor != null) cursor.close();
+ }
+ return "";
+ }
}
« no previous file with comments | « android_webview/native/aw_web_contents_delegate.cc ('k') | ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698