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..6406462707f1cd8892067c0185f145cd86a0fdab |
| --- /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 "base/basictypes.h" |
| +#include "base/observer_list.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; |
| + protected: |
| + virtual ~KeyPressListener() {} |
| + }; |
| + |
| + KeyPressMonitor(); |
| + ~KeyPressMonitor(); |
| + |
| + // Adds |listener| to receive event notifications. A listener should not be |
| + // added more than once. |
| + // 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 ObserverList<KeyPressListener> ListenerList; |
|
DaleCurtis
2013/08/02 01:01:17
Typedef seems a bit overkill. AudioInputControlle
jiayl
2013/08/02 20:32:20
Done.
|
| + ListenerList listeners_; |
| + base::Lock listeners_lock_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(KeyPressMonitor); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_AUDIO_KEY_PRESS_MONITOR_H_ |