diff --git a/ash/clipboard/clipboard_history_controller_impl.cc b/ash/clipboard/clipboard_history_controller_impl.cc index 621bfbf7d4551..4b784518f5105 100644 --- a/ash/clipboard/clipboard_history_controller_impl.cc +++ b/ash/clipboard/clipboard_history_controller_impl.cc @@ -32,6 +32,8 @@ #include "base/location.h" #include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_macros.h" +#include "base/metrics/user_metrics.h" +#include "base/notreached.h" #include "base/one_shot_event.h" #include "base/ranges/algorithm.h" #include "base/strings/utf_string_conversions.h" @@ -103,6 +105,36 @@ void EncodeBitmapToPNG( std::move(barrier_callback).Run(); } +// Emits a user action indicating that the clipboard history item at menu index +// `command_id` was pasted. +void RecordMenuIndexPastedUserAction(int command_id) { + // Per guidance in user_metrics.h, use string literals for action names. + switch (command_id) { + case 1: + base::RecordAction( + base::UserMetricsAction("Ash_ClipboardHistory_PastedItem1")); + break; + case 2: + base::RecordAction( + base::UserMetricsAction("Ash_ClipboardHistory_PastedItem2")); + break; + case 3: + base::RecordAction( + base::UserMetricsAction("Ash_ClipboardHistory_PastedItem3")); + break; + case 4: + base::RecordAction( + base::UserMetricsAction("Ash_ClipboardHistory_PastedItem4")); + break; + case 5: + base::RecordAction( + base::UserMetricsAction("Ash_ClipboardHistory_PastedItem5")); + break; + default: + NOTREACHED(); + } +} + using ClipboardHistoryPasteType = ash::ClipboardHistoryControllerImpl::ClipboardHistoryPasteType; bool IsPlainTextPaste(ClipboardHistoryPasteType paste_type) { @@ -715,9 +747,15 @@ void ClipboardHistoryControllerImpl::ExecuteCommand(int command_id, void ClipboardHistoryControllerImpl::PasteMenuItemData( int command_id, ClipboardHistoryPasteType paste_type) { + // Record the paste item's history list index in a histogram to get a + // distribution of where in the list users paste from. UMA_HISTOGRAM_ENUMERATION( "Ash.ClipboardHistory.ContextMenu.MenuOptionSelected", command_id, ClipboardHistoryUtil::kMaxCommandId); + // Record the paste item's history list index as a user action to analyze + // usage patterns, e.g., how frequently the same index is pasted multiple + // times in a row. + RecordMenuIndexPastedUserAction(command_id); // Deactivate ClipboardImageModelFactory prior to pasting to ensure that any // modifications to the clipboard for HTML rendering purposes are reversed. diff --git a/tools/metrics/actions/actions.xml b/tools/metrics/actions/actions.xml index b653959772188..bfc5e8fd6e5c1 100644 --- a/tools/metrics/actions/actions.xml +++ b/tools/metrics/actions/actions.xml @@ -3715,6 +3715,46 @@ should be able to be added at any place in this file. </description> </action> +<action name="Ash_ClipboardHistory_PastedItem1"> + <owner>ckincaid@chromium.org</owner> + <owner>multipaste@google.com</owner> + <description> + Emitted when a user pastes the first item from their clipboard history. + </description> +</action> + +<action name="Ash_ClipboardHistory_PastedItem2"> + <owner>ckincaid@chromium.org</owner> + <owner>multipaste@google.com</owner> + <description> + Emitted when a user pastes the second item from their clipboard history. + </description> +</action> + +<action name="Ash_ClipboardHistory_PastedItem3"> + <owner>ckincaid@chromium.org</owner> + <owner>multipaste@google.com</owner> + <description> + Emitted when a user pastes the third item from their clipboard history. + </description> +</action> + +<action name="Ash_ClipboardHistory_PastedItem4"> + <owner>ckincaid@chromium.org</owner> + <owner>multipaste@google.com</owner> + <description> + Emitted when a user pastes the fourth item from their clipboard history. + </description> +</action> + +<action name="Ash_ClipboardHistory_PastedItem5"> + <owner>ckincaid@chromium.org</owner> + <owner>multipaste@google.com</owner> + <description> + Emitted when a user pastes the fifth item from their clipboard history. + </description> +</action> + <action name="Ash_Tablet_BackGesture"> <owner>minch@chromium.org</owner> <owner>tclaiborne@chromium.org</owner>