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

Unified Diff: media/audio/key_press_monitor.h

Issue 21183002: Adding key press detection in the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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/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_

Powered by Google App Engine
This is Rietveld 408576698