1 // Copyright 2013 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.
5 #include "chrome/browser/chromeos/device_uma.h"
7 #include <X11/extensions/XInput.h>
8 #include <X11/extensions/XInput2.h>
10 #include "base/logging.h"
11 #include "base/memory/singleton.h"
12 #include "base/metrics/histogram.h"
13 #include "ui/events/event_constants.h"
14 #include "ui/events/event_utils.h"
15 #include "ui/events/x/device_data_manager.h"
17 // Enum type for CrOS gesture lib UMA
18 enum UMACrosGestureMetricsType
{
19 // To give an estimated number of all interested events.
20 UMA_CROS_GESTURE_METRICS_ALL_EVENTS
,
21 UMA_CROS_GESTURE_METRICS_NOISY_GROUND
,
22 // NOTE: Add states only immediately above this line. Make sure to
23 // update the enum list in tools/metrics/histograms/histograms.xml
25 UMA_CROS_GESTURE_METRICS_COUNT
30 DeviceUMA
* DeviceUMA::GetInstance() {
31 return Singleton
<DeviceUMA
>::get();
34 DeviceUMA::DeviceUMA()
35 :is_observing_(false) {
36 AddMessageLoopObserver();
39 DeviceUMA::~DeviceUMA() {
40 RemoveMessageLoopObserver();
43 void DeviceUMA::Stop() {
44 RemoveMessageLoopObserver();
47 void DeviceUMA::AddMessageLoopObserver() {
49 base::MessageLoopForUI::current()->AddObserver(this);
54 void DeviceUMA::RemoveMessageLoopObserver() {
56 base::MessageLoopForUI::current()->RemoveObserver(this);
57 is_observing_
= false;
61 base::EventStatus
DeviceUMA::WillProcessEvent(
62 const base::NativeEvent
& event
) {
63 CheckIncomingEvent(event
);
64 return base::EVENT_CONTINUE
;
67 void DeviceUMA::DidProcessEvent(
68 const base::NativeEvent
& event
) {
71 void DeviceUMA::CheckTouchpadEvent(const base::NativeEvent
& native_event
) {
73 static_cast<XIDeviceEvent
*>(native_event
->xcookie
.data
);
74 // We take only the slave event since there is no need to count twice.
75 if (xiev
->deviceid
!= xiev
->sourceid
)
77 UMA_HISTOGRAM_ENUMERATION("Touchpad.Metrics",
78 UMA_CROS_GESTURE_METRICS_ALL_EVENTS
,
79 UMA_CROS_GESTURE_METRICS_COUNT
);
81 // Check for the CrOS touchpad metrics gesture
82 ui::DeviceDataManager
*manager
= ui::DeviceDataManager::GetInstance();
83 if (manager
->IsCMTMetricsEvent(native_event
)) {
84 ui::GestureMetricsType type
;
86 manager
->GetMetricsData(native_event
, &type
, &data1
, &data2
);
88 // We currently track only the noisy ground issue. Please see
89 // http://crbug.com/237683.
90 if (type
== ui::kGestureMetricsTypeNoisyGround
) {
91 UMA_HISTOGRAM_ENUMERATION("Touchpad.Metrics",
92 UMA_CROS_GESTURE_METRICS_NOISY_GROUND
,
93 UMA_CROS_GESTURE_METRICS_COUNT
);
98 void DeviceUMA::CheckIncomingEvent(const base::NativeEvent
& event
) {
99 switch (event
->type
) {
101 if (ui::DeviceDataManager::GetInstance()->IsXIDeviceEvent(event
) &&
102 ui::IsTouchpadEvent(event
))
103 CheckTouchpadEvent(event
);
112 } // namespace chromeos