Index: media/base/keyboard_event_counter.cc |
diff --git a/media/base/keyboard_event_counter.cc b/media/base/keyboard_event_counter.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0e78e014b7e7370467b1f709d8af9e893e558fa9 |
--- /dev/null |
+++ b/media/base/keyboard_event_counter.cc |
@@ -0,0 +1,42 @@ |
+// 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/logging.h" |
+ |
+namespace media { |
+ |
+KeyboardEventCounter::KeyboardEventCounter() : total_key_presses_(0) {} |
+ |
+KeyboardEventCounter::~KeyboardEventCounter() {} |
+ |
+void KeyboardEventCounter::Reset() { |
+ base::AutoLock auto_lock(lock_); |
+ pressed_keys_.clear(); |
+ total_key_presses_ = 0; |
+} |
+ |
+void KeyboardEventCounter::OnKeyboardEvent( |
+ ui::EventType event, ui::KeyboardCode key_code) { |
+ base::AutoLock auto_lock(lock_); |
+ // 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); |
+ ++total_key_presses_; |
+ } else { |
+ DCHECK_EQ(ui::ET_KEY_RELEASED, event); |
+ DCHECK(pressed_keys_.find(key_code) != pressed_keys_.end()); |
Mark Mentovai
2013/08/23 20:18:11
There’s no possible way you can guarantee this con
jiayl
2013/08/23 23:47:58
removed.
|
+ pressed_keys_.erase(key_code); |
+ } |
+} |
+ |
+size_t KeyboardEventCounter::GetKeyPressCount() const { |
+ base::AutoLock auto_lock(lock_); |
Mark Mentovai
2013/08/23 20:18:11
This probably isn’t a hot spot, but you could make
jiayl
2013/08/23 23:47:58
But the documentation in atomicops.h says that tho
Mark Mentovai
2013/08/26 15:11:01
jiayl wrote:
jiayl
2013/08/26 17:16:58
But *_AtomicIncrement does not have a version for
Mark Mentovai
2013/08/26 19:07:55
jiayl wrote:
jiayl
2013/08/26 19:30:08
Done.
|
+ return total_key_presses_; |
+} |
+ |
+} // namespace media |