Chromium Code Reviews| 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 <sys/select.h> | 7 #include <sys/select.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 #define XK_MISCELLANY | 9 #define XK_MISCELLANY |
| 10 #include <X11/keysymdef.h> | 10 #include <X11/keysymdef.h> |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 #include <X11/extensions/record.h> | 30 #include <X11/extensions/record.h> |
| 31 | 31 |
| 32 namespace media { | 32 namespace media { |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 class UserInputMonitorLinux : public UserInputMonitor , | 35 class UserInputMonitorLinux : public UserInputMonitor , |
| 36 public base::MessagePumpLibevent::Watcher { | 36 public base::MessagePumpLibevent::Watcher { |
| 37 public: | 37 public: |
| 38 explicit UserInputMonitorLinux( | 38 explicit UserInputMonitorLinux( |
| 39 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | 39 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 40 virtual ~UserInputMonitorLinux(); | |
| 41 | |
| 42 virtual size_t GetKeyPressCount() const OVERRIDE; | 40 virtual size_t GetKeyPressCount() const OVERRIDE; |
| 43 | 41 |
| 44 private: | 42 private: |
| 45 enum EventType { | 43 enum EventType { |
| 46 MOUSE_EVENT, | 44 MOUSE_EVENT, |
| 47 KEYBOARD_EVENT | 45 KEYBOARD_EVENT |
| 48 }; | 46 }; |
| 49 | 47 |
| 48 virtual ~UserInputMonitorLinux(); | |
| 49 | |
| 50 virtual void StartMouseMonitoring() OVERRIDE; | 50 virtual void StartMouseMonitoring() OVERRIDE; |
| 51 virtual void StopMouseMonitoring() OVERRIDE; | 51 virtual void StopMouseMonitoring() OVERRIDE; |
| 52 virtual void StartKeyboardMonitoring() OVERRIDE; | 52 virtual void StartKeyboardMonitoring() OVERRIDE; |
| 53 virtual void StopKeyboardMonitoring() OVERRIDE; | 53 virtual void StopKeyboardMonitoring() OVERRIDE; |
| 54 | 54 |
| 55 // | 55 // |
| 56 // The following methods must be called on the IO thread. | 56 // The following methods must be called on the IO thread. |
| 57 // | 57 // |
| 58 void StartMonitor(EventType type); | 58 void StartMonitor(EventType type); |
| 59 void StopMonitor(EventType type); | 59 void StopMonitor(EventType type); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 } | 101 } |
| 102 | 102 |
| 103 size_t UserInputMonitorLinux::GetKeyPressCount() const { | 103 size_t UserInputMonitorLinux::GetKeyPressCount() const { |
| 104 return counter_.GetKeyPressCount(); | 104 return counter_.GetKeyPressCount(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void UserInputMonitorLinux::StartMouseMonitoring() { | 107 void UserInputMonitorLinux::StartMouseMonitoring() { |
| 108 if (!io_task_runner_->BelongsToCurrentThread()) { | 108 if (!io_task_runner_->BelongsToCurrentThread()) { |
| 109 io_task_runner_->PostTask( | 109 io_task_runner_->PostTask( |
| 110 FROM_HERE, | 110 FROM_HERE, |
| 111 base::Bind(&UserInputMonitorLinux::StartMonitor, | 111 base::Bind(&UserInputMonitorLinux::StartMouseMonitoring, this)); |
| 112 base::Unretained(this), | |
| 113 MOUSE_EVENT)); | |
| 114 return; | 112 return; |
| 115 } | 113 } |
| 116 StartMonitor(MOUSE_EVENT); | 114 StartMonitor(MOUSE_EVENT); |
| 117 } | 115 } |
| 118 | 116 |
| 119 void UserInputMonitorLinux::StopMouseMonitoring() { | 117 void UserInputMonitorLinux::StopMouseMonitoring() { |
| 120 if (!io_task_runner_->BelongsToCurrentThread()) { | 118 if (!io_task_runner_->BelongsToCurrentThread()) { |
| 121 io_task_runner_->PostTask( | 119 io_task_runner_->PostTask( |
| 122 FROM_HERE, | 120 FROM_HERE, |
| 123 base::Bind(&UserInputMonitorLinux::StopMonitor, | 121 base::Bind(&UserInputMonitorLinux::StopMouseMonitoring, this)); |
| 124 base::Unretained(this), | |
| 125 MOUSE_EVENT)); | |
| 126 return; | 122 return; |
| 127 } | 123 } |
| 128 StopMonitor(MOUSE_EVENT); | 124 StopMonitor(MOUSE_EVENT); |
| 129 } | 125 } |
| 130 | 126 |
| 131 void UserInputMonitorLinux::StartKeyboardMonitoring() { | 127 void UserInputMonitorLinux::StartKeyboardMonitoring() { |
| 132 if (!io_task_runner_->BelongsToCurrentThread()) { | 128 if (!io_task_runner_->BelongsToCurrentThread()) { |
| 133 io_task_runner_->PostTask( | 129 io_task_runner_->PostTask( |
| 134 FROM_HERE, | 130 FROM_HERE, |
| 135 base::Bind(&UserInputMonitorLinux::StartMonitor, | 131 base::Bind(&UserInputMonitorLinux::StartKeyboardMonitoring, this)); |
| 136 base::Unretained(this), | |
| 137 KEYBOARD_EVENT)); | |
| 138 return; | 132 return; |
| 139 } | 133 } |
| 140 StartMonitor(KEYBOARD_EVENT); | 134 StartMonitor(KEYBOARD_EVENT); |
| 141 } | 135 } |
| 142 | 136 |
| 143 void UserInputMonitorLinux::StopKeyboardMonitoring() { | 137 void UserInputMonitorLinux::StopKeyboardMonitoring() { |
| 144 if (!io_task_runner_->BelongsToCurrentThread()) { | 138 if (!io_task_runner_->BelongsToCurrentThread()) { |
|
Sergey Ulanov
2013/09/04 18:40:09
There is potential race between StartKeyboardMonit
jiayl
2013/09/05 00:29:38
If the same caller calls Start and Stop on differe
Sergey Ulanov
2013/09/07 20:19:41
It might not be the same caller. One object may b
jiayl
2013/09/10 16:31:00
Done.
| |
| 145 io_task_runner_->PostTask( | 139 io_task_runner_->PostTask( |
| 146 FROM_HERE, | 140 FROM_HERE, |
| 147 base::Bind(&UserInputMonitorLinux::StopMonitor, | 141 base::Bind(&UserInputMonitorLinux::StopKeyboardMonitoring, this)); |
| 148 base::Unretained(this), | |
| 149 KEYBOARD_EVENT)); | |
| 150 return; | 142 return; |
| 151 } | 143 } |
| 152 StopMonitor(KEYBOARD_EVENT); | 144 StopMonitor(KEYBOARD_EVENT); |
| 153 } | 145 } |
| 154 | 146 |
| 155 void UserInputMonitorLinux::StartMonitor(EventType type) { | 147 void UserInputMonitorLinux::StartMonitor(EventType type) { |
| 156 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 148 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 157 | 149 |
| 158 if (type == KEYBOARD_EVENT) | 150 if (type == KEYBOARD_EVENT) |
| 159 counter_.Reset(); | 151 counter_.Reset(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 XRecordInterceptData* data) { | 311 XRecordInterceptData* data) { |
| 320 if (data->category == XRecordFromServer) { | 312 if (data->category == XRecordFromServer) { |
| 321 xEvent* event = reinterpret_cast<xEvent*>(data->data); | 313 xEvent* event = reinterpret_cast<xEvent*>(data->data); |
| 322 reinterpret_cast<UserInputMonitorLinux*>(self)->ProcessXEvent(event); | 314 reinterpret_cast<UserInputMonitorLinux*>(self)->ProcessXEvent(event); |
| 323 } | 315 } |
| 324 XRecordFreeData(data); | 316 XRecordFreeData(data); |
| 325 } | 317 } |
| 326 | 318 |
| 327 } // namespace | 319 } // namespace |
| 328 | 320 |
| 329 scoped_ptr<UserInputMonitor> UserInputMonitor::Create( | 321 scoped_refptr<UserInputMonitor> UserInputMonitor::Create( |
| 330 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 322 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 331 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { | 323 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { |
| 332 return scoped_ptr<UserInputMonitor>( | 324 return scoped_refptr<UserInputMonitor>( |
| 333 new UserInputMonitorLinux(io_task_runner)); | 325 new UserInputMonitorLinux(io_task_runner)); |
| 334 } | 326 } |
| 335 | 327 |
| 336 } // namespace media | 328 } // namespace media |
| OLD | NEW |