Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: ash/common/metrics/pointer_metrics_recorder.cc

Issue 2331093002: UMA stats for stylus usage (Closed)
Patch Set: nit and rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/common/metrics/pointer_metrics_recorder.h"
6
7 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
8 #include "ash/common/wm_lookup.h"
9 #include "ash/common/wm_shell.h"
10 #include "ash/common/wm_window.h"
11 #include "ash/shared/app_types.h"
12 #include "base/metrics/histogram_macros.h"
13 #include "ui/events/event_constants.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace ash {
17
18 namespace {
19
20 // Form factor of the down event. This enum is used to back an UMA histogram
21 // and new values should be inserted immediately above FORM_FACTOR_COUNT.
22 enum class DownEventFormFactor {
23 CLAMSHELL = 0,
24 TOUCH_VIEW,
25 FORM_FACTOR_COUNT,
26 };
27
28 // Input type of the down event. This enum is used to back an UMA
29 // histogram and new values should be inserted immediately above SOURCE_COUNT.
30 enum class DownEventSource {
31 UNKNOWN = 0,
32 MOUSE,
33 STYLUS,
34 TOUCH,
35 SOURCE_COUNT,
36 };
37
38 int GetDestination(views::Widget* target) {
39 if (!target)
40 return static_cast<int>(AppType::OTHERS);
41
42 WmWindow* window = WmLookup::Get()->GetWindowForWidget(target);
43 DCHECK(window);
44 return window->GetAppType();
45 }
46
47 void RecordUMA(ui::EventPointerType type, views::Widget* target) {
48 DownEventFormFactor form_factor = DownEventFormFactor::CLAMSHELL;
49 if (ash::WmShell::Get()
50 ->maximize_mode_controller()
51 ->IsMaximizeModeWindowManagerEnabled()) {
52 form_factor = DownEventFormFactor::TOUCH_VIEW;
53 }
54 UMA_HISTOGRAM_ENUMERATION(
55 "Event.DownEventCount.PerFormFactor",
56 static_cast<base::HistogramBase::Sample>(form_factor),
57 static_cast<base::HistogramBase::Sample>(
58 DownEventFormFactor::FORM_FACTOR_COUNT));
59
60 DownEventSource input_type = DownEventSource::UNKNOWN;
61 switch (type) {
62 case ui::EventPointerType::POINTER_TYPE_UNKNOWN:
63 input_type = DownEventSource::UNKNOWN;
64 break;
65 case ui::EventPointerType::POINTER_TYPE_MOUSE:
66 input_type = DownEventSource::MOUSE;
67 break;
68 case ui::EventPointerType::POINTER_TYPE_PEN:
69 input_type = DownEventSource::STYLUS;
70 break;
71 case ui::EventPointerType::POINTER_TYPE_TOUCH:
72 input_type = DownEventSource::TOUCH;
73 break;
74 case ui::EventPointerType::POINTER_TYPE_ERASER:
75 input_type = DownEventSource::STYLUS;
76 break;
77 }
78
79 UMA_HISTOGRAM_ENUMERATION(
80 "Event.DownEventCount.PerInput",
81 static_cast<base::HistogramBase::Sample>(input_type),
82 static_cast<base::HistogramBase::Sample>(DownEventSource::SOURCE_COUNT));
83
84 UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerDestination",
85 GetDestination(target), kAppCount);
86 }
87
88 } // namespace
89
90 PointerMetricsRecorder::PointerMetricsRecorder() {
91 ash::WmShell::Get()->AddPointerWatcher(
92 this, views::PointerWatcherEventTypes::BASIC);
93 }
94
95 PointerMetricsRecorder::~PointerMetricsRecorder() {
96 ash::WmShell::Get()->RemovePointerWatcher(this);
97 }
98
99 void PointerMetricsRecorder::OnPointerEventObserved(
100 const ui::PointerEvent& event,
101 const gfx::Point& location_in_screen,
102 views::Widget* target) {
103 if (event.type() == ui::ET_POINTER_DOWN)
104 RecordUMA(event.pointer_details().pointer_type, target);
105 }
106
107 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/metrics/pointer_metrics_recorder.h ('k') | ash/common/metrics/pointer_metrics_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698