Commit 68aa3780 authored by Andrew Xu's avatar Andrew Xu Committed by Chromium LUCI CQ

[Multipaste] Metrics to count multipaste menu showing times

This CL records how many times the multipaste menu shows through the
accelerator, render view's context menu and textfield's context menu
respectively.

Bug: 1164439
Change-Id: I7a9f8ab1efd21de951d353ae596536d44bb4ee01
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2618540Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842853}
parent 9d3793ec
......@@ -21,6 +21,7 @@
#include "base/base64.h"
#include "base/files/file_path.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
......@@ -219,16 +220,17 @@ void ClipboardHistoryControllerImpl::ShowMenuByAccelerator() {
ExecuteSelectedMenuItem(ui::EF_COMMAND_DOWN);
return;
}
ShowMenu(CalculateAnchorRect(), ui::MENU_SOURCE_KEYBOARD);
ShowMenu(CalculateAnchorRect(), ui::MENU_SOURCE_KEYBOARD,
ShowSource::kAccelerator);
}
gfx::Rect ClipboardHistoryControllerImpl::GetMenuBoundsInScreenForTest() const {
return context_menu_->GetMenuBoundsInScreenForTest();
}
void ClipboardHistoryControllerImpl::ShowMenu(
const gfx::Rect& anchor_rect,
ui::MenuSourceType source_type) {
void ClipboardHistoryControllerImpl::ShowMenu(const gfx::Rect& anchor_rect,
ui::MenuSourceType source_type,
ShowSource show_source) {
if (IsMenuShowing() || !CanShowMenu())
return;
......@@ -248,6 +250,9 @@ void ClipboardHistoryControllerImpl::ShowMenu(
DCHECK(IsMenuShowing());
accelerator_target_->OnMenuShown();
base::UmaHistogramEnumeration("Ash.ClipboardHistory.ContextMenu.ShowMenu",
show_source);
// The first menu item should be selected as default after the clipboard
// history menu shows. Note that the menu item is selected asynchronously
// to avoid the interference from synthesized mouse events.
......
......@@ -87,7 +87,8 @@ class ASH_EXPORT ClipboardHistoryControllerImpl
// ClipboardHistoryController:
bool CanShowMenu() const override;
void ShowMenu(const gfx::Rect& anchor_rect,
ui::MenuSourceType source_type) override;
ui::MenuSourceType source_type,
ShowSource show_source) override;
std::unique_ptr<ScopedClipboardHistoryPause> CreateScopedPause() override;
base::Value GetHistoryValues(
const std::set<std::string>& item_id_filter) const override;
......
......@@ -28,6 +28,26 @@ class ScopedClipboardHistoryPause;
// clipboard history menu.
class ASH_PUBLIC_EXPORT ClipboardHistoryController {
public:
// The different ways the multipaste menu can be shown. These values are
// written to logs. New enum values can be added, but existing enums must
// never be renumbered, deleted, or reused.
enum class ShowSource {
// Shown by the accelerator.
kAccelerator = 0,
// Shown by a render view's context menu.
kRenderViewContextMenu = 1,
// Shown by a textfield's context menu.
kTextfieldContextMenu = 2,
// Shown by the virtual keyboard.
kVirtualKeyboard = 3,
// Insert new types above this line.
kMaxValue = kVirtualKeyboard
};
class Observer : public base::CheckedObserver {
public:
// Called when the clipboard history menu is shown.
......@@ -54,7 +74,8 @@ class ASH_PUBLIC_EXPORT ClipboardHistoryController {
// Shows the clipboard history menu triggered by `source_type` at the
// specified position.
virtual void ShowMenu(const gfx::Rect& anchor_rect,
ui::MenuSourceType source_type) = 0;
ui::MenuSourceType source_type,
ShowSource show_source) = 0;
// Creates a ScopedClipboardHistoryPause, which pauses ClipboardHistory for
// its lifetime.
......
......@@ -65,8 +65,9 @@ void ViewsTextServicesContextMenuImpl::ExecuteCommand(int command_id,
else
source_type = ui::MENU_SOURCE_KEYBOARD;
clipboard_history_controller->ShowMenu(client()->GetCaretBounds(),
source_type);
clipboard_history_controller->ShowMenu(
client()->GetCaretBounds(), source_type,
ClipboardHistoryController::ShowSource::kTextfieldContextMenu);
return;
}
......
......@@ -2501,7 +2501,8 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
source_type = ui::MENU_SOURCE_KEYBOARD;
ash::ClipboardHistoryController::Get()->ShowMenu(
gfx::Rect(anchor_point_in_screen, gfx::Size()), source_type);
gfx::Rect(anchor_point_in_screen, gfx::Size()), source_type,
ash::ClipboardHistoryController::ShowSource::kRenderViewContextMenu);
#else
NOTREACHED();
#endif
......
......@@ -275,9 +275,14 @@ IN_PROC_BROWSER_TEST_F(ClipboardHistoryWithMultiProfileBrowserTest,
SetClipboardText("B");
SetClipboardText("C");
base::HistogramTester histogram_tester;
ShowContextMenuViaAccelerator(/*wait_for_selection=*/true);
ASSERT_TRUE(GetClipboardHistoryController()->IsMenuShowing());
ASSERT_EQ(3, GetContextMenu()->GetMenuItemsCount());
histogram_tester.ExpectUniqueSample(
"Ash.ClipboardHistory.ContextMenu.ShowMenu",
ash::ClipboardHistoryController::ShowSource::kAccelerator, 1);
// The history menu's first item should be selected as default after the menu
// shows. Meanwhile, its delete button should not show.
......
......@@ -11255,6 +11255,13 @@ histogram as enum -->
<int value="3" label="Web Smart Paste"/>
</enum>
<enum name="ClipboardHistoryTriggerType">
<int value="0" label="Accelerator"/>
<int value="1" label="Render View Context Menu"/>
<int value="2" label="Textfield Context Menu"/>
<int value="3" label="Virtual Keyboard"/>
</enum>
<enum name="ClockdriftLevel">
<int value="0" label="None"/>
<int value="1" label="Probable"/>
......@@ -407,6 +407,16 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary>
</histogram>
<histogram name="Ash.ClipboardHistory.ContextMenu.ShowMenu"
enum="ClipboardHistoryTriggerType" expires_after="2021-09-01">
<owner>andrewxu@chromium.org</owner>
<owner>multipaste@google.com</owner>
<summary>
It records how many times users trigger the clipboard history menu through
different ways respecitvely. Recorded when the clipboard history menu shows.
</summary>
</histogram>
<histogram name="Ash.ClipboardHistory.ContextMenu.ShowPlaceholderString"
enum="ClipboardHistoryPlaceholderStringType" expires_after="2021-09-01">
<owner>newcomer@chromium.org</owner>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment