| 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..2296a51bd13907f9b893e9fca6a6cb6a53bf77af
|
| --- /dev/null
|
| +++ b/media/audio/key_press_monitor.h
|
| @@ -0,0 +1,56 @@
|
| +// 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 except ctor and dtor should be called on the
|
| +// thread whose message loop is passed to the ctor.
|
| +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(const scoped_refptr<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_
|
|
|