| 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/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/threading/worker_pool.h" | 14 #include "base/threading/worker_pool.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "ui/events/devices/device_data_manager.h" | 16 #include "ui/events/devices/device_data_manager.h" |
| 16 #include "ui/events/devices/device_util_linux.h" | 17 #include "ui/events/devices/device_util_linux.h" |
| 17 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" | 18 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
| 18 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 19 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
| 19 #include "ui/events/ozone/evdev/event_device_info.h" | 20 #include "ui/events/ozone/evdev/event_device_info.h" |
| 20 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" | 21 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" |
| 21 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" | 22 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
| 22 | 23 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // run it on the FILE thread. | 241 // run it on the FILE thread. |
| 241 void CloseInputDevice(const base::FilePath& path, | 242 void CloseInputDevice(const base::FilePath& path, |
| 242 scoped_ptr<EventConverterEvdev> converter) { | 243 scoped_ptr<EventConverterEvdev> converter) { |
| 243 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); | 244 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); |
| 244 converter.reset(); | 245 converter.reset(); |
| 245 } | 246 } |
| 246 | 247 |
| 247 } // namespace | 248 } // namespace |
| 248 | 249 |
| 249 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( | 250 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( |
| 250 DeviceEventDispatcherEvdev* dispatcher, | 251 scoped_ptr<DeviceEventDispatcherEvdev> dispatcher, |
| 251 scoped_refptr<base::SingleThreadTaskRunner> dispatch_runner, | |
| 252 CursorDelegateEvdev* cursor) | 252 CursorDelegateEvdev* cursor) |
| 253 : ui_task_runner_(dispatch_runner), | 253 : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 254 cursor_(cursor), | 254 cursor_(cursor), |
| 255 #if defined(USE_EVDEV_GESTURES) | 255 #if defined(USE_EVDEV_GESTURES) |
| 256 gesture_property_provider_(new GesturePropertyProvider), | 256 gesture_property_provider_(new GesturePropertyProvider), |
| 257 #endif | 257 #endif |
| 258 dispatcher_(dispatcher), | 258 dispatcher_(dispatcher.Pass()), |
| 259 weak_ptr_factory_(this) { | 259 weak_ptr_factory_(this) { |
| 260 } | 260 } |
| 261 | 261 |
| 262 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { | 262 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { |
| 263 STLDeleteValues(&converters_); | 263 STLDeleteValues(&converters_); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void InputDeviceFactoryEvdev::AddInputDevice(int id, | 266 void InputDeviceFactoryEvdev::AddInputDevice(int id, |
| 267 const base::FilePath& path) { | 267 const base::FilePath& path) { |
| 268 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); | 268 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
| 269 params->id = id; | 269 params->id = id; |
| 270 params->path = path; | 270 params->path = path; |
| 271 params->cursor = cursor_; | 271 params->cursor = cursor_; |
| 272 params->dispatcher = dispatcher_; | 272 params->dispatcher = dispatcher_.get(); |
| 273 | 273 |
| 274 #if defined(USE_EVDEV_GESTURES) | 274 #if defined(USE_EVDEV_GESTURES) |
| 275 params->gesture_property_provider = gesture_property_provider_.get(); | 275 params->gesture_property_provider = gesture_property_provider_.get(); |
| 276 #endif | 276 #endif |
| 277 | 277 |
| 278 OpenInputDeviceReplyCallback reply_callback = | 278 OpenInputDeviceReplyCallback reply_callback = |
| 279 base::Bind(&InputDeviceFactoryEvdev::AttachInputDevice, | 279 base::Bind(&InputDeviceFactoryEvdev::AttachInputDevice, |
| 280 weak_ptr_factory_.GetWeakPtr()); | 280 weak_ptr_factory_.GetWeakPtr()); |
| 281 | 281 |
| 282 // Dispatch task to open from the worker pool, since open may block. | 282 // Dispatch task to open from the worker pool, since open may block. |
| 283 base::WorkerPool::PostTask(FROM_HERE, | 283 base::WorkerPool::PostTask(FROM_HERE, |
| 284 base::Bind(&OpenInputDevice, base::Passed(¶ms), | 284 base::Bind(&OpenInputDevice, base::Passed(¶ms), |
| 285 ui_task_runner_, reply_callback), | 285 task_runner_, reply_callback), |
| 286 true /* task_is_slow */); | 286 true /* task_is_slow */); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void InputDeviceFactoryEvdev::RemoveInputDevice(const base::FilePath& path) { | 289 void InputDeviceFactoryEvdev::RemoveInputDevice(const base::FilePath& path) { |
| 290 DetachInputDevice(path); | 290 DetachInputDevice(path); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void InputDeviceFactoryEvdev::AttachInputDevice( | 293 void InputDeviceFactoryEvdev::AttachInputDevice( |
| 294 scoped_ptr<EventConverterEvdev> converter) { | 294 scoped_ptr<EventConverterEvdev> converter) { |
| 295 const base::FilePath& path = converter->path(); | 295 const base::FilePath& path = converter->path(); |
| 296 | 296 |
| 297 TRACE_EVENT1("ozone", "AttachInputDevice", "path", path.value()); | 297 TRACE_EVENT1("ozone", "AttachInputDevice", "path", path.value()); |
| 298 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 298 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 299 | 299 |
| 300 // If we have an existing device, detach it. We don't want two | 300 // If we have an existing device, detach it. We don't want two |
| 301 // devices with the same name open at the same time. | 301 // devices with the same name open at the same time. |
| 302 if (converters_[path]) | 302 if (converters_[path]) |
| 303 DetachInputDevice(path); | 303 DetachInputDevice(path); |
| 304 | 304 |
| 305 // Add initialized device to map. | 305 // Add initialized device to map. |
| 306 converters_[path] = converter.release(); | 306 converters_[path] = converter.release(); |
| 307 converters_[path]->Start(); | 307 converters_[path]->Start(); |
| 308 | 308 |
| 309 NotifyDeviceChange(*converters_[path]); | 309 NotifyDeviceChange(*converters_[path]); |
| 310 } | 310 } |
| 311 | 311 |
| 312 void InputDeviceFactoryEvdev::DetachInputDevice(const base::FilePath& path) { | 312 void InputDeviceFactoryEvdev::DetachInputDevice(const base::FilePath& path) { |
| 313 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); | 313 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); |
| 314 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 314 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 315 | 315 |
| 316 // Remove device from map. | 316 // Remove device from map. |
| 317 scoped_ptr<EventConverterEvdev> converter(converters_[path]); | 317 scoped_ptr<EventConverterEvdev> converter(converters_[path]); |
| 318 converters_.erase(path); | 318 converters_.erase(path); |
| 319 | 319 |
| 320 if (converter) { | 320 if (converter) { |
| 321 // Cancel libevent notifications from this converter. This part must be | 321 // Cancel libevent notifications from this converter. This part must be |
| 322 // on UI since the polling happens on UI. | 322 // on UI since the polling happens on UI. |
| 323 converter->Stop(); | 323 converter->Stop(); |
| 324 | 324 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 std::vector<int> ids; | 506 std::vector<int> ids; |
| 507 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 507 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
| 508 for (size_t i = 0; i < ids.size(); ++i) { | 508 for (size_t i = 0; i < ids.size(); ++i) { |
| 509 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, | 509 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, |
| 510 value); | 510 value); |
| 511 } | 511 } |
| 512 #endif | 512 #endif |
| 513 } | 513 } |
| 514 | 514 |
| 515 } // namespace ui | 515 } // namespace ui |
| OLD | NEW |