| Index: chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java
|
| index adc7cc8a2c559e83c3623b2dcb0141a7c4ce1e79..82382d0ceed0357eae524f2146e57aa6ebc3e31d 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java
|
| @@ -21,9 +21,51 @@ import org.chromium.content_public.browser.DownloadState;
|
| import org.chromium.ui.widget.Toast;
|
|
|
| import java.io.File;
|
| +import java.util.Collections;
|
| +import java.util.HashMap;
|
| +import java.util.Locale;
|
| +import java.util.Map;
|
|
|
| /** Wraps different classes that contain information about downloads. */
|
| public abstract class DownloadHistoryItemWrapper extends TimedItem {
|
| + public static final Integer FILE_EXTENSION_OTHER = 0;
|
| + public static final Integer FILE_EXTENSION_APK = 1;
|
| + public static final Integer FILE_EXTENSION_CSV = 2;
|
| + public static final Integer FILE_EXTENSION_DOC = 3;
|
| + public static final Integer FILE_EXTENSION_DOCX = 4;
|
| + public static final Integer FILE_EXTENSION_EXE = 5;
|
| + public static final Integer FILE_EXTENSION_PDF = 6;
|
| + public static final Integer FILE_EXTENSION_PPT = 7;
|
| + public static final Integer FILE_EXTENSION_PPTX = 8;
|
| + public static final Integer FILE_EXTENSION_PSD = 9;
|
| + public static final Integer FILE_EXTENSION_RTF = 10;
|
| + public static final Integer FILE_EXTENSION_TXT = 11;
|
| + public static final Integer FILE_EXTENSION_XLS = 12;
|
| + public static final Integer FILE_EXTENSION_XLSX = 13;
|
| + public static final Integer FILE_EXTENSION_ZIP = 14;
|
| + public static final Integer FILE_EXTENSION_BOUNDARY = 15;
|
| +
|
| + private static final Map<String, Integer> EXTENSIONS_MAP;
|
| + static {
|
| + Map<String, Integer> extensions = new HashMap<>();
|
| + extensions.put("apk", FILE_EXTENSION_APK);
|
| + extensions.put("csv", FILE_EXTENSION_CSV);
|
| + extensions.put("doc", FILE_EXTENSION_DOC);
|
| + extensions.put("docx", FILE_EXTENSION_DOCX);
|
| + extensions.put("exe", FILE_EXTENSION_EXE);
|
| + extensions.put("pdf", FILE_EXTENSION_PDF);
|
| + extensions.put("ppt", FILE_EXTENSION_PPT);
|
| + extensions.put("pptx", FILE_EXTENSION_PPTX);
|
| + extensions.put("psd", FILE_EXTENSION_PSD);
|
| + extensions.put("rtf", FILE_EXTENSION_RTF);
|
| + extensions.put("txt", FILE_EXTENSION_TXT);
|
| + extensions.put("xls", FILE_EXTENSION_XLS);
|
| + extensions.put("xlsx", FILE_EXTENSION_XLSX);
|
| + extensions.put("zip", FILE_EXTENSION_ZIP);
|
| +
|
| + EXTENSIONS_MAP = Collections.unmodifiableMap(extensions);
|
| + }
|
| +
|
| protected final BackendProvider mBackendProvider;
|
| protected final ComponentName mComponentName;
|
| protected File mFile;
|
| @@ -97,6 +139,9 @@ public abstract class DownloadHistoryItemWrapper extends TimedItem {
|
| /** @return The mime type or null if the item doesn't have one. */
|
| public abstract String getMimeType();
|
|
|
| + /** @return The file extension type. See list at the top of the file. */
|
| + public abstract int getFileExtensionType();
|
| +
|
| /** @return How much of the download has completed, or -1 if there is no progress. */
|
| abstract int getDownloadProgress();
|
|
|
| @@ -141,16 +186,29 @@ public abstract class DownloadHistoryItemWrapper extends TimedItem {
|
| protected void recordOpenSuccess() {
|
| RecordHistogram.recordEnumeratedHistogram("Android.DownloadManager.Item.OpenSucceeded",
|
| getFilterType(), DownloadFilter.FILTER_BOUNDARY);
|
| +
|
| + if (getFilterType() == DownloadFilter.FILTER_OTHER) {
|
| + RecordHistogram.recordEnumeratedHistogram(
|
| + "Android.DownloadManager.OtherExtensions.OpenSucceeded",
|
| + getFileExtensionType(), FILE_EXTENSION_BOUNDARY);
|
| + }
|
| }
|
|
|
| protected void recordOpenFailure() {
|
| RecordHistogram.recordEnumeratedHistogram("Android.DownloadManager.Item.OpenFailed",
|
| getFilterType(), DownloadFilter.FILTER_BOUNDARY);
|
| +
|
| + if (getFilterType() == DownloadFilter.FILTER_OTHER) {
|
| + RecordHistogram.recordEnumeratedHistogram(
|
| + "Android.DownloadManager.OtherExtensions.OpenFailed",
|
| + getFileExtensionType(), FILE_EXTENSION_BOUNDARY);
|
| + }
|
| }
|
|
|
| /** Wraps a {@link DownloadItem}. */
|
| public static class DownloadItemWrapper extends DownloadHistoryItemWrapper {
|
| private DownloadItem mItem;
|
| + private Integer mFileExtensionType;
|
|
|
| DownloadItemWrapper(DownloadItem item, BackendProvider provider, ComponentName component) {
|
| super(provider, component);
|
| @@ -219,6 +277,28 @@ public abstract class DownloadHistoryItemWrapper extends TimedItem {
|
| }
|
|
|
| @Override
|
| + public int getFileExtensionType() {
|
| + if (mFileExtensionType == null) {
|
| + int extensionIndex = getFilePath().lastIndexOf(".");
|
| + if (extensionIndex == -1 || extensionIndex == getFilePath().length() - 1) {
|
| + mFileExtensionType = FILE_EXTENSION_OTHER;
|
| + return mFileExtensionType;
|
| + }
|
| +
|
| + String extension = getFilePath().substring(extensionIndex + 1);
|
| + if (!TextUtils.isEmpty(extension) && EXTENSIONS_MAP.containsKey(
|
| + extension.toLowerCase(Locale.getDefault()))) {
|
| + mFileExtensionType = EXTENSIONS_MAP.get(
|
| + extension.toLowerCase(Locale.getDefault()));
|
| + } else {
|
| + mFileExtensionType = FILE_EXTENSION_OTHER;
|
| + }
|
| + }
|
| +
|
| + return mFileExtensionType;
|
| + }
|
| +
|
| + @Override
|
| public int getDownloadProgress() {
|
| return mItem.getDownloadInfo().getPercentCompleted();
|
| }
|
| @@ -409,6 +489,11 @@ public abstract class DownloadHistoryItemWrapper extends TimedItem {
|
| }
|
|
|
| @Override
|
| + public int getFileExtensionType() {
|
| + return FILE_EXTENSION_OTHER;
|
| + }
|
| +
|
| + @Override
|
| public int getDownloadProgress() {
|
| return -1;
|
| }
|
|
|