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

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 should be called on the thread whose message
20 // 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
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 protected:
28 virtual ~KeyPressListener() {}
29 };
30
31 // |message_loop| is the message loop that this object runs on.
32 KeyPressMonitor(base::MessageLoopProxy* message_loop);
33 ~KeyPressMonitor();
34
35 // Adds |listener| to receive event notifications. A listener should not be
36 // added more than once.
37 // The callers should make sure to call RemoveKeyPressListener before
38 // |listener| is destroyed.
39 void AddKeyPressListener(KeyPressListener* listener);
40 // Removes |listener| from receiving event notifications. Does nothing if
41 // |listener| has not been added or has already been removed.
42 void RemoveKeyPressListener(KeyPressListener* listener);
43
44 private:
45 // Raw pointers of the listeners.
46 ObserverList<KeyPressListener> listeners_;
47 // The message loop of the thread that this object runs on.
48 scoped_refptr<base::MessageLoopProxy> message_loop_;
49
50 DISALLOW_COPY_AND_ASSIGN(KeyPressMonitor);
51 };
52
53 } // namespace media
54
55 #endif // MEDIA_AUDIO_KEY_PRESS_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698