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
3 // found in the LICENSE file.
5 #include "media/base/user_input_monitor.h"
7 #include "base/logging.h"
11 #ifdef DISABLE_USER_INPUT_MONITOR
12 scoped_ptr
<UserInputMonitor
> UserInputMonitor::Create(
13 const scoped_refptr
<base::SingleThreadTaskRunner
>& io_task_runner
,
14 const scoped_refptr
<base::SingleThreadTaskRunner
>& ui_task_runner
) {
15 return scoped_ptr
<UserInputMonitor
>();
17 #endif // DISABLE_USER_INPUT_MONITOR
19 UserInputMonitor::UserInputMonitor()
20 : key_press_counter_references_(0),
21 mouse_listeners_count_(0),
22 mouse_listeners_(new MouseListenerList()) {}
24 UserInputMonitor::~UserInputMonitor() {
25 DCHECK_EQ(0u, key_press_counter_references_
);
26 mouse_listeners_
->AssertEmpty();
29 void UserInputMonitor::AddMouseListener(MouseEventListener
* listener
) {
30 mouse_listeners_
->AddObserver(listener
);
32 base::AutoLock
auto_lock(lock_
);
33 mouse_listeners_count_
++;
34 if (mouse_listeners_count_
== 1) {
35 StartMouseMonitoring();
36 DVLOG(2) << "Started mouse monitoring.";
41 void UserInputMonitor::RemoveMouseListener(MouseEventListener
* listener
) {
42 mouse_listeners_
->RemoveObserver(listener
);
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.";
54 void UserInputMonitor::EnableKeyPressMonitoring() {
55 base::AutoLock
auto_lock(lock_
);
56 ++key_press_counter_references_
;
57 if (key_press_counter_references_
== 1) {
58 StartKeyboardMonitoring();
59 DVLOG(2) << "Started keyboard monitoring.";
63 void UserInputMonitor::DisableKeyPressMonitoring() {
64 base::AutoLock
auto_lock(lock_
);
65 DCHECK_NE(key_press_counter_references_
, 0u);
66 --key_press_counter_references_
;
67 if (key_press_counter_references_
== 0) {
68 StopKeyboardMonitoring();
69 DVLOG(2) << "Stopped keyboard monitoring.";