OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ui/events/ozone/evdev/input_device_factory_evdev.h" | 5 #include "ui/events/ozone/evdev/input_device_factory_evdev.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <linux/input.h> | 8 #include <linux/input.h> |
9 | 9 |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/thread_task_runner_handle.h" |
12 #include "base/threading/worker_pool.h" | 13 #include "base/threading/worker_pool.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "ui/events/devices/device_data_manager.h" | 15 #include "ui/events/devices/device_data_manager.h" |
15 #include "ui/events/devices/device_util_linux.h" | 16 #include "ui/events/devices/device_util_linux.h" |
16 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" | 17 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
17 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 18 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
18 #include "ui/events/ozone/evdev/event_device_info.h" | 19 #include "ui/events/ozone/evdev/event_device_info.h" |
19 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" | 20 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" |
20 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" | 21 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
21 | 22 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // run it on the FILE thread. | 174 // run it on the FILE thread. |
174 void CloseInputDevice(const base::FilePath& path, | 175 void CloseInputDevice(const base::FilePath& path, |
175 scoped_ptr<EventConverterEvdev> converter) { | 176 scoped_ptr<EventConverterEvdev> converter) { |
176 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); | 177 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); |
177 converter.reset(); | 178 converter.reset(); |
178 } | 179 } |
179 | 180 |
180 } // namespace | 181 } // namespace |
181 | 182 |
182 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( | 183 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( |
183 DeviceEventDispatcherEvdev* dispatcher, | 184 scoped_ptr<DeviceEventDispatcherEvdev> dispatcher, |
184 scoped_refptr<base::SingleThreadTaskRunner> dispatch_runner, | |
185 CursorDelegateEvdev* cursor) | 185 CursorDelegateEvdev* cursor) |
186 : ui_task_runner_(dispatch_runner), | 186 : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
187 cursor_(cursor), | 187 cursor_(cursor), |
188 #if defined(USE_EVDEV_GESTURES) | 188 #if defined(USE_EVDEV_GESTURES) |
189 gesture_property_provider_(new GesturePropertyProvider), | 189 gesture_property_provider_(new GesturePropertyProvider), |
190 #endif | 190 #endif |
191 dispatcher_(dispatcher), | 191 dispatcher_(dispatcher.Pass()), |
192 weak_ptr_factory_(this) { | 192 weak_ptr_factory_(this) { |
193 } | 193 } |
194 | 194 |
195 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { | 195 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { |
196 STLDeleteValues(&converters_); | 196 STLDeleteValues(&converters_); |
197 } | 197 } |
198 | 198 |
199 void InputDeviceFactoryEvdev::AddInputDevice(int id, | 199 void InputDeviceFactoryEvdev::AddInputDevice(int id, |
200 const base::FilePath& path) { | 200 const base::FilePath& path) { |
201 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); | 201 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
202 params->id = id; | 202 params->id = id; |
203 params->path = path; | 203 params->path = path; |
204 params->cursor = cursor_; | 204 params->cursor = cursor_; |
205 params->dispatcher = dispatcher_; | 205 params->dispatcher = dispatcher_.get(); |
206 | 206 |
207 #if defined(USE_EVDEV_GESTURES) | 207 #if defined(USE_EVDEV_GESTURES) |
208 params->gesture_property_provider = gesture_property_provider_.get(); | 208 params->gesture_property_provider = gesture_property_provider_.get(); |
209 #endif | 209 #endif |
210 | 210 |
211 OpenInputDeviceReplyCallback reply_callback = | 211 OpenInputDeviceReplyCallback reply_callback = |
212 base::Bind(&InputDeviceFactoryEvdev::AttachInputDevice, | 212 base::Bind(&InputDeviceFactoryEvdev::AttachInputDevice, |
213 weak_ptr_factory_.GetWeakPtr()); | 213 weak_ptr_factory_.GetWeakPtr()); |
214 | 214 |
215 // Dispatch task to open from the worker pool, since open may block. | 215 // Dispatch task to open from the worker pool, since open may block. |
216 base::WorkerPool::PostTask(FROM_HERE, | 216 base::WorkerPool::PostTask(FROM_HERE, |
217 base::Bind(&OpenInputDevice, base::Passed(¶ms), | 217 base::Bind(&OpenInputDevice, base::Passed(¶ms), |
218 ui_task_runner_, reply_callback), | 218 task_runner_, reply_callback), |
219 true /* task_is_slow */); | 219 true /* task_is_slow */); |
220 } | 220 } |
221 | 221 |
222 void InputDeviceFactoryEvdev::RemoveInputDevice(const base::FilePath& path) { | 222 void InputDeviceFactoryEvdev::RemoveInputDevice(const base::FilePath& path) { |
223 DetachInputDevice(path); | 223 DetachInputDevice(path); |
224 } | 224 } |
225 | 225 |
226 void InputDeviceFactoryEvdev::AttachInputDevice( | 226 void InputDeviceFactoryEvdev::AttachInputDevice( |
227 scoped_ptr<EventConverterEvdev> converter) { | 227 scoped_ptr<EventConverterEvdev> converter) { |
228 const base::FilePath& path = converter->path(); | 228 const base::FilePath& path = converter->path(); |
229 | 229 |
230 TRACE_EVENT1("ozone", "AttachInputDevice", "path", path.value()); | 230 TRACE_EVENT1("ozone", "AttachInputDevice", "path", path.value()); |
231 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 231 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
232 | 232 |
233 // If we have an existing device, detach it. We don't want two | 233 // If we have an existing device, detach it. We don't want two |
234 // devices with the same name open at the same time. | 234 // devices with the same name open at the same time. |
235 if (converters_[path]) | 235 if (converters_[path]) |
236 DetachInputDevice(path); | 236 DetachInputDevice(path); |
237 | 237 |
238 // Add initialized device to map. | 238 // Add initialized device to map. |
239 converters_[path] = converter.release(); | 239 converters_[path] = converter.release(); |
240 converters_[path]->Start(); | 240 converters_[path]->Start(); |
241 | 241 |
242 NotifyDeviceChange(*converters_[path]); | 242 NotifyDeviceChange(*converters_[path]); |
243 } | 243 } |
244 | 244 |
245 void InputDeviceFactoryEvdev::DetachInputDevice(const base::FilePath& path) { | 245 void InputDeviceFactoryEvdev::DetachInputDevice(const base::FilePath& path) { |
246 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); | 246 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); |
247 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 247 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
248 | 248 |
249 // Remove device from map. | 249 // Remove device from map. |
250 scoped_ptr<EventConverterEvdev> converter(converters_[path]); | 250 scoped_ptr<EventConverterEvdev> converter(converters_[path]); |
251 converters_.erase(path); | 251 converters_.erase(path); |
252 | 252 |
253 if (converter) { | 253 if (converter) { |
254 // Cancel libevent notifications from this converter. This part must be | 254 // Cancel libevent notifications from this converter. This part must be |
255 // on UI since the polling happens on UI. | 255 // on UI since the polling happens on UI. |
256 converter->Stop(); | 256 converter->Stop(); |
257 | 257 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 std::vector<int> ids; | 430 std::vector<int> ids; |
431 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 431 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
432 for (size_t i = 0; i < ids.size(); ++i) { | 432 for (size_t i = 0; i < ids.size(); ++i) { |
433 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, | 433 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, |
434 value); | 434 value); |
435 } | 435 } |
436 #endif | 436 #endif |
437 } | 437 } |
438 | 438 |
439 } // namespace ui | 439 } // namespace ui |
OLD | NEW |