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

Side by Side 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, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_AUDIO_KEY_PRESS_MONITOR_H_
6 #define MEDIA_AUDIO_KEY_PRESS_MONITOR_H_
7
8 #include "base/basictypes.h"
9 #include "base/observer_list.h"
10 #include "base/synchronization/lock.h"
11
12 namespace base {
13 class MessageLoopProxy;
14 } // namespace base
15
16 namespace media {
17
18 // This class monitors the system-wide key presses and notifies the listeners.
19 // Not thread safe. All methods except ctor and dtor should be called on the
20 // thread whose message loop is passed to the ctor.
21 class KeyPressMonitor {
22 public:
23 class KeyPressListener {
24 public:
25 // This is called on |message_loop_|'s thread.
26 virtual void OnKeyPressed() = 0;
27
28 protected:
29 virtual ~KeyPressListener() {}
30 };
31
32 // |message_loop| is the message loop that this object runs on.
33 KeyPressMonitor(const scoped_refptr<base::MessageLoopProxy>& message_loop);
34 ~KeyPressMonitor();
35
36 // Adds |listener| to receive event notifications. A listener should not be
37 // added more than once.
38 // The callers should make sure to call RemoveKeyPressListener before
39 // |listener| is destroyed.
40 void AddKeyPressListener(KeyPressListener* listener);
41 // Removes |listener| from receiving event notifications. Does nothing if
42 // |listener| has not been added or has already been removed.
43 void RemoveKeyPressListener(KeyPressListener* listener);
44
45 private:
46 // Raw pointers of the listeners.
47 ObserverList<KeyPressListener> listeners_;
48 // The message loop of the thread that this object runs on.
49 scoped_refptr<base::MessageLoopProxy> message_loop_;
50
51 DISALLOW_COPY_AND_ASSIGN(KeyPressMonitor);
52 };
53
54 } // namespace media
55
56 #endif // MEDIA_AUDIO_KEY_PRESS_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698