Chromium Code Reviews| Index: media/base/user_input_monitor.h |
| diff --git a/media/base/user_input_monitor.h b/media/base/user_input_monitor.h |
| index 9eb82f334f833612a0720367c83c4513ba275bef..91fa311d73c1dee6397a59b8ac45cc751e07600d 100644 |
| --- a/media/base/user_input_monitor.h |
| +++ b/media/base/user_input_monitor.h |
| @@ -9,7 +9,6 @@ |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| -#include "base/memory/weak_ptr.h" |
| #include "base/observer_list.h" |
| #include "base/synchronization/lock.h" |
| #include "media/base/media_export.h" |
| @@ -28,6 +27,8 @@ namespace media { |
| // Thread safe. The thread on which the listenters are called is not guaranteed. |
| // The callers should not perform expensive/blocking tasks in the callback since |
| // it might be called on the browser UI/IO threads. |
| +// The object must outlive the browser UI/IO threads to make sure the callbacks |
| +// will not access deleted object. |
| class MEDIA_EXPORT UserInputMonitor { |
| public: |
| // The interface to receive mouse movement events. |
| @@ -39,17 +40,6 @@ class MEDIA_EXPORT UserInputMonitor { |
| protected: |
| virtual ~MouseEventListener() {} |
| }; |
| - // The interface to receive key stroke events. |
| - class MEDIA_EXPORT KeyStrokeListener { |
| - public: |
| - // Called when any key is pressed. Called only once until the key is |
| - // released, i.e. holding down a key for a long period will generate one |
| - // callback just when the key is pressed down. |
| - virtual void OnKeyStroke() = 0; |
| - |
| - protected: |
| - virtual ~KeyStrokeListener() {} |
| - }; |
| virtual ~UserInputMonitor(); |
| @@ -65,8 +55,15 @@ class MEDIA_EXPORT UserInputMonitor { |
| // destroyed. |
| void AddMouseListener(MouseEventListener* listener); |
| void RemoveMouseListener(MouseEventListener* listener); |
| - void AddKeyStrokeListener(KeyStrokeListener* listener); |
| - void RemoveKeyStrokeListener(KeyStrokeListener* listener); |
| + |
| + // The callers must call AddKeyPressCounterReference before calling |
| + // GetKeyPressCount(), and call ReleaseKeyPressCounterReference when it no |
| + // longer needs it. |
| + void AddKeyPressCounterReference(); |
| + void ReleaseKeyPressCounterReference(); |
| + // Returns the number of Key presses since the first KeyPressCounterReference |
| + // is added. Auto-repeated key presses are not counted. |
| + virtual size_t GetKeyPressCount() const; |
| protected: |
| UserInputMonitor(); |
| @@ -82,14 +79,14 @@ class MEDIA_EXPORT UserInputMonitor { |
| virtual void StartKeyboardMonitoring() = 0; |
| virtual void StopKeyboardMonitoring() = 0; |
| - base::Lock lock_; |
| + mutable base::Lock lock_; |
| ObserverList<MouseEventListener, true> mouse_listeners_; |
| - ObserverList<KeyStrokeListener, true> key_stroke_listeners_; |
| bool monitoring_mouse_; |
| - bool monitoring_keyboard_; |
| + size_t key_press_counter_references_; |
| // The set of keys currently held down. Used for convering raw keyboard events |
| // into KeyStrokeListener callbacks. |
| - std::set<ui::KeyboardCode> pressed_keys_; |
| + std::set<int> pressed_keys_; |
| + size_t total_key_presses_; |
|
DaleCurtis
2013/08/22 22:07:34
Shouldn't this just be pressed_keys_.size() ?
jiayl
2013/08/22 22:23:22
No. If you press and release a key, pressed_keys_.
|
| DISALLOW_COPY_AND_ASSIGN(UserInputMonitor); |
| }; |