Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <unordered_set> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/synchronization/lock.h" | |
| 12 | |
| 13 namespace media { | |
| 14 | |
| 15 // This class monitors the system-wide key presses and notifies the listeners. | |
| 16 // All methods can be called on any thread. | |
| 17 // TODO(jiayl): this is only a stub now. Need to implement the event monitoring. | |
| 18 class KeyPressMonitor { | |
| 19 public: | |
| 20 // The implementation has to be thread safe. | |
| 21 class KeyPressListener { | |
| 22 public: | |
| 23 // This can be called on any thread. | |
| 24 virtual void OnKeyPressed() = 0; | |
| 25 virtual ~KeyPressListener() {} | |
|
DaleCurtis
2013/08/01 23:20:29
protected:
jiayl
2013/08/01 23:35:22
Done.
| |
| 26 }; | |
| 27 | |
| 28 KeyPressMonitor(); | |
| 29 ~KeyPressMonitor(); | |
| 30 | |
| 31 // Adds |listener| to receive event notifications. Does nothing if |listener| | |
| 32 // is already added. | |
| 33 // The callers should make sure |listener| is valid and call | |
| 34 // RemoveKeyPressListener before |listener| is destroyed. | |
| 35 void AddKeyPressListener(KeyPressListener* listener); | |
| 36 // Removes |listener| from receiving event notifications. Does nothing if | |
| 37 // |listener| has not been added or has already been removed. | |
| 38 void RemoveKeyPressListener(KeyPressListener* listener); | |
| 39 | |
| 40 private: | |
| 41 // Raw pointers of the listeners. | |
| 42 typedef std::unordered_set<KeyPressListener*> ListenerSet; | |
|
DaleCurtis
2013/08/01 23:20:29
Use base::ObserverList instead.
jiayl
2013/08/01 23:35:22
Done.
| |
| 43 ListenerSet listeners_; | |
| 44 base::Lock listeners_lock_; | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(KeyPressMonitor); | |
| 47 }; | |
| 48 | |
| 49 } // namespace media | |
| 50 | |
| 51 #endif // MEDIA_AUDIO_KEY_PRESS_MONITOR_H_ | |
| OLD | NEW |