From a60a2e9061334a5726ae30166ef004209719f4f9 Mon Sep 17 00:00:00 2001 From: newt Date: Thu, 13 Aug 2015 15:01:31 -0700 Subject: [PATCH] [Android] Add UMA histograms to measure context menu actions. This adds four related histograms to measure how users interact with context menus. The histograms are ContextMenu.Link, ContextMenu.Image, ContextMenu.ImageLink, and ContextMenu.Video, and the values are the various actions that can be taken on each context menu, e.g. "Open in new tab" or "Save image". For example, if a user long presses an image and selects "Copy image", we'll record the "Copy image" event in the ContextMenu.Image histogram. ContextMenu.ImageLink is used when the user long presses an image which is also a link. This case is treated specially because its context menu is currently so long that it needs extra love and investigation. BUG=483685 Review URL: https://codereview.chromium.org/1267213002 Cr-Commit-Position: refs/heads/master@{#343283} --- .../contextmenu/ChromeContextMenuPopulator.java | 58 ++++++++++++++++++++++ tools/metrics/histograms/histograms.xml | 33 ++++++++++++ 2 files changed, 91 insertions(+) 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 6d7e2d7b8da5..092759f3e241 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 org.chromium.base.metrics.RecordHistogram; import org.chromium.chrome.R; import org.chromium.chrome.browser.UrlUtilities; import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; @@ -24,6 +25,48 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { private MenuInflater mMenuInflater; private static final String BLANK_URL = "about:blank"; + static class ContextMenuUma { + // Note: these values must match the ContextMenuOption enum in histograms.xml. + static final int ACTION_OPEN_IN_NEW_TAB = 0; + static final int ACTION_OPEN_IN_INCOGNITO_TAB = 1; + static final int ACTION_COPY_LINK_ADDRESS = 2; + static final int ACTION_COPY_EMAIL_ADDRESS = 3; + static final int ACTION_COPY_LINK_TEXT = 4; + static final int ACTION_SAVE_LINK = 5; + static final int ACTION_SAVE_IMAGE = 6; + static final int ACTION_OPEN_IMAGE = 7; + static final int ACTION_OPEN_IMAGE_IN_NEW_TAB = 8; + static final int ACTION_COPY_IMAGE = 9; + static final int ACTION_COPY_IMAGE_URL = 10; + static final int ACTION_SEARCH_BY_IMAGE = 11; + static final int ACTION_LOAD_IMAGES = 12; + static final int ACTION_LOAD_ORIGINAL_IMAGE = 13; + static final int ACTION_SAVE_VIDEO = 14; + static final int NUM_ACTIONS = 15; + + /** + * Records a histogram entry when the user selects an item from a context menu. + * @param params The ContextMenuParams describing the current context menu. + * @param action The action that the user selected (e.g. ACTION_SAVE_IMAGE). + */ + static void record(ContextMenuParams params, int action) { + assert action >= 0; + assert action < NUM_ACTIONS; + String histogramName; + if (params.isVideo()) { + histogramName = "ContextMenu.SelectedOption.Video"; + } else if (params.isImage()) { + histogramName = params.isAnchor() + ? "ContextMenu.SelectedOption.ImageLink" + : "ContextMenu.SelectedOption.Image"; + } else { + assert params.isAnchor(); + histogramName = "ContextMenu.SelectedOption.Link"; + } + RecordHistogram.recordEnumeratedHistogram(histogramName, action, NUM_ACTIONS); + } + } + /** * Builds a {@link ChromeContextMenuPopulator}. * @param delegate The {@link ChromeContextMenuItemDelegate} that will be notified with actions @@ -136,19 +179,25 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { @Override public boolean onItemSelected(ContextMenuHelper helper, ContextMenuParams params, int itemId) { if (itemId == R.id.contextmenu_open_in_new_tab) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IN_NEW_TAB); mDelegate.onOpenInNewTab(params.getLinkUrl(), params.getReferrer()); } else if (itemId == R.id.contextmenu_open_in_incognito_tab) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IN_INCOGNITO_TAB); mDelegate.onOpenInNewIncognitoTab(params.getLinkUrl()); } else if (itemId == R.id.contextmenu_open_image) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IMAGE); mDelegate.onOpenImageUrl(params.getSrcUrl(), params.getReferrer()); } else if (itemId == R.id.contextmenu_open_image_in_new_tab || itemId == R.id.contextmenu_open_original_image_in_new_tab) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IMAGE_IN_NEW_TAB); mDelegate.onOpenImageInNewTab(params.getSrcUrl(), params.getReferrer()); } else if (itemId == R.id.contextmenu_load_images) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_LOAD_IMAGES); DataReductionProxyUma.dataReductionProxyLoFiUIAction( DataReductionProxyUma.ACTION_LOAD_IMAGES_CONTEXT_MENU_CLICKED); mDelegate.onReloadIgnoringCache(); } else if (itemId == R.id.contextmenu_load_original_image) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_LOAD_ORIGINAL_IMAGE); DataReductionProxyUma.dataReductionProxyLoFiUIAction( DataReductionProxyUma.ACTION_LOAD_IMAGE_CONTEXT_MENU_CLICKED); if (!DataReductionProxySettings.getInstance().wasLoFiLoadImageRequestedBefore()) { @@ -158,32 +207,41 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { } mDelegate.onLoadOriginalImage(); } else if (itemId == R.id.contextmenu_copy_link_address_text) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_COPY_LINK_ADDRESS); mDelegate.onSaveToClipboard(params.getUnfilteredLinkUrl(), ChromeContextMenuItemDelegate.CLIPBOARD_TYPE_LINK_URL); } else if (itemId == R.id.contextmenu_copy_email_address) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_COPY_EMAIL_ADDRESS); mDelegate.onSaveToClipboard(MailTo.parse(params.getLinkUrl()).getTo(), ChromeContextMenuItemDelegate.CLIPBOARD_TYPE_LINK_URL); } else if (itemId == R.id.contextmenu_copy_link_text) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_COPY_LINK_TEXT); mDelegate.onSaveToClipboard( params.getLinkText(), ChromeContextMenuItemDelegate.CLIPBOARD_TYPE_LINK_TEXT); } else if (itemId == R.id.contextmenu_save_image) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_SAVE_IMAGE); if (mDelegate.startDownload(params.getSrcUrl(), false)) { helper.startContextMenuDownload( false, mDelegate.isDataReductionProxyEnabledForURL(params.getSrcUrl())); } } else if (itemId == R.id.contextmenu_save_video) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_SAVE_VIDEO); if (mDelegate.startDownload(params.getSrcUrl(), false)) { helper.startContextMenuDownload(false, false); } } else if (itemId == R.id.contextmenu_save_link_as) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_SAVE_LINK); if (mDelegate.startDownload(params.getUnfilteredLinkUrl(), true)) { helper.startContextMenuDownload(true, false); } } else if (itemId == R.id.contextmenu_search_by_image) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_SEARCH_BY_IMAGE); mDelegate.onSearchByImageInNewTab(); } else if (itemId == R.id.contextmenu_copy_image) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_COPY_IMAGE); mDelegate.onSaveImageToClipboard(params.getSrcUrl()); } else if (itemId == R.id.contextmenu_copy_image_url) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_COPY_IMAGE_URL); mDelegate.onSaveToClipboard( params.getSrcUrl(), ChromeContextMenuItemDelegate.CLIPBOARD_TYPE_IMAGE_URL); } else { diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 0b80bfcdb816..c1db8839a4b4 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -4297,6 +4297,11 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. + + newt@chromium.org + The option that the user selected from a context menu. + + Please list the metric's owners. Add more owner tags as needed. @@ -53611,6 +53616,25 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. + + The item selected from a context menu + + + + + + + + + + + + + + + + + Reason why a cookie was removed from the cookie store @@ -72694,6 +72718,15 @@ To add a new entry, add it with any value and run test to compute valid value. + + + + + + + + -- 2.11.4.GIT