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

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

Issue 2736573002: chromeos: Move files in //ash/common to //ash, part 2 (Closed)
Patch Set: Created 3 years, 9 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_shell.h"
9 #include "ash/common/wm_window.h"
10 #include "ash/shared/app_types.h"
11 #include "base/metrics/histogram_macros.h"
12 #include "ui/events/event_constants.h"
13 #include "ui/views/widget/widget.h"
14
15 namespace ash {
16
17 namespace {
18
19 // Form factor of the down event. This enum is used to back an UMA histogram
20 // and new values should be inserted immediately above FORM_FACTOR_COUNT.
21 enum class DownEventFormFactor {
22 CLAMSHELL = 0,
23 TOUCH_VIEW,
24 FORM_FACTOR_COUNT,
25 };
26
27 // Input type of the down event. This enum is used to back an UMA
28 // histogram and new values should be inserted immediately above SOURCE_COUNT.
29 enum class DownEventSource {
30 UNKNOWN = 0,
31 MOUSE,
32 STYLUS,
33 TOUCH,
34 SOURCE_COUNT,
35 };
36
37 int GetDestination(views::Widget* target) {
38 if (!target)
39 return static_cast<int>(AppType::OTHERS);
40
41 WmWindow* window = WmWindow::Get(target->GetNativeWindow());
42 DCHECK(window);
43 return window->GetAppType();
44 }
45
46 void RecordUMA(ui::EventPointerType type, views::Widget* target) {
47 DownEventFormFactor form_factor = DownEventFormFactor::CLAMSHELL;
48 if (ash::WmShell::Get()
49 ->maximize_mode_controller()
50 ->IsMaximizeModeWindowManagerEnabled()) {
51 form_factor = DownEventFormFactor::TOUCH_VIEW;
52 }
53 UMA_HISTOGRAM_ENUMERATION(
54 "Event.DownEventCount.PerFormFactor",
55 static_cast<base::HistogramBase::Sample>(form_factor),
56 static_cast<base::HistogramBase::Sample>(
57 DownEventFormFactor::FORM_FACTOR_COUNT));
58
59 DownEventSource input_type = DownEventSource::UNKNOWN;
60 switch (type) {
61 case ui::EventPointerType::POINTER_TYPE_UNKNOWN:
62 input_type = DownEventSource::UNKNOWN;
63 break;
64 case ui::EventPointerType::POINTER_TYPE_MOUSE:
65 input_type = DownEventSource::MOUSE;
66 break;
67 case ui::EventPointerType::POINTER_TYPE_PEN:
68 input_type = DownEventSource::STYLUS;
69 break;
70 case ui::EventPointerType::POINTER_TYPE_TOUCH:
71 input_type = DownEventSource::TOUCH;
72 break;
73 case ui::EventPointerType::POINTER_TYPE_ERASER:
74 input_type = DownEventSource::STYLUS;
75 break;
76 }
77
78 UMA_HISTOGRAM_ENUMERATION(
79 "Event.DownEventCount.PerInput",
80 static_cast<base::HistogramBase::Sample>(input_type),
81 static_cast<base::HistogramBase::Sample>(DownEventSource::SOURCE_COUNT));
82
83 UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerDestination",
84 GetDestination(target), kAppCount);
85 }
86
87 } // namespace
88
89 PointerMetricsRecorder::PointerMetricsRecorder() {
90 ash::WmShell::Get()->AddPointerWatcher(
91 this, views::PointerWatcherEventTypes::BASIC);
92 }
93
94 PointerMetricsRecorder::~PointerMetricsRecorder() {
95 ash::WmShell::Get()->RemovePointerWatcher(this);
96 }
97
98 void PointerMetricsRecorder::OnPointerEventObserved(
99 const ui::PointerEvent& event,
100 const gfx::Point& location_in_screen,
101 views::Widget* target) {
102 if (event.type() == ui::ET_POINTER_DOWN)
103 RecordUMA(event.pointer_details().pointer_type, target);
104 }
105
106 } // 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