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"
8 #include "third_party/skia/include/core/SkPoint.h"
12 #ifdef DISABLE_USER_INPUT_MONITOR
13 scoped_ptr
<UserInputMonitor
> UserInputMonitor::Create(
14 const scoped_refptr
<base::SingleThreadTaskRunner
>& io_task_runner
,
15 const scoped_refptr
<base::SingleThreadTaskRunner
>& ui_task_runner
) {
16 return scoped_ptr
<UserInputMonitor
>();
18 #endif // DISABLE_USER_INPUT_MONITOR
20 UserInputMonitor::UserInputMonitor()
21 : key_press_counter_references_(0),
22 mouse_listeners_count_(0),
23 mouse_listeners_(new MouseListenerList()) {}
25 UserInputMonitor::~UserInputMonitor() {
26 DCHECK_EQ(0u, key_press_counter_references_
);
27 mouse_listeners_
->AssertEmpty();
30 void UserInputMonitor::AddMouseListener(MouseEventListener
* listener
) {
31 mouse_listeners_
->AddObserver(listener
);
33 base::AutoLock
auto_lock(lock_
);
34 mouse_listeners_count_
++;
35 if (mouse_listeners_count_
== 1) {
36 StartMouseMonitoring();
37 DVLOG(2) << "Started mouse monitoring.";
42 void UserInputMonitor::RemoveMouseListener(MouseEventListener
* listener
) {
43 mouse_listeners_
->RemoveObserver(listener
);
45 base::AutoLock
auto_lock(lock_
);
46 DCHECK_NE(mouse_listeners_count_
, 0u);
47 mouse_listeners_count_
--;
48 if (mouse_listeners_count_
== 0) {
49 StopMouseMonitoring();
50 DVLOG(2) << "Stopped mouse monitoring.";
55 void UserInputMonitor::EnableKeyPressMonitoring() {
56 base::AutoLock
auto_lock(lock_
);
57 ++key_press_counter_references_
;
58 if (key_press_counter_references_
== 1) {
59 StartKeyboardMonitoring();
60 DVLOG(2) << "Started keyboard monitoring.";
64 void UserInputMonitor::DisableKeyPressMonitoring() {
65 base::AutoLock
auto_lock(lock_
);
66 DCHECK_NE(key_press_counter_references_
, 0u);
67 --key_press_counter_references_
;
68 if (key_press_counter_references_
== 0) {
69 StopKeyboardMonitoring();
70 DVLOG(2) << "Stopped keyboard monitoring.";