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 "media/base/keyboard_event_counter.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 namespace media { | |
10 | |
11 KeyboardEventCounter::KeyboardEventCounter() : total_key_presses_(0) {} | |
12 | |
13 KeyboardEventCounter::~KeyboardEventCounter() {} | |
14 | |
15 void KeyboardEventCounter::Reset() { | |
16 base::AutoLock auto_lock(lock_); | |
17 pressed_keys_.clear(); | |
18 total_key_presses_ = 0; | |
19 } | |
20 | |
21 void KeyboardEventCounter::OnKeyboardEvent( | |
22 ui::EventType event, ui::KeyboardCode key_code) { | |
23 base::AutoLock auto_lock(lock_); | |
24 // Updates the pressed keys and the total count of key presses. | |
25 if (event == ui::ET_KEY_PRESSED) { | |
26 if (pressed_keys_.find(key_code) != pressed_keys_.end()) | |
27 return; | |
28 pressed_keys_.insert(key_code); | |
29 ++total_key_presses_; | |
30 } else { | |
31 DCHECK_EQ(ui::ET_KEY_RELEASED, event); | |
32 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.
| |
33 pressed_keys_.erase(key_code); | |
34 } | |
35 } | |
36 | |
37 size_t KeyboardEventCounter::GetKeyPressCount() const { | |
38 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.
| |
39 return total_key_presses_; | |
40 } | |
41 | |
42 } // namespace media | |
OLD | NEW |