| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ash/keyboard_uma_event_filter.h" | |
| 6 | |
| 7 #include "base/metrics/histogram.h" | |
| 8 #include "ui/events/event.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 // This threshold is used to drop keystrokes that are more than some time apart. | |
| 13 // These keystrokes are dropped to avoid recording outliers, as well as pauses | |
| 14 // between actual segments of typing. | |
| 15 const int kKeystrokeThresholdInSeconds = 5; | |
| 16 } | |
| 17 | |
| 18 namespace ash { | |
| 19 | |
| 20 KeyboardUMAEventFilter::KeyboardUMAEventFilter() {} | |
| 21 | |
| 22 KeyboardUMAEventFilter::~KeyboardUMAEventFilter() {} | |
| 23 | |
| 24 void KeyboardUMAEventFilter::OnKeyEvent(ui::KeyEvent* event) { | |
| 25 // This is a rough approximation, so assume that each key release is the | |
| 26 // result of a typed key. | |
| 27 if (event->type() != ui::ET_KEY_RELEASED) | |
| 28 return; | |
| 29 | |
| 30 // Reset the timer on non-character keystrokes. | |
| 31 if (!isprint(event->GetCharacter())) { | |
| 32 last_keystroke_time_ = base::TimeTicks(); | |
| 33 return; | |
| 34 } | |
| 35 | |
| 36 if (last_keystroke_time_.ToInternalValue() == 0) { | |
| 37 last_keystroke_time_ = event->time_stamp(); | |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 base::TimeDelta delta = event->time_stamp() - last_keystroke_time_; | |
| 42 if (delta < base::TimeDelta::FromSeconds(kKeystrokeThresholdInSeconds)) | |
| 43 UMA_HISTOGRAM_TIMES("Keyboard.KeystrokeDeltas", delta); | |
| 44 | |
| 45 last_keystroke_time_ = event->time_stamp(); | |
| 46 } | |
| 47 | |
| 48 } // namespace ash | |
| OLD | NEW |