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

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

Issue 2577573002: Removes mouse listeners from UserInputMonitor. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | media/base/user_input_monitor.cc » ('j') | media/base/user_input_monitor.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_USER_INPUT_MONITOR_H_ 5 #ifndef MEDIA_BASE_USER_INPUT_MONITOR_H_
6 #define MEDIA_BASE_USER_INPUT_MONITOR_H_ 6 #define MEDIA_BASE_USER_INPUT_MONITOR_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/observer_list_threadsafe.h" 14 #include "base/observer_list_threadsafe.h"
Wez 2016/12/16 02:06:43 nit: This header include is no longer necessary.
CJ 2016/12/22 22:42:57 Done.
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "media/base/media_export.h" 16 #include "media/base/media_export.h"
17 17
18 struct SkIPoint; 18 struct SkIPoint;
19 19
20 namespace base { 20 namespace base {
21 class SingleThreadTaskRunner; 21 class SingleThreadTaskRunner;
22 } // namespace base 22 } // namespace base
23 23
24 namespace media { 24 namespace media {
25 25
26 // Monitors and notifies about mouse movements and keyboard events. 26 // Monitors and notifies about mouse movements and keyboard events.
Wez 2016/12/16 02:06:43 nit: Update this to remove mention of mouse.
CJ 2016/12/22 22:42:57 Done.
27 // Thread safe. The listeners are called on the thread where the listeners are 27 // Thread safe. The listeners are called on the thread where the listeners are
28 // added. 28 // added.
29 class MEDIA_EXPORT UserInputMonitor { 29 class MEDIA_EXPORT UserInputMonitor {
30 public: 30 public:
31 // The interface to receive mouse movement events.
32 class MEDIA_EXPORT MouseEventListener {
33 public:
34 // |position| is the new mouse position.
35 virtual void OnMouseMoved(const SkIPoint& position) = 0;
36
37 protected:
38 virtual ~MouseEventListener() {}
39 };
40 typedef base::ObserverListThreadSafe<UserInputMonitor::MouseEventListener>
41 MouseListenerList;
42
43 UserInputMonitor(); 31 UserInputMonitor();
44 virtual ~UserInputMonitor(); 32 virtual ~UserInputMonitor();
45 33
46 // Creates a platform-specific instance of UserInputMonitor. 34 // Creates a platform-specific instance of UserInputMonitor.
47 // |io_task_runner| is the task runner for an IO thread. 35 // |io_task_runner| is the task runner for an IO thread.
48 // |ui_task_runner| is the task runner for a UI thread. 36 // |ui_task_runner| is the task runner for a UI thread.
49 static std::unique_ptr<UserInputMonitor> Create( 37 static std::unique_ptr<UserInputMonitor> Create(
50 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 38 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
51 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); 39 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
52 40
53 // The same |listener| should only be added once.
54 // The clients should make sure to call Remove*Listener before |listener| is
55 // destroyed.
56 void AddMouseListener(MouseEventListener* listener);
57 void RemoveMouseListener(MouseEventListener* listener);
58
59 // A caller must call EnableKeyPressMonitoring and 41 // A caller must call EnableKeyPressMonitoring and
60 // DisableKeyPressMonitoring in pair. 42 // DisableKeyPressMonitoring in pair.
61 void EnableKeyPressMonitoring(); 43 void EnableKeyPressMonitoring();
62 void DisableKeyPressMonitoring(); 44 void DisableKeyPressMonitoring();
63 45
64 // Returns the number of keypresses. The starting point from when it is 46 // Returns the number of keypresses. The starting point from when it is
65 // counted is not guaranteed, but consistent within the pair of calls of 47 // counted is not guaranteed, but consistent within the pair of calls of
66 // EnableKeyPressMonitoring and DisableKeyPressMonitoring. So a caller can 48 // EnableKeyPressMonitoring and DisableKeyPressMonitoring. So a caller can
67 // use the difference between the values returned at two times to get the 49 // use the difference between the values returned at two times to get the
68 // number of keypresses happened within that time period, but should not make 50 // number of keypresses happened within that time period, but should not make
69 // any assumption on the initial value. 51 // any assumption on the initial value.
70 virtual size_t GetKeyPressCount() const = 0; 52 virtual size_t GetKeyPressCount() const = 0;
71 53
72 protected:
73 scoped_refptr<MouseListenerList> mouse_listeners() {
74 return mouse_listeners_;
75 }
76
77 private: 54 private:
78 virtual void StartKeyboardMonitoring() = 0; 55 virtual void StartKeyboardMonitoring() = 0;
79 virtual void StopKeyboardMonitoring() = 0; 56 virtual void StopKeyboardMonitoring() = 0;
80 virtual void StartMouseMonitoring() = 0;
81 virtual void StopMouseMonitoring() = 0;
82 57
83 base::Lock lock_; 58 base::Lock lock_;
84 size_t key_press_counter_references_; 59 size_t key_press_counter_references_;
85 size_t mouse_listeners_count_;
86 scoped_refptr<MouseListenerList> mouse_listeners_;
87 60
88 DISALLOW_COPY_AND_ASSIGN(UserInputMonitor); 61 DISALLOW_COPY_AND_ASSIGN(UserInputMonitor);
89 }; 62 };
90 63
91 } // namespace media 64 } // namespace media
92 65
93 #endif // MEDIA_BASE_USER_INPUT_MONITOR_H_ 66 #endif // MEDIA_BASE_USER_INPUT_MONITOR_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/user_input_monitor.cc » ('j') | media/base/user_input_monitor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698