Added three histograms to track the following TCP connection latency
[chromium-blink-merge.git] / ash / keyboard_uma_event_filter.cc
blob6b7ae6bee3851bb23085dd6e977f56a9e1218853
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 "ash/keyboard_uma_event_filter.h"
7 #include "base/metrics/histogram.h"
8 #include "ui/events/event.h"
10 namespace {
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;
19 namespace ash {
20 namespace internal {
22 KeyboardUMAEventFilter::KeyboardUMAEventFilter() {}
24 KeyboardUMAEventFilter::~KeyboardUMAEventFilter() {}
26 void KeyboardUMAEventFilter::OnKeyEvent(ui::KeyEvent* event) {
27 // This is a rough approximation, so assume that each key release is the
28 // result of a typed key.
29 if (event->type() != ui::ET_KEY_RELEASED)
30 return;
32 // Reset the timer on non-character keystrokes.
33 if (!isprint(event->GetCharacter())) {
34 last_keystroke_time_ = base::TimeDelta();
35 return;
38 if (last_keystroke_time_.ToInternalValue() == 0) {
39 last_keystroke_time_ = event->time_stamp();
40 return;
43 base::TimeDelta delta = event->time_stamp() - last_keystroke_time_;
44 if (delta < base::TimeDelta::FromSeconds(kKeystrokeThresholdInSeconds))
45 UMA_HISTOGRAM_TIMES("Keyboard.KeystrokeDeltas", delta);
47 last_keystroke_time_ = event->time_stamp();
50 } // namespace internal
51 } // namespace ash