Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / device_uma.cc
blob487c661412b97001b07c6f88402bce9ac98fb9a0
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
24 // accordingly.
25 UMA_CROS_GESTURE_METRICS_COUNT
28 namespace chromeos {
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() {
48 if (!is_observing_) {
49 base::MessageLoopForUI::current()->AddObserver(this);
50 is_observing_ = true;
54 void DeviceUMA::RemoveMessageLoopObserver() {
55 if (is_observing_) {
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) {
72 XIDeviceEvent* xiev =
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)
76 return;
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;
85 float data1, data2;
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) {
100 case GenericEvent: {
101 if (ui::DeviceDataManager::GetInstance()->IsXIDeviceEvent(event) &&
102 ui::IsTouchpadEvent(event))
103 CheckTouchpadEvent(event);
104 break;
106 default:
107 break;
109 return;
112 } // namespace chromeos