Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: media/base/user_input_monitor_linux.cc

Issue 23702008: Adds the UserInputMonitor implementation for Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
20 #include "base/posix/eintr_wrapper.h" 21 #include "base/posix/eintr_wrapper.h"
21 #include "base/single_thread_task_runner.h" 22 #include "base/single_thread_task_runner.h"
23 #include "base/synchronization/lock.h"
22 #include "media/base/keyboard_event_counter.h" 24 #include "media/base/keyboard_event_counter.h"
23 #include "third_party/skia/include/core/SkPoint.h" 25 #include "third_party/skia/include/core/SkPoint.h"
24 #include "ui/base/keycodes/keyboard_code_conversion_x.h" 26 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
25 27
26 // These includes need to be later than dictated by the style guide due to 28 // 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. 29 // Xlib header pollution, specifically the min, max, and Status macros.
28 #include <X11/XKBlib.h> 30 #include <X11/XKBlib.h>
29 #include <X11/Xlibint.h> 31 #include <X11/Xlibint.h>
30 #include <X11/extensions/record.h> 32 #include <X11/extensions/record.h>
31 33
32 namespace media { 34 namespace media {
33 namespace { 35 namespace {
34 36
35 class UserInputMonitorLinux : public UserInputMonitor , 37 // This is the actual implementation of event monitoring. It's separated from
36 public base::MessagePumpLibevent::Watcher { 38 // UserInputMonitorLinux since it needs to be deleted on the IO thread.
39 class UserInputMonitorLinuxCore
40 : public base::MessagePumpLibevent::Watcher,
41 public base::SupportsWeakPtr<UserInputMonitorLinuxCore> {
Wez 2013/09/13 10:01:27 You have to be careful using SupportsWeakPtr - Wea
jiayl 2013/09/13 16:23:33 I don't think WeakPtrFactory in UserInputMonitorLi
37 public: 42 public:
38 explicit UserInputMonitorLinux(
39 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
40 virtual ~UserInputMonitorLinux();
41
42 virtual size_t GetKeyPressCount() const OVERRIDE;
43
44 private:
45 enum EventType { 43 enum EventType {
46 MOUSE_EVENT, 44 MOUSE_EVENT,
47 KEYBOARD_EVENT 45 KEYBOARD_EVENT
48 }; 46 };
49 47
50 virtual void StartMouseMonitoring() OVERRIDE; 48 explicit UserInputMonitorLinuxCore(
51 virtual void StopMouseMonitoring() OVERRIDE; 49 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
52 virtual void StartKeyboardMonitoring() OVERRIDE; 50 const scoped_refptr<UserInputMonitor::MouseListenerList>&
53 virtual void StopKeyboardMonitoring() OVERRIDE; 51 mouse_listeners);
52 virtual ~UserInputMonitorLinuxCore();
54 53
55 // 54 size_t GetKeyPressCount() const;
56 // The following methods must be called on the IO thread.
57 //
58 void StartMonitor(EventType type); 55 void StartMonitor(EventType type);
59 void StopMonitor(EventType type); 56 void StopMonitor(EventType type);
60 57
58 private:
61 // base::MessagePumpLibevent::Watcher interface. 59 // base::MessagePumpLibevent::Watcher interface.
62 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; 60 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
63 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; 61 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
64 62
65 // Processes key and mouse events. 63 // Processes key and mouse events.
66 void ProcessXEvent(xEvent* event); 64 void ProcessXEvent(xEvent* event);
67 static void ProcessReply(XPointer self, XRecordInterceptData* data); 65 static void ProcessReply(XPointer self, XRecordInterceptData* data);
68 66
69 // Task runner on which X Window events are received.
70 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 67 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
68 scoped_refptr<ObserverListThreadSafe<UserInputMonitor::MouseEventListener> >
69 mouse_listeners_;
71 70
72 // 71 //
73 // The following members should only be accessed on the IO thread. 72 // The following members should only be accessed on the IO thread.
74 // 73 //
75 base::MessagePumpLibevent::FileDescriptorWatcher controller_; 74 base::MessagePumpLibevent::FileDescriptorWatcher controller_;
76 Display* display_; 75 Display* x_control_display_;
77 Display* x_record_display_; 76 Display* x_record_display_;
78 XRecordRange* x_record_range_[2]; 77 XRecordRange* x_record_range_[2];
79 XRecordContext x_record_context_; 78 XRecordContext x_record_context_;
80 KeyboardEventCounter counter_; 79 KeyboardEventCounter counter_;
81 80
81 DISALLOW_COPY_AND_ASSIGN(UserInputMonitorLinuxCore);
82 };
83
84 class UserInputMonitorLinux : public UserInputMonitor {
85 public:
86 explicit UserInputMonitorLinux(
87 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
88 virtual ~UserInputMonitorLinux();
89
90 // Public UserInputMonitor overrides.
91 virtual size_t GetKeyPressCount() const OVERRIDE;
92
93 private:
94 // Private UserInputMonitor overrides.
95 virtual void StartKeyboardMonitoring() OVERRIDE;
96 virtual void StopKeyboardMonitoring() OVERRIDE;
97 virtual void StartMouseMonitoring() OVERRIDE;
98 virtual void StopMouseMonitoring() OVERRIDE;
99
100 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
101 UserInputMonitorLinuxCore* core_;
102
82 DISALLOW_COPY_AND_ASSIGN(UserInputMonitorLinux); 103 DISALLOW_COPY_AND_ASSIGN(UserInputMonitorLinux);
83 }; 104 };
84 105
85 UserInputMonitorLinux::UserInputMonitorLinux( 106 UserInputMonitorLinuxCore::UserInputMonitorLinuxCore(
86 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) 107 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
108 const scoped_refptr<UserInputMonitor::MouseListenerList>& mouse_listeners)
87 : io_task_runner_(io_task_runner), 109 : io_task_runner_(io_task_runner),
88 display_(NULL), 110 mouse_listeners_(mouse_listeners),
111 x_control_display_(NULL),
89 x_record_display_(NULL), 112 x_record_display_(NULL),
90 x_record_context_(0) { 113 x_record_context_(0) {
91 x_record_range_[0] = NULL; 114 x_record_range_[0] = NULL;
92 x_record_range_[1] = NULL; 115 x_record_range_[1] = NULL;
93 } 116 }
94 117
95 UserInputMonitorLinux::~UserInputMonitorLinux() { 118 UserInputMonitorLinuxCore::~UserInputMonitorLinuxCore() {
96 DCHECK(!display_); 119 DCHECK(!x_control_display_);
97 DCHECK(!x_record_display_); 120 DCHECK(!x_record_display_);
98 DCHECK(!x_record_range_[0]); 121 DCHECK(!x_record_range_[0]);
99 DCHECK(!x_record_range_[1]); 122 DCHECK(!x_record_range_[1]);
100 DCHECK(!x_record_context_); 123 DCHECK(!x_record_context_);
101 } 124 }
102 125
103 size_t UserInputMonitorLinux::GetKeyPressCount() const { 126 size_t UserInputMonitorLinuxCore::GetKeyPressCount() const {
104 return counter_.GetKeyPressCount(); 127 return counter_.GetKeyPressCount();
105 } 128 }
106 129
107 void UserInputMonitorLinux::StartMouseMonitoring() { 130 void UserInputMonitorLinuxCore::StartMonitor(EventType type) {
108 if (!io_task_runner_->BelongsToCurrentThread()) {
109 io_task_runner_->PostTask(
110 FROM_HERE,
111 base::Bind(&UserInputMonitorLinux::StartMonitor,
112 base::Unretained(this),
113 MOUSE_EVENT));
114 return;
115 }
116 StartMonitor(MOUSE_EVENT);
117 }
118
119 void UserInputMonitorLinux::StopMouseMonitoring() {
120 if (!io_task_runner_->BelongsToCurrentThread()) {
121 io_task_runner_->PostTask(
122 FROM_HERE,
123 base::Bind(&UserInputMonitorLinux::StopMonitor,
124 base::Unretained(this),
125 MOUSE_EVENT));
126 return;
127 }
128 StopMonitor(MOUSE_EVENT);
129 }
130
131 void UserInputMonitorLinux::StartKeyboardMonitoring() {
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()); 131 DCHECK(io_task_runner_->BelongsToCurrentThread());
157 132
158 if (type == KEYBOARD_EVENT) 133 if (type == KEYBOARD_EVENT)
159 counter_.Reset(); 134 counter_.Reset();
160 135
161 // TODO(jamiewalch): We should pass the display in. At that point, since 136 // 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 137 // 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 138 // and both channels are used from a separate thread, we'll need to duplicate
164 // them with something like the following: 139 // them with something like the following:
165 // XOpenDisplay(DisplayString(display)); 140 // XOpenDisplay(DisplayString(display));
166 if (!display_) 141 if (!x_control_display_)
167 display_ = XOpenDisplay(NULL); 142 x_control_display_ = XOpenDisplay(NULL);
168 143
169 if (!x_record_display_) 144 if (!x_record_display_)
170 x_record_display_ = XOpenDisplay(NULL); 145 x_record_display_ = XOpenDisplay(NULL);
171 146
172 if (!display_ || !x_record_display_) { 147 if (!x_control_display_ || !x_record_display_) {
173 LOG(ERROR) << "Couldn't open X display"; 148 LOG(ERROR) << "Couldn't open X display";
174 return; 149 return;
175 } 150 }
176 151
177 int xr_opcode, xr_event, xr_error; 152 int xr_opcode, xr_event, xr_error;
178 if (!XQueryExtension(display_, "RECORD", &xr_opcode, &xr_event, &xr_error)) { 153 if (!XQueryExtension(
154 x_control_display_, "RECORD", &xr_opcode, &xr_event, &xr_error)) {
179 LOG(ERROR) << "X Record extension not available."; 155 LOG(ERROR) << "X Record extension not available.";
180 return; 156 return;
181 } 157 }
182 158
183 if (!x_record_range_[type]) 159 if (!x_record_range_[type])
184 x_record_range_[type] = XRecordAllocRange(); 160 x_record_range_[type] = XRecordAllocRange();
185 161
186 if (!x_record_range_[type]) { 162 if (!x_record_range_[type]) {
187 LOG(ERROR) << "XRecordAllocRange failed."; 163 LOG(ERROR) << "XRecordAllocRange failed.";
188 return; 164 return;
189 } 165 }
190 166
191 if (type == MOUSE_EVENT) { 167 if (type == MOUSE_EVENT) {
192 x_record_range_[type]->device_events.first = MotionNotify; 168 x_record_range_[type]->device_events.first = MotionNotify;
193 x_record_range_[type]->device_events.last = MotionNotify; 169 x_record_range_[type]->device_events.last = MotionNotify;
194 } else { 170 } else {
195 DCHECK_EQ(KEYBOARD_EVENT, type); 171 DCHECK_EQ(KEYBOARD_EVENT, type);
196 x_record_range_[type]->device_events.first = KeyPress; 172 x_record_range_[type]->device_events.first = KeyPress;
197 x_record_range_[type]->device_events.last = KeyRelease; 173 x_record_range_[type]->device_events.last = KeyRelease;
198 } 174 }
199 175
200 if (x_record_context_) { 176 if (x_record_context_) {
201 XRecordDisableContext(display_, x_record_context_); 177 XRecordDisableContext(x_control_display_, x_record_context_);
202 XFlush(display_); 178 XFlush(x_control_display_);
203 XRecordFreeContext(x_record_display_, x_record_context_); 179 XRecordFreeContext(x_record_display_, x_record_context_);
204 x_record_context_ = 0; 180 x_record_context_ = 0;
205 } 181 }
206 XRecordRange** record_range_to_use = 182 XRecordRange** record_range_to_use =
207 (x_record_range_[0] && x_record_range_[1]) ? x_record_range_ 183 (x_record_range_[0] && x_record_range_[1]) ? x_record_range_
208 : &x_record_range_[type]; 184 : &x_record_range_[type];
209 int number_of_ranges = (x_record_range_[0] && x_record_range_[1]) ? 2 : 1; 185 int number_of_ranges = (x_record_range_[0] && x_record_range_[1]) ? 2 : 1;
210 186
211 XRecordClientSpec client_spec = XRecordAllClients; 187 XRecordClientSpec client_spec = XRecordAllClients;
212 x_record_context_ = XRecordCreateContext(x_record_display_, 188 x_record_context_ = XRecordCreateContext(x_record_display_,
213 0, 189 0,
214 &client_spec, 190 &client_spec,
215 1, 191 1,
216 record_range_to_use, 192 record_range_to_use,
217 number_of_ranges); 193 number_of_ranges);
218 if (!x_record_context_) { 194 if (!x_record_context_) {
219 LOG(ERROR) << "XRecordCreateContext failed."; 195 LOG(ERROR) << "XRecordCreateContext failed.";
220 return; 196 return;
221 } 197 }
222 198
223 if (!XRecordEnableContextAsync(x_record_display_, 199 if (!XRecordEnableContextAsync(x_record_display_,
224 x_record_context_, 200 x_record_context_,
225 &UserInputMonitorLinux::ProcessReply, 201 &UserInputMonitorLinuxCore::ProcessReply,
226 reinterpret_cast<XPointer>(this))) { 202 reinterpret_cast<XPointer>(this))) {
227 LOG(ERROR) << "XRecordEnableContextAsync failed."; 203 LOG(ERROR) << "XRecordEnableContextAsync failed.";
228 return; 204 return;
229 } 205 }
230 206
231 if (!x_record_range_[0] || !x_record_range_[1]) { 207 if (!x_record_range_[0] || !x_record_range_[1]) {
232 // Register OnFileCanReadWithoutBlocking() to be called every time there is 208 // Register OnFileCanReadWithoutBlocking() to be called every time there is
233 // something to read from |x_record_display_|. 209 // something to read from |x_record_display_|.
234 base::MessageLoopForIO* message_loop = base::MessageLoopForIO::current(); 210 base::MessageLoopForIO* message_loop = base::MessageLoopForIO::current();
235 int result = 211 int result =
236 message_loop->WatchFileDescriptor(ConnectionNumber(x_record_display_), 212 message_loop->WatchFileDescriptor(ConnectionNumber(x_record_display_),
237 true, 213 true,
238 base::MessageLoopForIO::WATCH_READ, 214 base::MessageLoopForIO::WATCH_READ,
239 &controller_, 215 &controller_,
240 this); 216 this);
241 if (!result) { 217 if (!result) {
242 LOG(ERROR) << "Failed to create X record task."; 218 LOG(ERROR) << "Failed to create X record task.";
243 return; 219 return;
244 } 220 }
245 } 221 }
246 222
247 // Fetch pending events if any. 223 // Fetch pending events if any.
248 OnFileCanReadWithoutBlocking(ConnectionNumber(x_record_display_)); 224 OnFileCanReadWithoutBlocking(ConnectionNumber(x_record_display_));
249 } 225 }
250 226
251 void UserInputMonitorLinux::StopMonitor(EventType type) { 227 void UserInputMonitorLinuxCore::StopMonitor(EventType type) {
252 DCHECK(io_task_runner_->BelongsToCurrentThread()); 228 DCHECK(io_task_runner_->BelongsToCurrentThread());
253 229
254 if (x_record_range_[type]) { 230 if (x_record_range_[type]) {
255 XFree(x_record_range_[type]); 231 XFree(x_record_range_[type]);
256 x_record_range_[type] = NULL; 232 x_record_range_[type] = NULL;
257 } 233 }
258 if (x_record_range_[0] || x_record_range_[1]) 234 if (x_record_range_[0] || x_record_range_[1])
259 return; 235 return;
260 236
261 // Context must be disabled via the control channel because we can't send 237 // 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. 238 // any X protocol traffic over the data channel while it's recording.
263 if (x_record_context_) { 239 if (x_record_context_) {
264 XRecordDisableContext(display_, x_record_context_); 240 XRecordDisableContext(x_control_display_, x_record_context_);
265 XFlush(display_); 241 XFlush(x_control_display_);
266 XRecordFreeContext(x_record_display_, x_record_context_); 242 XRecordFreeContext(x_record_display_, x_record_context_);
267 x_record_context_ = 0; 243 x_record_context_ = 0;
268 244
269 controller_.StopWatchingFileDescriptor(); 245 controller_.StopWatchingFileDescriptor();
270 if (x_record_display_) { 246 if (x_record_display_) {
271 XCloseDisplay(x_record_display_); 247 XCloseDisplay(x_record_display_);
272 x_record_display_ = NULL; 248 x_record_display_ = NULL;
273 } 249 }
274 if (display_) { 250 if (x_control_display_) {
275 XCloseDisplay(display_); 251 XCloseDisplay(x_control_display_);
276 display_ = NULL; 252 x_control_display_ = NULL;
277 } 253 }
278 } 254 }
279 } 255 }
280 256
281 void UserInputMonitorLinux::OnFileCanReadWithoutBlocking(int fd) { 257 void UserInputMonitorLinuxCore::OnFileCanReadWithoutBlocking(int fd) {
282 DCHECK(io_task_runner_->BelongsToCurrentThread()); 258 DCHECK(io_task_runner_->BelongsToCurrentThread());
283 XEvent event; 259 XEvent event;
284 // Fetch pending events if any. 260 // Fetch pending events if any.
285 while (XPending(x_record_display_)) { 261 while (XPending(x_record_display_)) {
286 XNextEvent(x_record_display_, &event); 262 XNextEvent(x_record_display_, &event);
287 } 263 }
288 } 264 }
289 265
290 void UserInputMonitorLinux::OnFileCanWriteWithoutBlocking(int fd) { 266 void UserInputMonitorLinuxCore::OnFileCanWriteWithoutBlocking(int fd) {
291 NOTREACHED(); 267 NOTREACHED();
292 } 268 }
293 269
294 void UserInputMonitorLinux::ProcessXEvent(xEvent* event) { 270 void UserInputMonitorLinuxCore::ProcessXEvent(xEvent* event) {
295 DCHECK(io_task_runner_->BelongsToCurrentThread()); 271 DCHECK(io_task_runner_->BelongsToCurrentThread());
296 if (event->u.u.type == MotionNotify) { 272 if (event->u.u.type == MotionNotify) {
297 SkIPoint position(SkIPoint::Make(event->u.keyButtonPointer.rootX, 273 SkIPoint position(SkIPoint::Make(event->u.keyButtonPointer.rootX,
298 event->u.keyButtonPointer.rootY)); 274 event->u.keyButtonPointer.rootY));
299 OnMouseEvent(position); 275 mouse_listeners_->Notify(
276 &UserInputMonitor::MouseEventListener::OnMouseMoved, position);
300 } else { 277 } else {
301 ui::EventType type; 278 ui::EventType type;
302 if (event->u.u.type == KeyPress) { 279 if (event->u.u.type == KeyPress) {
303 type = ui::ET_KEY_PRESSED; 280 type = ui::ET_KEY_PRESSED;
304 } else if (event->u.u.type == KeyRelease) { 281 } else if (event->u.u.type == KeyRelease) {
305 type = ui::ET_KEY_RELEASED; 282 type = ui::ET_KEY_RELEASED;
306 } else { 283 } else {
307 NOTREACHED(); 284 NOTREACHED();
308 return; 285 return;
309 } 286 }
310 287
311 KeySym key_sym = XkbKeycodeToKeysym(display_, event->u.u.detail, 0, 0); 288 KeySym key_sym =
289 XkbKeycodeToKeysym(x_control_display_, event->u.u.detail, 0, 0);
312 ui::KeyboardCode key_code = ui::KeyboardCodeFromXKeysym(key_sym); 290 ui::KeyboardCode key_code = ui::KeyboardCodeFromXKeysym(key_sym);
313 counter_.OnKeyboardEvent(type, key_code); 291 counter_.OnKeyboardEvent(type, key_code);
314 } 292 }
315 } 293 }
316 294
317 // static 295 // static
318 void UserInputMonitorLinux::ProcessReply(XPointer self, 296 void UserInputMonitorLinuxCore::ProcessReply(XPointer self,
319 XRecordInterceptData* data) { 297 XRecordInterceptData* data) {
320 if (data->category == XRecordFromServer) { 298 if (data->category == XRecordFromServer) {
321 xEvent* event = reinterpret_cast<xEvent*>(data->data); 299 xEvent* event = reinterpret_cast<xEvent*>(data->data);
322 reinterpret_cast<UserInputMonitorLinux*>(self)->ProcessXEvent(event); 300 reinterpret_cast<UserInputMonitorLinuxCore*>(self)->ProcessXEvent(event);
323 } 301 }
324 XRecordFreeData(data); 302 XRecordFreeData(data);
325 } 303 }
326 304
305 //
306 // Implementation of UserInputMonitorLinux.
307 //
308
309 UserInputMonitorLinux::UserInputMonitorLinux(
310 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
311 : io_task_runner_(io_task_runner),
312 core_(new UserInputMonitorLinuxCore(io_task_runner, mouse_listeners())) {}
313
314 UserInputMonitorLinux::~UserInputMonitorLinux() {
315 if (!io_task_runner_->DeleteSoon(FROM_HERE, core_))
316 delete core_;
317 }
318
319 size_t UserInputMonitorLinux::GetKeyPressCount() const {
320 return core_->GetKeyPressCount();
321 }
322
323 void UserInputMonitorLinux::StartKeyboardMonitoring() {
324 io_task_runner_->PostTask(
325 FROM_HERE,
326 base::Bind(&UserInputMonitorLinuxCore::StartMonitor,
327 core_->AsWeakPtr(),
328 UserInputMonitorLinuxCore::KEYBOARD_EVENT));
329 }
330
331 void UserInputMonitorLinux::StopKeyboardMonitoring() {
332 io_task_runner_->PostTask(
333 FROM_HERE,
334 base::Bind(&UserInputMonitorLinuxCore::StopMonitor,
335 core_->AsWeakPtr(),
336 UserInputMonitorLinuxCore::KEYBOARD_EVENT));
337 }
338
339 void UserInputMonitorLinux::StartMouseMonitoring() {
340 io_task_runner_->PostTask(FROM_HERE,
341 base::Bind(&UserInputMonitorLinuxCore::StartMonitor,
342 core_->AsWeakPtr(),
343 UserInputMonitorLinuxCore::MOUSE_EVENT));
344 }
345
346 void UserInputMonitorLinux::StopMouseMonitoring() {
347 io_task_runner_->PostTask(FROM_HERE,
348 base::Bind(&UserInputMonitorLinuxCore::StopMonitor,
349 core_->AsWeakPtr(),
350 UserInputMonitorLinuxCore::MOUSE_EVENT));
351 }
352
327 } // namespace 353 } // namespace
328 354
329 scoped_ptr<UserInputMonitor> UserInputMonitor::Create( 355 scoped_ptr<UserInputMonitor> UserInputMonitor::Create(
330 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 356 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
331 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { 357 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) {
332 return scoped_ptr<UserInputMonitor>( 358 return scoped_ptr<UserInputMonitor>(
333 new UserInputMonitorLinux(io_task_runner)); 359 new UserInputMonitorLinux(io_task_runner));
334 } 360 }
335 361
336 } // namespace media 362 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698