OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/user_input_monitor.h" | 5 #include "media/base/user_input_monitor.h" |
6 | 6 |
7 #include "third_party/skia/include/core/SkPoint.h" | 7 #include "third_party/skia/include/core/SkPoint.h" |
8 | 8 |
9 namespace media { | 9 namespace media { |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 mouse_listeners_.AddObserver(listener); | 26 mouse_listeners_.AddObserver(listener); |
27 if (!monitoring_mouse_) { | 27 if (!monitoring_mouse_) { |
28 StartMouseMonitoring(); | 28 StartMouseMonitoring(); |
29 monitoring_mouse_ = true; | 29 monitoring_mouse_ = true; |
30 DVLOG(2) << "Started mouse monitoring."; | 30 DVLOG(2) << "Started mouse monitoring."; |
31 } | 31 } |
32 } | 32 } |
33 void UserInputMonitor::RemoveMouseListener(MouseEventListener* listener) { | 33 void UserInputMonitor::RemoveMouseListener(MouseEventListener* listener) { |
34 base::AutoLock auto_lock(lock_); | 34 base::AutoLock auto_lock(lock_); |
35 mouse_listeners_.RemoveObserver(listener); | 35 mouse_listeners_.RemoveObserver(listener); |
36 if (mouse_listeners_.size() == 0) { | 36 if (!mouse_listeners_.might_have_observers()) { |
37 StopMouseMonitoring(); | 37 StopMouseMonitoring(); |
38 monitoring_mouse_ = false; | 38 monitoring_mouse_ = false; |
39 DVLOG(2) << "Stopped mouse monitoring."; | 39 DVLOG(2) << "Stopped mouse monitoring."; |
40 } | 40 } |
41 } | 41 } |
42 void UserInputMonitor::AddKeyStrokeListener(KeyStrokeListener* listener) { | 42 void UserInputMonitor::AddKeyStrokeListener(KeyStrokeListener* listener) { |
43 base::AutoLock auto_lock(lock_); | 43 base::AutoLock auto_lock(lock_); |
44 key_stroke_listeners_.AddObserver(listener); | 44 key_stroke_listeners_.AddObserver(listener); |
45 if (!monitoring_keyboard_) { | 45 if (!monitoring_keyboard_) { |
46 StartKeyboardMonitoring(); | 46 StartKeyboardMonitoring(); |
47 monitoring_keyboard_ = true; | 47 monitoring_keyboard_ = true; |
48 DVLOG(2) << "Started keyboard monitoring."; | 48 DVLOG(2) << "Started keyboard monitoring."; |
49 } | 49 } |
50 } | 50 } |
51 void UserInputMonitor::RemoveKeyStrokeListener(KeyStrokeListener* listener) { | 51 void UserInputMonitor::RemoveKeyStrokeListener(KeyStrokeListener* listener) { |
52 base::AutoLock auto_lock(lock_); | 52 base::AutoLock auto_lock(lock_); |
53 key_stroke_listeners_.RemoveObserver(listener); | 53 key_stroke_listeners_.RemoveObserver(listener); |
54 if (key_stroke_listeners_.size() == 0) { | 54 if (!key_stroke_listeners_.might_have_observers()) { |
55 StopKeyboardMonitoring(); | 55 StopKeyboardMonitoring(); |
56 monitoring_keyboard_ = false; | 56 monitoring_keyboard_ = false; |
57 DVLOG(2) << "Stopped keyboard monitoring."; | 57 DVLOG(2) << "Stopped keyboard monitoring."; |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 UserInputMonitor::UserInputMonitor() | 61 UserInputMonitor::UserInputMonitor() |
62 : monitoring_mouse_(false), monitoring_keyboard_(false) {} | 62 : monitoring_mouse_(false), monitoring_keyboard_(false) {} |
63 | 63 |
64 void UserInputMonitor::OnMouseEvent(const SkIPoint& position) { | 64 void UserInputMonitor::OnMouseEvent(const SkIPoint& position) { |
(...skipping 13 matching lines...) Expand all Loading... |
78 DVLOG(6) << "Key stroke detected."; | 78 DVLOG(6) << "Key stroke detected."; |
79 FOR_EACH_OBSERVER(KeyStrokeListener, key_stroke_listeners_, OnKeyStroke()); | 79 FOR_EACH_OBSERVER(KeyStrokeListener, key_stroke_listeners_, OnKeyStroke()); |
80 } else { | 80 } else { |
81 DCHECK_EQ(ui::ET_KEY_RELEASED, event); | 81 DCHECK_EQ(ui::ET_KEY_RELEASED, event); |
82 DCHECK(pressed_keys_.find(key_code) != pressed_keys_.end()); | 82 DCHECK(pressed_keys_.find(key_code) != pressed_keys_.end()); |
83 pressed_keys_.erase(key_code); | 83 pressed_keys_.erase(key_code); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 } // namespace media | 87 } // namespace media |
OLD | NEW |