• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "media/base/user_input_monitor.h"
6 
7 #include "base/logging.h"
8 #include "third_party/skia/include/core/SkPoint.h"
9 
10 namespace media {
11 
12 #ifdef DISABLE_USER_INPUT_MONITOR
Create(const scoped_refptr<base::SingleThreadTaskRunner> & io_task_runner,const scoped_refptr<base::SingleThreadTaskRunner> & ui_task_runner)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>();
17 }
18 #endif  // DISABLE_USER_INPUT_MONITOR
19 
UserInputMonitor()20 UserInputMonitor::UserInputMonitor()
21     : key_press_counter_references_(0),
22       mouse_listeners_count_(0),
23       mouse_listeners_(new MouseListenerList()) {}
24 
~UserInputMonitor()25 UserInputMonitor::~UserInputMonitor() {
26   DCHECK_EQ(0u, key_press_counter_references_);
27   mouse_listeners_->AssertEmpty();
28 }
29 
AddMouseListener(MouseEventListener * listener)30 void UserInputMonitor::AddMouseListener(MouseEventListener* listener) {
31   mouse_listeners_->AddObserver(listener);
32   {
33     base::AutoLock auto_lock(lock_);
34     mouse_listeners_count_++;
35     if (mouse_listeners_count_ == 1) {
36       StartMouseMonitoring();
37       DVLOG(2) << "Started mouse monitoring.";
38     }
39   }
40 }
41 
RemoveMouseListener(MouseEventListener * listener)42 void UserInputMonitor::RemoveMouseListener(MouseEventListener* listener) {
43   mouse_listeners_->RemoveObserver(listener);
44   {
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.";
51     }
52   }
53 }
54 
EnableKeyPressMonitoring()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.";
61   }
62 }
63 
DisableKeyPressMonitoring()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.";
71   }
72 }
73 
74 }  // namespace media
75