Chromium Code Reviews| 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..1454b5e1760955f148a6996eb93a8f900878c8cc |
| --- /dev/null |
| +++ b/media/audio/key_press_monitor.h |
| @@ -0,0 +1,55 @@ |
| +// 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 "base/basictypes.h" |
| +#include "base/observer_list.h" |
| +#include "base/synchronization/lock.h" |
| + |
| +namespace base { |
| +class MessageLoopProxy; |
| +} // namespace base |
| + |
| +namespace media { |
| + |
| +// This class monitors the system-wide key presses and notifies the listeners. |
| +// Not thread safe. All methods should be called on the thread whose message |
| +// loop is passed to the ctor. |
|
DaleCurtis
2013/08/02 21:04:47
What about construction and destruction? Should d
jiayl
2013/08/02 21:45:45
Changed it to RefCountedThreadSafe. AudioInputCont
DaleCurtis
2013/08/02 21:55:29
Ref counting is a last resort and likely overkill
|
| +class KeyPressMonitor { |
| + public: |
| + class KeyPressListener { |
| + public: |
| + // This is called on |message_loop_|'s thread. |
| + virtual void OnKeyPressed() = 0; |
| + protected: |
| + virtual ~KeyPressListener() {} |
| + }; |
| + |
| + // |message_loop| is the message loop that this object runs on. |
| + KeyPressMonitor(base::MessageLoopProxy* message_loop); |
| + ~KeyPressMonitor(); |
| + |
| + // Adds |listener| to receive event notifications. A listener should not be |
| + // added more than once. |
| + // The callers should make sure to 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. |
| + ObserverList<KeyPressListener> listeners_; |
| + // The message loop of the thread that this object runs on. |
| + scoped_refptr<base::MessageLoopProxy> message_loop_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(KeyPressMonitor); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_AUDIO_KEY_PRESS_MONITOR_H_ |