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

Unified Diff: ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java

Issue 2663523002: Record whether a file picker specialized for media content can be used (Closed)
Patch Set: Created 3 years, 11 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 | « ui/android/BUILD.gn ('k') | ui/android/junit/src/org/chromium/ui/base/SelectFileDialogTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
diff --git a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
index 00ed8b5c9459574db037258b64ef83d4d19c3762..3415ae5b6cd781260eee8dd4cc18bb895578c6cb 100644
--- a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
+++ b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
@@ -27,6 +27,7 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex;
+import org.chromium.base.metrics.RecordHistogram;
import org.chromium.ui.R;
import org.chromium.ui.UiUtils;
@@ -54,6 +55,21 @@ public class SelectFileDialog
private static final String ANY_TYPES = "*/*";
/**
+ * The SELECT_FILE_DIALOG_SCOPE_* enumerations are used to measure the sort of content that
+ * developers are requesting to be shown in the select file dialog. Values must be kept in sync
+ * with their definition in //tools/metrics/histograms/histograms.xml, and both the numbering
+ * and meaning of the values must remain constant as they're recorded by UMA.
+ *
+ * Values are package visible because they're tested in the SelectFileDialogTest junit test.
+ */
+ static final int SELECT_FILE_DIALOG_SCOPE_GENERIC = 0;
+ static final int SELECT_FILE_DIALOG_SCOPE_IMAGES = 1;
+ static final int SELECT_FILE_DIALOG_SCOPE_VIDEOS = 2;
+ static final int SELECT_FILE_DIALOG_SCOPE_IMAGES_AND_VIDEOS = 3;
+ static final int SELECT_FILE_DIALOG_SCOPE_COUNT =
+ SELECT_FILE_DIALOG_SCOPE_IMAGES_AND_VIDEOS + 1;
+
+ /**
* If set, overrides the WindowAndroid passed in {@link selectFile()}.
*/
private static WindowAndroid sOverrideWindowAndroid;
@@ -82,6 +98,14 @@ public class SelectFileDialog
}
/**
+ * Overrides the list of accepted file types for testing purposes.
+ */
+ @VisibleForTesting
+ public void setFileTypesForTests(List<String> fileTypes) {
+ mFileTypes = fileTypes;
+ }
+
+ /**
* Creates and starts an intent based on the passed fileTypes and capture value.
* @param fileTypes MIME types requested (i.e. "image/*")
* @param capture The capture value as described in http://www.w3.org/TR/html-media-capture/
@@ -174,6 +198,9 @@ public class SelectFileDialog
getContentIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
+ RecordHistogram.recordEnumeratedHistogram("Android.SelectFileDialogScope",
+ determineSelectFileDialogScope(), SELECT_FILE_DIALOG_SCOPE_COUNT);
+
ArrayList<Intent> extraIntents = new ArrayList<Intent>();
if (!noSpecificType()) {
// Create a chooser based on the accept type that was specified in the webpage. Note
@@ -355,6 +382,28 @@ public class SelectFileDialog
nativeOnFileNotSelected(mNativeSelectFileDialog);
}
+ // Determines the scope of the requested select file dialog for use in a UMA histogram. Right
+ // now we want to distinguish between generic, photo and visual media pickers.
+ @VisibleForTesting
+ int determineSelectFileDialogScope() {
+ boolean isGeneric = noSpecificType();
+
+ if (!isGeneric && shouldShowImageTypes()) {
+ return SELECT_FILE_DIALOG_SCOPE_IMAGES;
+ } else if (!isGeneric && shouldShowVideoTypes()) {
+ return SELECT_FILE_DIALOG_SCOPE_VIDEOS;
+ } else if (mFileTypes.size() == 2) {
+ // The shouldShow{Image,Video}Types() methods cannot be used here since they test for
+ // a generic dialog, which any request with more than one file type is considered as.
+ if ((mFileTypes.contains(ALL_IMAGE_TYPES) || acceptSpecificType(IMAGE_TYPE))
+ && (mFileTypes.contains(ALL_VIDEO_TYPES) || acceptSpecificType(VIDEO_TYPE))) {
+ return SELECT_FILE_DIALOG_SCOPE_IMAGES_AND_VIDEOS;
+ }
+ }
+
+ return SELECT_FILE_DIALOG_SCOPE_GENERIC;
+ }
+
private boolean noSpecificType() {
// We use a single Intent to decide the type of the file chooser we display to the user,
// which means we can only give it a single type. If there are multiple accept types
@@ -453,8 +502,9 @@ public class SelectFileDialog
}
}
+ @VisibleForTesting
@CalledByNative
- private static SelectFileDialog create(long nativeSelectFileDialog) {
+ static SelectFileDialog create(long nativeSelectFileDialog) {
return new SelectFileDialog(nativeSelectFileDialog);
}
« no previous file with comments | « ui/android/BUILD.gn ('k') | ui/android/junit/src/org/chromium/ui/base/SelectFileDialogTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698