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

Unified Diff: media/base/user_input_monitor.h

Issue 22801007: Adds the UserInputMonitor implementation for Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
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..e58d7b268700ec6ad80d28f8ffae512939f56245 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 EnableKeyPressMonitoring before calling
Mark Mentovai 2013/08/23 18:09:03 “A caller must call” That clarifies that it’s OK
+ // GetKeyPressCount(), and call DisableKeyPressMonitoring when it no
+ // longer needs it.
+ void EnableKeyPressMonitoring();
+ void DisableKeyPressMonitoring();
+ // Returns the number of Key presses since the first KeyPressCounterReference
Mark Mentovai 2013/08/23 18:09:03 Let’s get a blank line before this, because otherw
Mark Mentovai 2013/08/23 18:09:03 Key is not a proper noun, it shouldn’t be capitali
Mark Mentovai 2013/08/23 18:09:03 This comment introduces the concept of a KeyPressC
+ // is added. Auto-repeated key presses are not counted.
Mark Mentovai 2013/08/23 18:09:03 It’s fine if the implementation doesn’t count auto
+ 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_;
Mark Mentovai 2013/08/23 18:09:03 What sort of constness is changing that requires t
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_;
Mark Mentovai 2013/08/23 18:09:03 This is irrelevant on at least one platform now.
+ size_t total_key_presses_;
DISALLOW_COPY_AND_ASSIGN(UserInputMonitor);
};

Powered by Google App Engine
This is Rietveld 408576698