Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: media/base/keyboard_event_counter.h

Issue 2577573002: Removes mouse listeners from UserInputMonitor. (Closed)
Patch Set: Lint. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ 5 #ifndef MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_
6 #define MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ 6 #define MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <set> 10 #include <set>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "media/base/media_export.h" 14 #include "media/base/media_export.h"
15 #include "ui/events/event_constants.h" 15 #include "ui/events/event_constants.h"
16 #include "ui/events/keycodes/keyboard_codes.h" 16 #include "ui/events/keycodes/keyboard_codes.h"
17 17
18 namespace media { 18 namespace media {
19 19
20 // This class tracks the total number of keypresses based on the OnKeyboardEvent 20 // This class tracks the total number of keypresses based on the OnKeyboardEvent
21 // calls it receives from the client. 21 // calls it receives from the client.
22 // Multiple key down events for the same key are counted as one keypress until 22 // Multiple key down events for the same key are counted as one keypress until
23 // the same key is released. 23 // the same key is released.
24 class MEDIA_EXPORT KeyboardEventCounter { 24 class MEDIA_EXPORT KeyboardEventCounter {
25 public: 25 public:
26 KeyboardEventCounter(); 26 KeyboardEventCounter();
27 ~KeyboardEventCounter(); 27 ~KeyboardEventCounter();
28 28
29 // Resets the count to 0. Must be called on the same thread as 29 // Resets the count to 0. Must be called on the same thread as
30 // OnKeyboardEvent. 30 // OnKeyboardEvent.
xhwang 2017/01/10 20:13:15 Can we use a ThreadChecker to enforce this?
Wez 2017/01/10 23:19:24 +1, if this constraint is valid. However, it's no
CJ 2017/01/11 23:41:55 Waiting on the result of this conversation.
CJ 2017/01/12 23:59:37 Removing Reset(). In the implementation, |total_ke
Wez 2017/01/13 01:26:16 No, but good question. The base::subtle::Atomic s
31 void Reset(); 31 void Reset();
32 32
33 // Returns the total number of keypresses since its creation or last Reset() 33 // Returns the total number of keypresses since its creation or last Reset()
34 // call. Can be called on any thread. 34 // call. Can be called on any thread.
35 size_t GetKeyPressCount() const; 35 size_t GetKeyPressCount() const;
36 36
37 // The client should call this method on key down or key up events. 37 // The client should call this method on key down or key up events.
38 // Must be called on a single thread. 38 // Must be called on a single thread.
39 void OnKeyboardEvent(ui::EventType event, ui::KeyboardCode key_code); 39 void OnKeyboardEvent(bool down, ui::KeyboardCode key_code);
40 40
41 private: 41 private:
42 // The set of keys currently held down. 42 // The set of keys currently held down.
43 std::set<ui::KeyboardCode> pressed_keys_; 43 std::set<ui::KeyboardCode> pressed_keys_;
44 44
45 size_t total_key_presses_; 45 size_t total_key_presses_;
46 46
47 DISALLOW_COPY_AND_ASSIGN(KeyboardEventCounter); 47 DISALLOW_COPY_AND_ASSIGN(KeyboardEventCounter);
48 }; 48 };
49 49
50 } // namespace media 50 } // namespace media
51 51
52 #endif // MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ 52 #endif // MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698