| 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 "base/logging.h" |
| 7 #include "third_party/skia/include/core/SkPoint.h" | 8 #include "third_party/skia/include/core/SkPoint.h" |
| 8 | 9 |
| 9 namespace media { | 10 namespace media { |
| 10 | 11 |
| 11 #ifdef DISABLE_USER_INPUT_MONITOR | 12 #ifdef DISABLE_USER_INPUT_MONITOR |
| 12 scoped_ptr<UserInputMonitor> UserInputMonitor::Create( | 13 scoped_ptr<UserInputMonitor> UserInputMonitor::Create( |
| 13 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 14 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 14 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { | 15 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { |
| 15 return scoped_ptr<UserInputMonitor>(); | 16 return scoped_ptr<UserInputMonitor>(); |
| 16 } | 17 } |
| 17 #endif // DISABLE_USER_INPUT_MONITOR | 18 #endif // DISABLE_USER_INPUT_MONITOR |
| 18 | 19 |
| 19 UserInputMonitor::UserInputMonitor() | 20 UserInputMonitor::UserInputMonitor() : key_press_counter_references_(0) {} |
| 20 : monitoring_mouse_(false), key_press_counter_references_(0) {} | |
| 21 | 21 |
| 22 UserInputMonitor::~UserInputMonitor() { | 22 UserInputMonitor::~UserInputMonitor() { |
| 23 DCHECK(!monitoring_mouse_); | 23 DCHECK_EQ(0u, key_press_counter_references_); |
| 24 DCHECK(!key_press_counter_references_); | |
| 25 } | |
| 26 | |
| 27 void UserInputMonitor::AddMouseListener(MouseEventListener* listener) { | |
| 28 base::AutoLock auto_lock(lock_); | |
| 29 mouse_listeners_.AddObserver(listener); | |
| 30 if (!monitoring_mouse_) { | |
| 31 StartMouseMonitoring(); | |
| 32 monitoring_mouse_ = true; | |
| 33 DVLOG(2) << "Started mouse monitoring."; | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 void UserInputMonitor::RemoveMouseListener(MouseEventListener* listener) { | |
| 38 base::AutoLock auto_lock(lock_); | |
| 39 mouse_listeners_.RemoveObserver(listener); | |
| 40 if (!mouse_listeners_.might_have_observers()) { | |
| 41 StopMouseMonitoring(); | |
| 42 monitoring_mouse_ = false; | |
| 43 DVLOG(2) << "Stopped mouse monitoring."; | |
| 44 } | |
| 45 } | 24 } |
| 46 | 25 |
| 47 void UserInputMonitor::EnableKeyPressMonitoring() { | 26 void UserInputMonitor::EnableKeyPressMonitoring() { |
| 48 base::AutoLock auto_lock(lock_); | 27 base::AutoLock auto_lock(lock_); |
| 49 ++key_press_counter_references_; | 28 ++key_press_counter_references_; |
| 50 if (key_press_counter_references_ == 1) { | 29 if (key_press_counter_references_ == 1) { |
| 51 StartKeyboardMonitoring(); | 30 StartKeyboardMonitoring(); |
| 52 DVLOG(2) << "Started keyboard monitoring."; | 31 DVLOG(2) << "Started keyboard monitoring."; |
| 53 } | 32 } |
| 54 } | 33 } |
| 55 | 34 |
| 56 void UserInputMonitor::DisableKeyPressMonitoring() { | 35 void UserInputMonitor::DisableKeyPressMonitoring() { |
| 57 base::AutoLock auto_lock(lock_); | 36 base::AutoLock auto_lock(lock_); |
| 58 DCHECK_NE(key_press_counter_references_, 0u); | 37 DCHECK_NE(key_press_counter_references_, 0u); |
| 59 --key_press_counter_references_; | 38 --key_press_counter_references_; |
| 60 if (key_press_counter_references_ == 0) { | 39 if (key_press_counter_references_ == 0) { |
| 61 StopKeyboardMonitoring(); | 40 StopKeyboardMonitoring(); |
| 62 DVLOG(2) << "Stopped keyboard monitoring."; | 41 DVLOG(2) << "Stopped keyboard monitoring."; |
| 63 } | 42 } |
| 64 } | 43 } |
| 65 | 44 |
| 66 void UserInputMonitor::OnMouseEvent(const SkIPoint& position) { | |
| 67 base::AutoLock auto_lock(lock_); | |
| 68 if (!monitoring_mouse_) | |
| 69 return; | |
| 70 FOR_EACH_OBSERVER( | |
| 71 MouseEventListener, mouse_listeners_, OnMouseMoved(position)); | |
| 72 } | |
| 73 | |
| 74 } // namespace media | 45 } // namespace media |
| OLD | NEW |