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 08c96918c7abbdff85cd9074d95c71de09247081..cb53085c7bd48400973d9aa68c5fc4eb11816654 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 |
@@ -19,9 +19,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; |
private Long mStableId; |
@@ -68,6 +110,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. */ |
public abstract int getDownloadProgress(); |
@@ -98,17 +143,30 @@ 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 final DownloadItem mItem; |
private File mFile; |
+ private Integer mFileExtensionType; |
DownloadItemWrapper(DownloadItem item, BackendProvider provider, ComponentName component) { |
super(provider, component); |
@@ -171,6 +229,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(); |
} |
@@ -284,6 +364,11 @@ public abstract class DownloadHistoryItemWrapper extends TimedItem { |
} |
@Override |
+ public int getFileExtensionType() { |
+ return FILE_EXTENSION_OTHER; |
+ } |
+ |
+ @Override |
public int getDownloadProgress() { |
return -1; |
} |