Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java |
| index bbaa18147bd0dd63d468592b319a165af6b18ec6..ea41ee784000bb7414bf7f9cb51953227e3f21fe 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java |
| @@ -10,6 +10,7 @@ import android.text.TextUtils; |
| import android.view.ContextMenu; |
| import android.view.MenuInflater; |
| import android.view.MenuItem; |
| +import android.webkit.MimeTypeMap; |
| import org.chromium.base.metrics.RecordHistogram; |
| import org.chromium.chrome.R; |
| @@ -83,6 +84,15 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| static final int ACTION_SHARE_IMAGE = 19; |
| static final int NUM_ACTIONS = 20; |
| + // Note: these values must match the ContextMenuSaveLinkType enum in histograms.xml. |
|
Ilya Sherman
2015/11/14 00:22:48
nit: Please also document that this enum-like-thin
qinmin
2015/11/17 00:38:56
Done.
|
| + static final int TYPE_TEXT = 0; |
| + static final int TYPE_IMAGE = 1; |
| + static final int TYPE_AUDIO = 2; |
| + static final int TYPE_VIDEO = 3; |
| + static final int TYPE_PDF = 4; |
| + static final int TYPE_UNKNWON = 5; |
| + static final int NUM_TYPES = 6; |
| + |
| /** |
| * Records a histogram entry when the user selects an item from a context menu. |
| * @param params The ContextMenuParams describing the current context menu. |
| @@ -104,6 +114,33 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| } |
| RecordHistogram.recordEnumeratedHistogram(histogramName, action, NUM_ACTIONS); |
| } |
| + |
| + /** |
| + * Records the content types when user downloads the file by long pressing the |
| + * save link context menu option. |
| + */ |
| + static void recordSaveLinkTypes(String url) { |
| + String extension = MimeTypeMap.getFileExtensionFromUrl(url); |
| + int mimeType = TYPE_UNKNWON; |
| + if (extension != null) { |
| + String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); |
| + if (type != null) { |
| + if (type.startsWith("text")) { |
| + mimeType = TYPE_TEXT; |
| + } else if (type.startsWith("image")) { |
| + mimeType = TYPE_IMAGE; |
| + } else if (type.startsWith("audio")) { |
| + mimeType = TYPE_AUDIO; |
| + } else if (type.startsWith("video")) { |
| + mimeType = TYPE_VIDEO; |
| + } else if (type.equals("application/pdf")) { |
| + mimeType = TYPE_PDF; |
| + } |
| + } |
| + } |
| + RecordHistogram.recordEnumeratedHistogram( |
| + "ContextMenu.SaveLinkType", mimeType, NUM_TYPES); |
| + } |
| } |
| /** |
| @@ -280,7 +317,9 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| } |
| } else if (itemId == R.id.contextmenu_save_link_as) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_SAVE_LINK); |
| - if (mDelegate.startDownload(params.getUnfilteredLinkUrl(), true)) { |
| + String url = params.getUnfilteredLinkUrl(); |
| + if (mDelegate.startDownload(url, true)) { |
| + ContextMenuUma.recordSaveLinkTypes(url); |
| helper.startContextMenuDownload(true, false); |
| } |
| } else if (itemId == R.id.contextmenu_search_by_image) { |