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

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

Issue 2331093002: UMA stats for stylus usage (Closed)
Patch Set: Changed ash/BUILD.gn 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/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/aura/client/aura_constants.h"
14 #include "ui/events/event_constants.h"
15 #include "ui/views/widget/widget.h"
16
17 namespace ash {
18
19 namespace {
20
21 // Form factor of the down event. This enum is used to back an UMA histogram
22 // and should be treated as append-only.
23 enum class DownEventFormFactor {
24 CLAM_SHELL = 0,
Daniel Erat 2016/09/27 19:15:10 nit: "CLAMSHELL" instead of "CLAM_SHELL" (since it
xiaoyinh(OOO Sep 11-29) 2016/09/29 20:37:43 Done.
25 TOUCH_VIEW,
26 FORM_FACTOR_COUNT,
27 };
28
29 // Input type of the down event. This enum is used to back an UMA
30 // histogram and should be treated as append-only.
31 enum class DownEventSource {
32 UNKNOWN = 0,
33 MOUSE,
34 STYLUS,
35 TOUCH,
36 SOURCE_COUNT,
37 };
38
39 void RecordUMA(ui::EventPointerType type, views::Widget* target) {
40 DownEventFormFactor form_factor = DownEventFormFactor::CLAM_SHELL;
41 if (ash::WmShell::Get()
42 ->maximize_mode_controller()
43 ->IsMaximizeModeWindowManagerEnabled()) {
44 form_factor = DownEventFormFactor::TOUCH_VIEW;
45 }
46 UMA_HISTOGRAM_ENUMERATION(
47 "Event.DownEventCount.PerFormFactor",
48 static_cast<base::HistogramBase::Sample>(form_factor),
49 static_cast<base::HistogramBase::Sample>(
50 DownEventFormFactor::FORM_FACTOR_COUNT));
51
52 DownEventSource input_type = DownEventSource::UNKNOWN;
53 switch (type) {
54 case ui::EventPointerType::POINTER_TYPE_UNKNOWN:
55 input_type = DownEventSource::UNKNOWN;
56 break;
57 case ui::EventPointerType::POINTER_TYPE_MOUSE:
58 input_type = DownEventSource::MOUSE;
59 break;
60 case ui::EventPointerType::POINTER_TYPE_PEN:
61 input_type = DownEventSource::STYLUS;
62 break;
63 case ui::EventPointerType::POINTER_TYPE_TOUCH:
64 input_type = DownEventSource::TOUCH;
65 break;
66 case ui::EventPointerType::POINTER_TYPE_ERASER:
67 input_type = DownEventSource::STYLUS;
68 break;
69 }
70
71 UMA_HISTOGRAM_ENUMERATION(
72 "Event.DownEventCount.PerInput",
73 static_cast<base::HistogramBase::Sample>(input_type),
74 static_cast<base::HistogramBase::Sample>(DownEventSource::SOURCE_COUNT));
75
76 if (!target)
77 return;
78
79 aura::Window* window = target->GetNativeWindow();
80 DCHECK(window);
81
82 int window_type = window->GetProperty(aura::client::kAppType);
83 UMA_HISTOGRAM_ENUMERATION(
84 "Event.DownEventCount.PerDestination", window_type,
85 static_cast<base::HistogramBase::Sample>(AppType::APP_COUNT));
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 return;
105 RecordUMA(event.pointer_details().pointer_type, target);
106 }
107
108 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698