forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointer_metrics_recorder.cc
109 lines (92 loc) · 3.35 KB
/
pointer_metrics_recorder.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/metrics/pointer_metrics_recorder.h"
#include "ash/public/cpp/app_types.h"
#include "ash/shell.h"
#include "ash/shell_port.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/metrics/histogram_macros.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/events/event_constants.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace {
// Form factor of the down event. This enum is used to back an UMA histogram
// and new values should be inserted immediately above FORM_FACTOR_COUNT.
enum class DownEventFormFactor {
CLAMSHELL = 0,
TABLET_MODE,
FORM_FACTOR_COUNT,
};
// Input type of the down event. This enum is used to back an UMA
// histogram and new values should be inserted immediately above SOURCE_COUNT.
enum class DownEventSource {
UNKNOWN = 0,
MOUSE,
STYLUS,
TOUCH,
SOURCE_COUNT,
};
int GetDestination(views::Widget* target) {
if (!target)
return static_cast<int>(AppType::OTHERS);
aura::Window* window = target->GetNativeWindow();
DCHECK(window);
return window->GetProperty(aura::client::kAppType);
}
void RecordUMA(ui::EventPointerType type, views::Widget* target) {
DownEventFormFactor form_factor = DownEventFormFactor::CLAMSHELL;
if (Shell::Get()
->tablet_mode_controller()
->IsTabletModeWindowManagerEnabled()) {
form_factor = DownEventFormFactor::TABLET_MODE;
}
UMA_HISTOGRAM_ENUMERATION(
"Event.DownEventCount.PerFormFactor",
static_cast<base::HistogramBase::Sample>(form_factor),
static_cast<base::HistogramBase::Sample>(
DownEventFormFactor::FORM_FACTOR_COUNT));
DownEventSource input_type = DownEventSource::UNKNOWN;
switch (type) {
case ui::EventPointerType::POINTER_TYPE_UNKNOWN:
input_type = DownEventSource::UNKNOWN;
break;
case ui::EventPointerType::POINTER_TYPE_MOUSE:
input_type = DownEventSource::MOUSE;
break;
case ui::EventPointerType::POINTER_TYPE_PEN:
input_type = DownEventSource::STYLUS;
break;
case ui::EventPointerType::POINTER_TYPE_TOUCH:
input_type = DownEventSource::TOUCH;
break;
case ui::EventPointerType::POINTER_TYPE_ERASER:
input_type = DownEventSource::STYLUS;
break;
}
UMA_HISTOGRAM_ENUMERATION(
"Event.DownEventCount.PerInput",
static_cast<base::HistogramBase::Sample>(input_type),
static_cast<base::HistogramBase::Sample>(DownEventSource::SOURCE_COUNT));
UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerDestination",
GetDestination(target), kAppCount);
}
} // namespace
PointerMetricsRecorder::PointerMetricsRecorder() {
ShellPort::Get()->AddPointerWatcher(this,
views::PointerWatcherEventTypes::BASIC);
}
PointerMetricsRecorder::~PointerMetricsRecorder() {
ShellPort::Get()->RemovePointerWatcher(this);
}
void PointerMetricsRecorder::OnPointerEventObserved(
const ui::PointerEvent& event,
const gfx::Point& location_in_screen,
gfx::NativeView target) {
if (event.type() == ui::ET_POINTER_DOWN)
RecordUMA(event.pointer_details().pointer_type,
views::Widget::GetTopLevelWidgetForNativeView(target));
}
} // namespace ash