summaryrefslogtreecommitdiff
path: root/media/base/keyboard_event_counter.cc
diff options
context:
space:
mode:
authorTorne (Richard Coles) <torne@google.com>2013-08-30 15:14:49 +0100
committerTorne (Richard Coles) <torne@google.com>2013-08-30 15:14:49 +0100
commit424c4d7b64af9d0d8fd9624f381f469654d5e3d2 (patch)
treeaf8b16dc2ba7fc8c8bb1c9fa18b907c847f3883d /media/base/keyboard_event_counter.cc
parentc70ef2906f891fe7d218980660e4cda465717916 (diff)
downloadchromium_org-424c4d7b64af9d0d8fd9624f381f469654d5e3d2.tar.gz
Merge from Chromium at DEPS revision r220549
This commit was generated by merge_to_master.py. Change-Id: I8fcb82db764ec1eb0294280936c177bd9ba8a9e9
Diffstat (limited to 'media/base/keyboard_event_counter.cc')
-rw-r--r--media/base/keyboard_event_counter.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/media/base/keyboard_event_counter.cc b/media/base/keyboard_event_counter.cc
new file mode 100644
index 0000000000..a4ae1097f8
--- /dev/null
+++ b/media/base/keyboard_event_counter.cc
@@ -0,0 +1,41 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/base/keyboard_event_counter.h"
+
+#include "base/atomicops.h"
+#include "base/logging.h"
+
+namespace media {
+
+KeyboardEventCounter::KeyboardEventCounter() : total_key_presses_(0) {}
+
+KeyboardEventCounter::~KeyboardEventCounter() {}
+
+void KeyboardEventCounter::Reset() {
+ pressed_keys_.clear();
+ total_key_presses_ = 0;
+}
+
+void KeyboardEventCounter::OnKeyboardEvent(ui::EventType event,
+ ui::KeyboardCode key_code) {
+ // Updates the pressed keys and the total count of key presses.
+ if (event == ui::ET_KEY_PRESSED) {
+ if (pressed_keys_.find(key_code) != pressed_keys_.end())
+ return;
+ pressed_keys_.insert(key_code);
+ base::subtle::NoBarrier_AtomicIncrement(
+ reinterpret_cast<base::subtle::AtomicWord*>(&total_key_presses_), 1);
+ } else {
+ DCHECK_EQ(ui::ET_KEY_RELEASED, event);
+ pressed_keys_.erase(key_code);
+ }
+}
+
+size_t KeyboardEventCounter::GetKeyPressCount() const {
+ return base::subtle::NoBarrier_Load(
+ reinterpret_cast<const base::subtle::AtomicWord*>(&total_key_presses_));
+}
+
+} // namespace media