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