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/atomicops.h" | |
8 #include "base/logging.h" | |
9 | |
10 namespace media { | |
11 | |
12 KeyboardEventCounter::KeyboardEventCounter() : total_key_presses_(0) {} | |
13 | |
14 KeyboardEventCounter::~KeyboardEventCounter() {} | |
15 | |
16 void KeyboardEventCounter::Reset() { | |
17 base::AutoLock auto_lock(lock_); | |
18 pressed_keys_.clear(); | |
19 total_key_presses_ = 0; | |
20 } | |
21 | |
22 void KeyboardEventCounter::OnKeyboardEvent(ui::EventType event, | |
23 ui::KeyboardCode key_code) { | |
24 base::AutoLock auto_lock(lock_); | |
Mark Mentovai
2013/08/26 19:33:43
Is it true that pressed_keys_ will now be maintain
jiayl
2013/08/26 20:09:19
UserInputMonitorLinux needs to be refactored to ma
| |
25 // Updates the pressed keys and the total count of key presses. | |
26 if (event == ui::ET_KEY_PRESSED) { | |
27 if (pressed_keys_.find(key_code) != pressed_keys_.end()) | |
28 return; | |
29 pressed_keys_.insert(key_code); | |
30 base::subtle::NoBarrier_AtomicIncrement( | |
31 reinterpret_cast<base::subtle::AtomicWord*>(&total_key_presses_), 1); | |
32 } else { | |
33 DCHECK_EQ(ui::ET_KEY_RELEASED, event); | |
34 pressed_keys_.erase(key_code); | |
35 } | |
36 } | |
37 | |
38 size_t KeyboardEventCounter::GetKeyPressCount() const { | |
39 return total_key_presses_; | |
Mark Mentovai
2013/08/26 19:33:43
You should use NoBarrier_Load here now (even thoug
jiayl
2013/08/26 20:09:19
Done.
| |
40 } | |
41 | |
42 } // namespace media | |
OLD | NEW |