This source file includes following definitions.
- GetInstance
- Stop
- AddMessageLoopObserver
- RemoveMessageLoopObserver
- WillProcessEvent
- DidProcessEvent
- CheckTouchpadEvent
- CheckIncomingEvent
#include "chrome/browser/chromeos/device_uma.h"
#include <X11/extensions/XInput.h>
#include <X11/extensions/XInput2.h>
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/metrics/histogram.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h"
#include "ui/events/x/device_data_manager.h"
enum UMACrosGestureMetricsType{
UMA_CROS_GESTURE_METRICS_ALL_EVENTS,
UMA_CROS_GESTURE_METRICS_NOISY_GROUND,
UMA_CROS_GESTURE_METRICS_COUNT
};
namespace chromeos {
DeviceUMA* DeviceUMA::GetInstance() {
return Singleton<DeviceUMA>::get();
}
DeviceUMA::DeviceUMA()
:is_observing_(false) {
AddMessageLoopObserver();
}
DeviceUMA::~DeviceUMA() {
RemoveMessageLoopObserver();
}
void DeviceUMA::Stop() {
RemoveMessageLoopObserver();
}
void DeviceUMA::AddMessageLoopObserver() {
if (!is_observing_) {
base::MessageLoopForUI::current()->AddObserver(this);
is_observing_ = true;
}
}
void DeviceUMA::RemoveMessageLoopObserver() {
if (is_observing_) {
base::MessageLoopForUI::current()->RemoveObserver(this);
is_observing_ = false;
}
}
base::EventStatus DeviceUMA::WillProcessEvent(
const base::NativeEvent& event) {
CheckIncomingEvent(event);
return base::EVENT_CONTINUE;
}
void DeviceUMA::DidProcessEvent(
const base::NativeEvent& event) {
}
void DeviceUMA::CheckTouchpadEvent(const base::NativeEvent& native_event) {
XIDeviceEvent* xiev =
static_cast<XIDeviceEvent*>(native_event->xcookie.data);
if (xiev->deviceid != xiev->sourceid)
return;
UMA_HISTOGRAM_ENUMERATION("Touchpad.Metrics",
UMA_CROS_GESTURE_METRICS_ALL_EVENTS,
UMA_CROS_GESTURE_METRICS_COUNT);
ui::DeviceDataManager *manager = ui::DeviceDataManager::GetInstance();
if (manager->IsCMTMetricsEvent(native_event)) {
ui::GestureMetricsType type;
float data1, data2;
manager->GetMetricsData(native_event, &type, &data1, &data2);
if (type == ui::kGestureMetricsTypeNoisyGround) {
UMA_HISTOGRAM_ENUMERATION("Touchpad.Metrics",
UMA_CROS_GESTURE_METRICS_NOISY_GROUND,
UMA_CROS_GESTURE_METRICS_COUNT);
}
}
}
void DeviceUMA::CheckIncomingEvent(const base::NativeEvent& event) {
switch (event->type) {
case GenericEvent: {
if (ui::DeviceDataManager::GetInstance()->IsXIDeviceEvent(event) &&
ui::IsTouchpadEvent(event))
CheckTouchpadEvent(event);
break;
}
default:
break;
}
return;
}
}