Commit 8d6bf7c7 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Record user action when entering or exiting touch mode

There are currently no cross platform metrics for touch mode. This
adds a pair of actions logged at browser start and when the current
touch mode changes.

Change-Id: I67da675c8c7ce9f11d0d0b53bd13047bf35a2afb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238363
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779573}
parent d543bbc7
......@@ -24531,6 +24531,24 @@ should be able to be added at any place in this file.
</description>
</action>
<action name="TouchMode.EnteredNonTouchMode">
<owner>collinbaker@chromium.org</owner>
<owner>chrome-desktop-ui@google.com</owner>
<description>
The user switched away from primarily using touch input or the browser
started in non-touch mode.
</description>
</action>
<action name="TouchMode.EnteredTouchMode">
<owner>collinbaker@chromium.org</owner>
<owner>chrome-desktop-ui@google.com</owner>
<description>
The user switched to primarily using touch input or the browser started in
touch mode.
</description>
</action>
<action name="Touchpad_Gesture_Overview">
<owner>Please list the metric's owners. Add more owner tags as needed.</owner>
<description>Please enter the description of this user action.</description>
......
......@@ -4,11 +4,13 @@
#include "ui/base/pointer/touch_ui_controller.h"
#include <memory>
#include <string>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop_current.h"
#include "base/metrics/user_metrics.h"
#include "base/no_destructor.h"
#include "base/trace_event/trace_event.h"
#include "ui/base/ui_base_switches.h"
......@@ -22,17 +24,27 @@
namespace ui {
#if defined(OS_WIN)
namespace {
#if defined(OS_WIN)
bool IsTabletMode() {
return base::win::IsWindows10TabletMode(
gfx::SingletonHwnd::GetInstance()->hwnd());
}
} // namespace
#endif // defined(OS_WIN)
void RecordEnteredTouchMode() {
base::RecordAction(base::UserMetricsAction("TouchMode.EnteredTouchMode"));
}
void RecordEnteredNonTouchMode() {
base::RecordAction(base::UserMetricsAction("TouchMode.EnteredNonTouchMode"));
}
} // namespace
TouchUiController::TouchUiScoperForTesting::TouchUiScoperForTesting(
bool enabled,
TouchUiController* controller)
......@@ -72,6 +84,11 @@ TouchUiController::TouchUiController(TouchUiState touch_ui_state)
tablet_mode_ = IsTabletMode();
}
#endif
if (touch_ui())
RecordEnteredTouchMode();
else
RecordEnteredNonTouchMode();
}
TouchUiController::~TouchUiController() = default;
......@@ -79,10 +96,8 @@ TouchUiController::~TouchUiController() = default;
void TouchUiController::OnTabletModeToggled(bool enabled) {
const bool was_touch_ui = touch_ui();
tablet_mode_ = enabled;
if (touch_ui() != was_touch_ui) {
TRACE_EVENT0("ui", "TouchUiController.NotifyListeners");
callback_list_.Notify();
}
if (touch_ui() != was_touch_ui)
TouchUiChanged();
}
std::unique_ptr<TouchUiController::Subscription>
......@@ -94,11 +109,19 @@ TouchUiController::TouchUiState TouchUiController::SetTouchUiState(
TouchUiState touch_ui_state) {
const bool was_touch_ui = touch_ui();
const TouchUiState old_state = std::exchange(touch_ui_state_, touch_ui_state);
if (touch_ui() != was_touch_ui) {
TRACE_EVENT0("ui", "TouchUiController.NotifyListeners");
callback_list_.Notify();
}
if (touch_ui() != was_touch_ui)
TouchUiChanged();
return old_state;
}
void TouchUiController::TouchUiChanged() {
if (touch_ui())
RecordEnteredTouchMode();
else
RecordEnteredNonTouchMode();
TRACE_EVENT0("ui", "TouchUiController.NotifyListeners");
callback_list_.Notify();
}
} // namespace ui
......@@ -5,6 +5,7 @@
#ifndef UI_BASE_POINTER_TOUCH_UI_CONTROLLER_H_
#define UI_BASE_POINTER_TOUCH_UI_CONTROLLER_H_
#include <memory>
#include <string>
#include "base/callback_list.h"
......@@ -64,6 +65,8 @@ class COMPONENT_EXPORT(UI_BASE) TouchUiController {
private:
TouchUiState SetTouchUiState(TouchUiState touch_ui_state);
void TouchUiChanged();
bool tablet_mode_ = false;
TouchUiState touch_ui_state_;
......
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