| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/weak_ptr.h" |
| 18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 19 #include "base/message_loop/message_pump_libevent.h" | 20 #include "base/message_loop/message_pump_libevent.h" |
| 21 #include "base/observer_list_threadsafe.h" |
| 20 #include "base/posix/eintr_wrapper.h" | 22 #include "base/posix/eintr_wrapper.h" |
| 21 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 24 #include "base/synchronization/lock.h" |
| 22 #include "media/base/keyboard_event_counter.h" | 25 #include "media/base/keyboard_event_counter.h" |
| 23 #include "third_party/skia/include/core/SkPoint.h" | 26 #include "third_party/skia/include/core/SkPoint.h" |
| 24 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 27 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
| 25 | 28 |
| 26 // These includes need to be later than dictated by the style guide due to | 29 // These includes need to be later than dictated by the style guide due to |
| 27 // Xlib header pollution, specifically the min, max, and Status macros. | 30 // Xlib header pollution, specifically the min, max, and Status macros. |
| 28 #include <X11/XKBlib.h> | 31 #include <X11/XKBlib.h> |
| 29 #include <X11/Xlibint.h> | 32 #include <X11/Xlibint.h> |
| 30 #include <X11/extensions/record.h> | 33 #include <X11/extensions/record.h> |
| 31 | 34 |
| 32 namespace media { | 35 namespace media { |
| 33 namespace { | 36 namespace { |
| 34 | 37 |
| 35 class UserInputMonitorLinux : public UserInputMonitor , | 38 class UserInputMonitorLinux : public UserInputMonitor { |
| 36 public base::MessagePumpLibevent::Watcher { | |
| 37 public: | 39 public: |
| 38 explicit UserInputMonitorLinux( | 40 explicit UserInputMonitorLinux( |
| 39 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | 41 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 40 virtual ~UserInputMonitorLinux(); | 42 virtual ~UserInputMonitorLinux(); |
| 41 | 43 |
| 44 // Public interface of UserInputMonitor. |
| 45 virtual void AddMouseListener(MouseEventListener* listener) OVERRIDE; |
| 46 virtual void RemoveMouseListener(MouseEventListener* listener) OVERRIDE; |
| 42 virtual size_t GetKeyPressCount() const OVERRIDE; | 47 virtual size_t GetKeyPressCount() const OVERRIDE; |
| 43 | 48 |
| 44 private: | 49 private: |
| 50 // Private interface of UserInputMonitor. |
| 51 virtual void StartKeyboardMonitoring() OVERRIDE; |
| 52 virtual void StopKeyboardMonitoring() OVERRIDE; |
| 53 |
| 54 class Core; |
| 55 Core* core_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(UserInputMonitorLinux); |
| 58 }; |
| 59 |
| 60 // This is the actual implementation of event monitoring. It's separated from |
| 61 // UserInputMonitorLinux since it needs to be deleted on the IO thread. |
| 62 class UserInputMonitorLinux::Core : public base::MessagePumpLibevent::Watcher { |
| 63 public: |
| 64 explicit Core( |
| 65 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 66 virtual ~Core(); |
| 67 |
| 68 void AddMouseListener(MouseEventListener* listener); |
| 69 void RemoveMouseListener(MouseEventListener* listener); |
| 70 size_t GetKeyPressCount() const; |
| 71 void StartKeyboardMonitoring(); |
| 72 void StopKeyboardMonitoring(); |
| 73 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() { |
| 74 return io_task_runner_; |
| 75 } |
| 76 |
| 77 private: |
| 45 enum EventType { | 78 enum EventType { |
| 46 MOUSE_EVENT, | 79 MOUSE_EVENT, |
| 47 KEYBOARD_EVENT | 80 KEYBOARD_EVENT |
| 48 }; | 81 }; |
| 49 | 82 |
| 50 virtual void StartMouseMonitoring() OVERRIDE; | |
| 51 virtual void StopMouseMonitoring() OVERRIDE; | |
| 52 virtual void StartKeyboardMonitoring() OVERRIDE; | |
| 53 virtual void StopKeyboardMonitoring() OVERRIDE; | |
| 54 | |
| 55 // | |
| 56 // The following methods must be called on the IO thread. | |
| 57 // | |
| 58 void StartMonitor(EventType type); | 83 void StartMonitor(EventType type); |
| 59 void StopMonitor(EventType type); | 84 void StopMonitor(EventType type); |
| 60 | 85 |
| 61 // base::MessagePumpLibevent::Watcher interface. | 86 // base::MessagePumpLibevent::Watcher interface. |
| 62 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | 87 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| 63 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | 88 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
| 64 | 89 |
| 65 // Processes key and mouse events. | 90 // Processes key and mouse events. |
| 66 void ProcessXEvent(xEvent* event); | 91 void ProcessXEvent(xEvent* event); |
| 67 static void ProcessReply(XPointer self, XRecordInterceptData* data); | 92 static void ProcessReply(XPointer self, XRecordInterceptData* data); |
| 68 | 93 |
| 69 // Task runner on which X Window events are received. | 94 base::Lock lock_; |
| 70 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 95 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 96 scoped_refptr<ObserverListThreadSafe<MouseEventListener> > mouse_listeners_; |
| 97 size_t mouse_listeners_count_; |
| 71 | 98 |
| 72 // | 99 // |
| 73 // The following members should only be accessed on the IO thread. | 100 // The following members should only be accessed on the IO thread. |
| 74 // | 101 // |
| 75 base::MessagePumpLibevent::FileDescriptorWatcher controller_; | 102 base::MessagePumpLibevent::FileDescriptorWatcher controller_; |
| 76 Display* display_; | 103 Display* display_; |
| 77 Display* x_record_display_; | 104 Display* x_record_display_; |
| 78 XRecordRange* x_record_range_[2]; | 105 XRecordRange* x_record_range_[2]; |
| 79 XRecordContext x_record_context_; | 106 XRecordContext x_record_context_; |
| 80 KeyboardEventCounter counter_; | 107 KeyboardEventCounter counter_; |
| 108 base::WeakPtrFactory<Core> weak_factory_; |
| 81 | 109 |
| 82 DISALLOW_COPY_AND_ASSIGN(UserInputMonitorLinux); | 110 DISALLOW_COPY_AND_ASSIGN(Core); |
| 83 }; | 111 }; |
| 84 | 112 |
| 85 UserInputMonitorLinux::UserInputMonitorLinux( | 113 UserInputMonitorLinux::Core::Core( |
| 86 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 114 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
| 87 : io_task_runner_(io_task_runner), | 115 : io_task_runner_(io_task_runner), |
| 116 mouse_listeners_(new ObserverListThreadSafe<MouseEventListener>()), |
| 117 mouse_listeners_count_(0), |
| 88 display_(NULL), | 118 display_(NULL), |
| 89 x_record_display_(NULL), | 119 x_record_display_(NULL), |
| 90 x_record_context_(0) { | 120 x_record_context_(0), |
| 121 weak_factory_(this) { |
| 91 x_record_range_[0] = NULL; | 122 x_record_range_[0] = NULL; |
| 92 x_record_range_[1] = NULL; | 123 x_record_range_[1] = NULL; |
| 93 } | 124 } |
| 94 | 125 |
| 95 UserInputMonitorLinux::~UserInputMonitorLinux() { | 126 UserInputMonitorLinux::Core::~Core() { |
| 127 DCHECK_EQ(0u, mouse_listeners_count_); |
| 96 DCHECK(!display_); | 128 DCHECK(!display_); |
| 97 DCHECK(!x_record_display_); | 129 DCHECK(!x_record_display_); |
| 98 DCHECK(!x_record_range_[0]); | 130 DCHECK(!x_record_range_[0]); |
| 99 DCHECK(!x_record_range_[1]); | 131 DCHECK(!x_record_range_[1]); |
| 100 DCHECK(!x_record_context_); | 132 DCHECK(!x_record_context_); |
| 101 } | 133 } |
| 102 | 134 |
| 103 size_t UserInputMonitorLinux::GetKeyPressCount() const { | 135 void UserInputMonitorLinux::Core::AddMouseListener( |
| 136 MouseEventListener* listener) { |
| 137 mouse_listeners_->AddObserver(listener); |
| 138 { |
| 139 base::AutoLock auto_lock(lock_); |
| 140 mouse_listeners_count_++; |
| 141 if (mouse_listeners_count_ == 1) { |
| 142 io_task_runner_->PostTask( |
| 143 FROM_HERE, |
| 144 base::Bind( |
| 145 &Core::StartMonitor, weak_factory_.GetWeakPtr(), MOUSE_EVENT)); |
| 146 DVLOG(2) << "Started mouse monitoring."; |
| 147 } |
| 148 } |
| 149 } |
| 150 |
| 151 void UserInputMonitorLinux::Core::RemoveMouseListener( |
| 152 MouseEventListener* listener) { |
| 153 mouse_listeners_->RemoveObserver(listener); |
| 154 { |
| 155 base::AutoLock auto_lock(lock_); |
| 156 mouse_listeners_count_--; |
| 157 if (mouse_listeners_count_ == 0) { |
| 158 io_task_runner_->PostTask( |
| 159 FROM_HERE, |
| 160 base::Bind( |
| 161 &Core::StopMonitor, weak_factory_.GetWeakPtr(), MOUSE_EVENT)); |
| 162 DVLOG(2) << "Stopped mouse monitoring."; |
| 163 } |
| 164 } |
| 165 } |
| 166 |
| 167 size_t UserInputMonitorLinux::Core::GetKeyPressCount() const { |
| 104 return counter_.GetKeyPressCount(); | 168 return counter_.GetKeyPressCount(); |
| 105 } | 169 } |
| 106 | 170 |
| 107 void UserInputMonitorLinux::StartMouseMonitoring() { | 171 void UserInputMonitorLinux::Core::StartKeyboardMonitoring() { |
| 108 if (!io_task_runner_->BelongsToCurrentThread()) { | 172 io_task_runner_->PostTask( |
| 109 io_task_runner_->PostTask( | 173 FROM_HERE, |
| 110 FROM_HERE, | 174 base::Bind( |
| 111 base::Bind(&UserInputMonitorLinux::StartMonitor, | 175 &Core::StartMonitor, weak_factory_.GetWeakPtr(), KEYBOARD_EVENT)); |
| 112 base::Unretained(this), | |
| 113 MOUSE_EVENT)); | |
| 114 return; | |
| 115 } | |
| 116 StartMonitor(MOUSE_EVENT); | |
| 117 } | 176 } |
| 118 | 177 |
| 119 void UserInputMonitorLinux::StopMouseMonitoring() { | 178 void UserInputMonitorLinux::Core::StopKeyboardMonitoring() { |
| 120 if (!io_task_runner_->BelongsToCurrentThread()) { | 179 io_task_runner_->PostTask( |
| 121 io_task_runner_->PostTask( | 180 FROM_HERE, |
| 122 FROM_HERE, | 181 base::Bind( |
| 123 base::Bind(&UserInputMonitorLinux::StopMonitor, | 182 &Core::StopMonitor, weak_factory_.GetWeakPtr(), KEYBOARD_EVENT)); |
| 124 base::Unretained(this), | |
| 125 MOUSE_EVENT)); | |
| 126 return; | |
| 127 } | |
| 128 StopMonitor(MOUSE_EVENT); | |
| 129 } | 183 } |
| 130 | 184 |
| 131 void UserInputMonitorLinux::StartKeyboardMonitoring() { | 185 void UserInputMonitorLinux::Core::StartMonitor(EventType type) { |
| 132 if (!io_task_runner_->BelongsToCurrentThread()) { | |
| 133 io_task_runner_->PostTask( | |
| 134 FROM_HERE, | |
| 135 base::Bind(&UserInputMonitorLinux::StartMonitor, | |
| 136 base::Unretained(this), | |
| 137 KEYBOARD_EVENT)); | |
| 138 return; | |
| 139 } | |
| 140 StartMonitor(KEYBOARD_EVENT); | |
| 141 } | |
| 142 | |
| 143 void UserInputMonitorLinux::StopKeyboardMonitoring() { | |
| 144 if (!io_task_runner_->BelongsToCurrentThread()) { | |
| 145 io_task_runner_->PostTask( | |
| 146 FROM_HERE, | |
| 147 base::Bind(&UserInputMonitorLinux::StopMonitor, | |
| 148 base::Unretained(this), | |
| 149 KEYBOARD_EVENT)); | |
| 150 return; | |
| 151 } | |
| 152 StopMonitor(KEYBOARD_EVENT); | |
| 153 } | |
| 154 | |
| 155 void UserInputMonitorLinux::StartMonitor(EventType type) { | |
| 156 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 186 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 157 | 187 |
| 158 if (type == KEYBOARD_EVENT) | 188 if (type == KEYBOARD_EVENT) |
| 159 counter_.Reset(); | 189 counter_.Reset(); |
| 160 | 190 |
| 161 // TODO(jamiewalch): We should pass the display in. At that point, since | 191 // TODO(jamiewalch): We should pass the display in. At that point, since |
| 162 // XRecord needs a private connection to the X Server for its data channel | 192 // XRecord needs a private connection to the X Server for its data channel |
| 163 // and both channels are used from a separate thread, we'll need to duplicate | 193 // and both channels are used from a separate thread, we'll need to duplicate |
| 164 // them with something like the following: | 194 // them with something like the following: |
| 165 // XOpenDisplay(DisplayString(display)); | 195 // XOpenDisplay(DisplayString(display)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 1, | 245 1, |
| 216 record_range_to_use, | 246 record_range_to_use, |
| 217 number_of_ranges); | 247 number_of_ranges); |
| 218 if (!x_record_context_) { | 248 if (!x_record_context_) { |
| 219 LOG(ERROR) << "XRecordCreateContext failed."; | 249 LOG(ERROR) << "XRecordCreateContext failed."; |
| 220 return; | 250 return; |
| 221 } | 251 } |
| 222 | 252 |
| 223 if (!XRecordEnableContextAsync(x_record_display_, | 253 if (!XRecordEnableContextAsync(x_record_display_, |
| 224 x_record_context_, | 254 x_record_context_, |
| 225 &UserInputMonitorLinux::ProcessReply, | 255 &Core::ProcessReply, |
| 226 reinterpret_cast<XPointer>(this))) { | 256 reinterpret_cast<XPointer>(this))) { |
| 227 LOG(ERROR) << "XRecordEnableContextAsync failed."; | 257 LOG(ERROR) << "XRecordEnableContextAsync failed."; |
| 228 return; | 258 return; |
| 229 } | 259 } |
| 230 | 260 |
| 231 if (!x_record_range_[0] || !x_record_range_[1]) { | 261 if (!x_record_range_[0] || !x_record_range_[1]) { |
| 232 // Register OnFileCanReadWithoutBlocking() to be called every time there is | 262 // Register OnFileCanReadWithoutBlocking() to be called every time there is |
| 233 // something to read from |x_record_display_|. | 263 // something to read from |x_record_display_|. |
| 234 base::MessageLoopForIO* message_loop = base::MessageLoopForIO::current(); | 264 base::MessageLoopForIO* message_loop = base::MessageLoopForIO::current(); |
| 235 int result = | 265 int result = |
| 236 message_loop->WatchFileDescriptor(ConnectionNumber(x_record_display_), | 266 message_loop->WatchFileDescriptor(ConnectionNumber(x_record_display_), |
| 237 true, | 267 true, |
| 238 base::MessageLoopForIO::WATCH_READ, | 268 base::MessageLoopForIO::WATCH_READ, |
| 239 &controller_, | 269 &controller_, |
| 240 this); | 270 this); |
| 241 if (!result) { | 271 if (!result) { |
| 242 LOG(ERROR) << "Failed to create X record task."; | 272 LOG(ERROR) << "Failed to create X record task."; |
| 243 return; | 273 return; |
| 244 } | 274 } |
| 245 } | 275 } |
| 246 | 276 |
| 247 // Fetch pending events if any. | 277 // Fetch pending events if any. |
| 248 OnFileCanReadWithoutBlocking(ConnectionNumber(x_record_display_)); | 278 OnFileCanReadWithoutBlocking(ConnectionNumber(x_record_display_)); |
| 249 } | 279 } |
| 250 | 280 |
| 251 void UserInputMonitorLinux::StopMonitor(EventType type) { | 281 void UserInputMonitorLinux::Core::StopMonitor(EventType type) { |
| 252 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 282 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 253 | 283 |
| 254 if (x_record_range_[type]) { | 284 if (x_record_range_[type]) { |
| 255 XFree(x_record_range_[type]); | 285 XFree(x_record_range_[type]); |
| 256 x_record_range_[type] = NULL; | 286 x_record_range_[type] = NULL; |
| 257 } | 287 } |
| 258 if (x_record_range_[0] || x_record_range_[1]) | 288 if (x_record_range_[0] || x_record_range_[1]) |
| 259 return; | 289 return; |
| 260 | 290 |
| 261 // Context must be disabled via the control channel because we can't send | 291 // Context must be disabled via the control channel because we can't send |
| 262 // any X protocol traffic over the data channel while it's recording. | 292 // any X protocol traffic over the data channel while it's recording. |
| 263 if (x_record_context_) { | 293 if (x_record_context_) { |
| 264 XRecordDisableContext(display_, x_record_context_); | 294 XRecordDisableContext(display_, x_record_context_); |
| 265 XFlush(display_); | 295 XFlush(display_); |
| 266 XRecordFreeContext(x_record_display_, x_record_context_); | 296 XRecordFreeContext(x_record_display_, x_record_context_); |
| 267 x_record_context_ = 0; | 297 x_record_context_ = 0; |
| 268 | 298 |
| 269 controller_.StopWatchingFileDescriptor(); | 299 controller_.StopWatchingFileDescriptor(); |
| 270 if (x_record_display_) { | 300 if (x_record_display_) { |
| 271 XCloseDisplay(x_record_display_); | 301 XCloseDisplay(x_record_display_); |
| 272 x_record_display_ = NULL; | 302 x_record_display_ = NULL; |
| 273 } | 303 } |
| 274 if (display_) { | 304 if (display_) { |
| 275 XCloseDisplay(display_); | 305 XCloseDisplay(display_); |
| 276 display_ = NULL; | 306 display_ = NULL; |
| 277 } | 307 } |
| 278 } | 308 } |
| 279 } | 309 } |
| 280 | 310 |
| 281 void UserInputMonitorLinux::OnFileCanReadWithoutBlocking(int fd) { | 311 void UserInputMonitorLinux::Core::OnFileCanReadWithoutBlocking(int fd) { |
| 282 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 312 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 283 XEvent event; | 313 XEvent event; |
| 284 // Fetch pending events if any. | 314 // Fetch pending events if any. |
| 285 while (XPending(x_record_display_)) { | 315 while (XPending(x_record_display_)) { |
| 286 XNextEvent(x_record_display_, &event); | 316 XNextEvent(x_record_display_, &event); |
| 287 } | 317 } |
| 288 } | 318 } |
| 289 | 319 |
| 290 void UserInputMonitorLinux::OnFileCanWriteWithoutBlocking(int fd) { | 320 void UserInputMonitorLinux::Core::OnFileCanWriteWithoutBlocking(int fd) { |
| 291 NOTREACHED(); | 321 NOTREACHED(); |
| 292 } | 322 } |
| 293 | 323 |
| 294 void UserInputMonitorLinux::ProcessXEvent(xEvent* event) { | 324 void UserInputMonitorLinux::Core::ProcessXEvent(xEvent* event) { |
| 295 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 325 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 296 if (event->u.u.type == MotionNotify) { | 326 if (event->u.u.type == MotionNotify) { |
| 297 SkIPoint position(SkIPoint::Make(event->u.keyButtonPointer.rootX, | 327 SkIPoint position(SkIPoint::Make(event->u.keyButtonPointer.rootX, |
| 298 event->u.keyButtonPointer.rootY)); | 328 event->u.keyButtonPointer.rootY)); |
| 299 OnMouseEvent(position); | 329 mouse_listeners_->Notify(&MouseEventListener::OnMouseMoved, position); |
| 300 } else { | 330 } else { |
| 301 ui::EventType type; | 331 ui::EventType type; |
| 302 if (event->u.u.type == KeyPress) { | 332 if (event->u.u.type == KeyPress) { |
| 303 type = ui::ET_KEY_PRESSED; | 333 type = ui::ET_KEY_PRESSED; |
| 304 } else if (event->u.u.type == KeyRelease) { | 334 } else if (event->u.u.type == KeyRelease) { |
| 305 type = ui::ET_KEY_RELEASED; | 335 type = ui::ET_KEY_RELEASED; |
| 306 } else { | 336 } else { |
| 307 NOTREACHED(); | 337 NOTREACHED(); |
| 308 return; | 338 return; |
| 309 } | 339 } |
| 310 | 340 |
| 311 KeySym key_sym = XkbKeycodeToKeysym(display_, event->u.u.detail, 0, 0); | 341 KeySym key_sym = XkbKeycodeToKeysym(display_, event->u.u.detail, 0, 0); |
| 312 ui::KeyboardCode key_code = ui::KeyboardCodeFromXKeysym(key_sym); | 342 ui::KeyboardCode key_code = ui::KeyboardCodeFromXKeysym(key_sym); |
| 313 counter_.OnKeyboardEvent(type, key_code); | 343 counter_.OnKeyboardEvent(type, key_code); |
| 314 } | 344 } |
| 315 } | 345 } |
| 316 | 346 |
| 317 // static | 347 // static |
| 318 void UserInputMonitorLinux::ProcessReply(XPointer self, | 348 void UserInputMonitorLinux::Core::ProcessReply(XPointer self, |
| 319 XRecordInterceptData* data) { | 349 XRecordInterceptData* data) { |
| 320 if (data->category == XRecordFromServer) { | 350 if (data->category == XRecordFromServer) { |
| 321 xEvent* event = reinterpret_cast<xEvent*>(data->data); | 351 xEvent* event = reinterpret_cast<xEvent*>(data->data); |
| 322 reinterpret_cast<UserInputMonitorLinux*>(self)->ProcessXEvent(event); | 352 reinterpret_cast<Core*>(self)->ProcessXEvent(event); |
| 323 } | 353 } |
| 324 XRecordFreeData(data); | 354 XRecordFreeData(data); |
| 325 } | 355 } |
| 326 | 356 |
| 357 // |
| 358 // Implementation of UserInputMonitorLinux. |
| 359 // |
| 360 |
| 361 UserInputMonitorLinux::UserInputMonitorLinux( |
| 362 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
| 363 : core_(new Core(io_task_runner)) {} |
| 364 |
| 365 UserInputMonitorLinux::~UserInputMonitorLinux() { |
| 366 if (!core_->io_task_runner()->DeleteSoon(FROM_HERE, core_)) |
| 367 delete core_; |
| 368 } |
| 369 |
| 370 void UserInputMonitorLinux::AddMouseListener(MouseEventListener* listener) { |
| 371 core_->AddMouseListener(listener); |
| 372 } |
| 373 |
| 374 void UserInputMonitorLinux::RemoveMouseListener(MouseEventListener* listener) { |
| 375 core_->RemoveMouseListener(listener); |
| 376 } |
| 377 |
| 378 size_t UserInputMonitorLinux::GetKeyPressCount() const { |
| 379 return core_->GetKeyPressCount(); |
| 380 } |
| 381 |
| 382 void UserInputMonitorLinux::StartKeyboardMonitoring() { |
| 383 core_->StartKeyboardMonitoring(); |
| 384 } |
| 385 |
| 386 void UserInputMonitorLinux::StopKeyboardMonitoring() { |
| 387 core_->StopKeyboardMonitoring(); |
| 388 } |
| 389 |
| 327 } // namespace | 390 } // namespace |
| 328 | 391 |
| 329 scoped_ptr<UserInputMonitor> UserInputMonitor::Create( | 392 scoped_ptr<UserInputMonitor> UserInputMonitor::Create( |
| 330 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 393 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 331 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { | 394 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { |
| 332 return scoped_ptr<UserInputMonitor>( | 395 return scoped_ptr<UserInputMonitor>( |
| 333 new UserInputMonitorLinux(io_task_runner)); | 396 new UserInputMonitorLinux(io_task_runner)); |
| 334 } | 397 } |
| 335 | 398 |
| 336 } // namespace media | 399 } // namespace media |
| OLD | NEW |