Index: media/audio/key_press_monitor.h |
diff --git a/media/audio/key_press_monitor.h b/media/audio/key_press_monitor.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cafbe2bdb9af5d55d6eaec55f89ba1d771c1fbbc |
--- /dev/null |
+++ b/media/audio/key_press_monitor.h |
@@ -0,0 +1,51 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_AUDIO_KEY_PRESS_MONITOR_H_ |
+#define MEDIA_AUDIO_KEY_PRESS_MONITOR_H_ |
+ |
+#include <unordered_set> |
+ |
+#include "base/basictypes.h" |
+#include "base/synchronization/lock.h" |
+ |
+namespace media { |
+ |
+// This class monitors the system-wide key presses and notifies the listeners. |
+// All methods can be called on any thread. |
+// TODO(jiayl): this is only a stub now. Need to implement the event monitoring. |
+class KeyPressMonitor { |
+ public: |
+ // The implementation has to be thread safe. |
+ class KeyPressListener { |
+ public: |
+ // This can be called on any thread. |
+ virtual void OnKeyPressed() = 0; |
+ virtual ~KeyPressListener() {} |
DaleCurtis
2013/08/01 23:20:29
protected:
jiayl
2013/08/01 23:35:22
Done.
|
+ }; |
+ |
+ KeyPressMonitor(); |
+ ~KeyPressMonitor(); |
+ |
+ // Adds |listener| to receive event notifications. Does nothing if |listener| |
+ // is already added. |
+ // The callers should make sure |listener| is valid and call |
+ // RemoveKeyPressListener before |listener| is destroyed. |
+ void AddKeyPressListener(KeyPressListener* listener); |
+ // Removes |listener| from receiving event notifications. Does nothing if |
+ // |listener| has not been added or has already been removed. |
+ void RemoveKeyPressListener(KeyPressListener* listener); |
+ |
+ private: |
+ // Raw pointers of the listeners. |
+ typedef std::unordered_set<KeyPressListener*> ListenerSet; |
DaleCurtis
2013/08/01 23:20:29
Use base::ObserverList instead.
jiayl
2013/08/01 23:35:22
Done.
|
+ ListenerSet listeners_; |
+ base::Lock listeners_lock_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(KeyPressMonitor); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_AUDIO_KEY_PRESS_MONITOR_H_ |