1 // Copyright 2015 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 "ui/events/ozone/evdev/touch_noise/touch_noise_finder.h"
7 #include "base/metrics/histogram_macros.h"
8 #include "base/stl_util.h"
9 #include "ui/events/event_utils.h"
10 #include "ui/events/ozone/evdev/touch_noise/far_apart_taps_touch_noise_filter.h"
11 #include "ui/events/ozone/evdev/touch_noise/horizontally_aligned_touch_noise_filter.h"
12 #include "ui/events/ozone/evdev/touch_noise/single_position_touch_noise_filter.h"
13 #include "ui/events/ozone/evdev/touch_noise/touch_noise_filter.h"
17 TouchNoiseFinder::TouchNoiseFinder() : last_noise_time_(ui::EventTimeForNow()) {
18 filters_
.push_back(new FarApartTapsTouchNoiseFilter
);
19 filters_
.push_back(new HorizontallyAlignedTouchNoiseFilter
);
20 filters_
.push_back(new SinglePositionTouchNoiseFilter
);
23 TouchNoiseFinder::~TouchNoiseFinder() {
24 STLDeleteElements(&filters_
);
27 void TouchNoiseFinder::HandleTouches(
28 const std::vector
<InProgressTouchEvdev
>& touches
,
29 base::TimeDelta time
) {
30 for (const InProgressTouchEvdev
& touch
: touches
) {
31 if (!touch
.was_touching
)
32 slots_with_noise_
.set(touch
.slot
, false);
35 bool had_noise
= slots_with_noise_
.any();
37 for (TouchNoiseFilter
* filter
: filters_
)
38 filter
->Filter(touches
, time
, &slots_with_noise_
);
40 RecordUMA(had_noise
, time
);
43 bool TouchNoiseFinder::SlotHasNoise(size_t slot
) const {
44 return slots_with_noise_
.test(slot
);
47 void TouchNoiseFinder::RecordUMA(bool had_noise
, base::TimeDelta time
) {
48 if (slots_with_noise_
.any()) {
50 UMA_HISTOGRAM_LONG_TIMES(
51 "Ozone.TouchNoiseFilter.TimeSinceLastNoiseOccurrence",
52 time
- last_noise_time_
);
55 last_noise_time_
= time
;