Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/keyboard_event_counter.h" | 5 #include "media/base/keyboard_event_counter.h" |
| 6 | 6 |
| 7 #include "base/atomicops.h" | 7 #include "base/atomicops.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| 11 | 11 |
| 12 KeyboardEventCounter::KeyboardEventCounter() : total_key_presses_(0) {} | 12 KeyboardEventCounter::KeyboardEventCounter() : total_key_presses_(0) {} |
| 13 | 13 |
| 14 KeyboardEventCounter::~KeyboardEventCounter() {} | 14 KeyboardEventCounter::~KeyboardEventCounter() {} |
| 15 | 15 |
| 16 void KeyboardEventCounter::Reset() { | 16 void KeyboardEventCounter::Reset() { |
| 17 pressed_keys_.clear(); | 17 pressed_keys_.clear(); |
| 18 base::subtle::NoBarrier_Store( | 18 base::subtle::NoBarrier_Store( |
| 19 reinterpret_cast<base::subtle::AtomicWord*>(&total_key_presses_), 0); | 19 reinterpret_cast<base::subtle::AtomicWord*>(&total_key_presses_), 0); |
| 20 } | 20 } |
| 21 | 21 |
| 22 void KeyboardEventCounter::OnKeyboardEvent(ui::EventType event, | 22 void KeyboardEventCounter::OnKeyboardEvent(bool down, |
|
xhwang
2017/01/10 20:13:15
personally I found an explicit enum is more readab
Wez
2017/01/10 23:19:24
Yes, strictly it's preferable to keep this as an e
CJ
2017/01/11 21:40:27
Confused as how the key_is_down ? KeyDown : KeyUp
Wez
2017/01/11 21:54:22
I just meant that instead of restoring this:
CJ
2017/01/11 23:08:09
Done.
| |
| 23 ui::KeyboardCode key_code) { | 23 ui::KeyboardCode key_code) { |
| 24 // Updates the pressed keys and the total count of key presses. | 24 // Updates the pressed keys and the total count of key presses. |
| 25 if (event == ui::ET_KEY_PRESSED) { | 25 if (down) { |
| 26 if (pressed_keys_.find(key_code) != pressed_keys_.end()) | 26 if (pressed_keys_.find(key_code) != pressed_keys_.end()) |
| 27 return; | 27 return; |
| 28 pressed_keys_.insert(key_code); | 28 pressed_keys_.insert(key_code); |
| 29 base::subtle::NoBarrier_AtomicIncrement( | 29 base::subtle::NoBarrier_AtomicIncrement( |
| 30 reinterpret_cast<base::subtle::AtomicWord*>(&total_key_presses_), 1); | 30 reinterpret_cast<base::subtle::AtomicWord*>(&total_key_presses_), 1); |
| 31 } else { | 31 } else { |
| 32 DCHECK_EQ(ui::ET_KEY_RELEASED, event); | |
| 33 pressed_keys_.erase(key_code); | 32 pressed_keys_.erase(key_code); |
| 34 } | 33 } |
| 35 } | 34 } |
| 36 | 35 |
| 37 size_t KeyboardEventCounter::GetKeyPressCount() const { | 36 size_t KeyboardEventCounter::GetKeyPressCount() const { |
| 38 return base::subtle::NoBarrier_Load( | 37 return base::subtle::NoBarrier_Load( |
| 39 reinterpret_cast<const base::subtle::AtomicWord*>(&total_key_presses_)); | 38 reinterpret_cast<const base::subtle::AtomicWord*>(&total_key_presses_)); |
| 40 } | 39 } |
| 41 | 40 |
| 42 } // namespace media | 41 } // namespace media |
| OLD | NEW |