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 #include <stddef.h> | 9 #include <stddef.h> |
| 10 |
10 #include <utility> | 11 #include <utility> |
11 | 12 |
| 13 #include "base/memory/ptr_util.h" |
12 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
13 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
14 #include "base/threading/worker_pool.h" | 16 #include "base/threading/worker_pool.h" |
15 #include "base/time/time.h" | 17 #include "base/time/time.h" |
16 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
17 #include "ui/events/devices/device_data_manager.h" | 19 #include "ui/events/devices/device_data_manager.h" |
18 #include "ui/events/devices/device_util_linux.h" | 20 #include "ui/events/devices/device_util_linux.h" |
19 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" | 21 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
20 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 22 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
21 #include "ui/events/ozone/evdev/event_device_info.h" | 23 #include "ui/events/ozone/evdev/event_device_info.h" |
22 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" | 24 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" |
23 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" | 25 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
24 | 26 |
25 #if defined(USE_EVDEV_GESTURES) | 27 #if defined(USE_EVDEV_GESTURES) |
26 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" | 28 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" |
27 #include "ui/events/ozone/evdev/libgestures_glue/gesture_feedback.h" | 29 #include "ui/events/ozone/evdev/libgestures_glue/gesture_feedback.h" |
28 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" | 30 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" |
29 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 31 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
30 #endif | 32 #endif |
31 | 33 |
32 #ifndef EVIOCSCLOCKID | 34 #ifndef EVIOCSCLOCKID |
33 #define EVIOCSCLOCKID _IOW('E', 0xa0, int) | 35 #define EVIOCSCLOCKID _IOW('E', 0xa0, int) |
34 #endif | 36 #endif |
35 | 37 |
36 namespace ui { | 38 namespace ui { |
37 | 39 |
38 namespace { | 40 namespace { |
39 | 41 |
40 typedef base::Callback<void(scoped_ptr<EventConverterEvdev>)> | 42 typedef base::Callback<void(std::unique_ptr<EventConverterEvdev>)> |
41 OpenInputDeviceReplyCallback; | 43 OpenInputDeviceReplyCallback; |
42 | 44 |
43 struct OpenInputDeviceParams { | 45 struct OpenInputDeviceParams { |
44 // Unique identifier for the new device. | 46 // Unique identifier for the new device. |
45 int id; | 47 int id; |
46 | 48 |
47 // Device path to open. | 49 // Device path to open. |
48 base::FilePath path; | 50 base::FilePath path; |
49 | 51 |
50 // Dispatcher for events. Call on UI thread only. | 52 // Dispatcher for events. Call on UI thread only. |
(...skipping 24 matching lines...) Expand all Loading... |
75 bool value) { | 77 bool value) { |
76 GesturesProp* property = provider->GetProperty(id, name); | 78 GesturesProp* property = provider->GetProperty(id, name); |
77 if (property) { | 79 if (property) { |
78 std::vector<bool> values(1, value); | 80 std::vector<bool> values(1, value); |
79 property->SetBoolValue(values); | 81 property->SetBoolValue(values); |
80 } | 82 } |
81 } | 83 } |
82 | 84 |
83 #endif | 85 #endif |
84 | 86 |
85 scoped_ptr<EventConverterEvdev> CreateConverter( | 87 std::unique_ptr<EventConverterEvdev> CreateConverter( |
86 const OpenInputDeviceParams& params, | 88 const OpenInputDeviceParams& params, |
87 int fd, | 89 int fd, |
88 const EventDeviceInfo& devinfo) { | 90 const EventDeviceInfo& devinfo) { |
89 #if defined(USE_EVDEV_GESTURES) | 91 #if defined(USE_EVDEV_GESTURES) |
90 // Touchpad or mouse: use gestures library. | 92 // Touchpad or mouse: use gestures library. |
91 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent | 93 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent |
92 if (devinfo.HasTouchpad() || devinfo.HasMouse()) { | 94 if (devinfo.HasTouchpad() || devinfo.HasMouse()) { |
93 scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = | 95 std::unique_ptr<GestureInterpreterLibevdevCros> gesture_interp = |
94 make_scoped_ptr(new GestureInterpreterLibevdevCros( | 96 base::WrapUnique(new GestureInterpreterLibevdevCros( |
95 params.id, params.cursor, params.gesture_property_provider, | 97 params.id, params.cursor, params.gesture_property_provider, |
96 params.dispatcher)); | 98 params.dispatcher)); |
97 return make_scoped_ptr(new EventReaderLibevdevCros( | 99 return base::WrapUnique(new EventReaderLibevdevCros( |
98 fd, params.path, params.id, devinfo, std::move(gesture_interp))); | 100 fd, params.path, params.id, devinfo, std::move(gesture_interp))); |
99 } | 101 } |
100 #endif | 102 #endif |
101 | 103 |
102 // Touchscreen: use TouchEventConverterEvdev. | 104 // Touchscreen: use TouchEventConverterEvdev. |
103 if (devinfo.HasTouchscreen()) { | 105 if (devinfo.HasTouchscreen()) { |
104 scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev( | 106 std::unique_ptr<TouchEventConverterEvdev> converter( |
105 fd, params.path, params.id, devinfo, params.dispatcher)); | 107 new TouchEventConverterEvdev(fd, params.path, params.id, devinfo, |
| 108 params.dispatcher)); |
106 converter->Initialize(devinfo); | 109 converter->Initialize(devinfo); |
107 return std::move(converter); | 110 return std::move(converter); |
108 } | 111 } |
109 | 112 |
110 // Graphics tablet | 113 // Graphics tablet |
111 if (devinfo.HasTablet()) | 114 if (devinfo.HasTablet()) |
112 return make_scoped_ptr<EventConverterEvdev>(new TabletEventConverterEvdev( | 115 return base::WrapUnique<EventConverterEvdev>(new TabletEventConverterEvdev( |
113 fd, params.path, params.id, params.cursor, devinfo, params.dispatcher)); | 116 fd, params.path, params.id, params.cursor, devinfo, params.dispatcher)); |
114 | 117 |
115 // Everything else: use EventConverterEvdevImpl. | 118 // Everything else: use EventConverterEvdevImpl. |
116 return make_scoped_ptr<EventConverterEvdevImpl>(new EventConverterEvdevImpl( | 119 return base::WrapUnique<EventConverterEvdevImpl>(new EventConverterEvdevImpl( |
117 fd, params.path, params.id, devinfo, params.cursor, params.dispatcher)); | 120 fd, params.path, params.id, devinfo, params.cursor, params.dispatcher)); |
118 } | 121 } |
119 | 122 |
120 // Open an input device. Opening may put the calling thread to sleep, and | 123 // Open an input device. Opening may put the calling thread to sleep, and |
121 // therefore should be run on a thread where latency is not critical. We | 124 // therefore should be run on a thread where latency is not critical. We |
122 // run it on a thread from the worker pool. | 125 // run it on a thread from the worker pool. |
123 // | 126 // |
124 // This takes a TaskRunner and runs the reply on that thread, so that we | 127 // This takes a TaskRunner and runs the reply on that thread, so that we |
125 // can hop threads if necessary (back to the UI thread). | 128 // can hop threads if necessary (back to the UI thread). |
126 void OpenInputDevice(scoped_ptr<OpenInputDeviceParams> params, | 129 void OpenInputDevice(std::unique_ptr<OpenInputDeviceParams> params, |
127 scoped_refptr<base::TaskRunner> reply_runner, | 130 scoped_refptr<base::TaskRunner> reply_runner, |
128 const OpenInputDeviceReplyCallback& reply_callback) { | 131 const OpenInputDeviceReplyCallback& reply_callback) { |
129 const base::FilePath& path = params->path; | 132 const base::FilePath& path = params->path; |
130 scoped_ptr<EventConverterEvdev> converter; | 133 std::unique_ptr<EventConverterEvdev> converter; |
131 | 134 |
132 TRACE_EVENT1("evdev", "OpenInputDevice", "path", path.value()); | 135 TRACE_EVENT1("evdev", "OpenInputDevice", "path", path.value()); |
133 | 136 |
134 int fd = open(path.value().c_str(), O_RDWR | O_NONBLOCK); | 137 int fd = open(path.value().c_str(), O_RDWR | O_NONBLOCK); |
135 if (fd < 0) { | 138 if (fd < 0) { |
136 PLOG(ERROR) << "Cannot open '" << path.value(); | 139 PLOG(ERROR) << "Cannot open '" << path.value(); |
137 reply_runner->PostTask( | 140 reply_runner->PostTask( |
138 FROM_HERE, base::Bind(reply_callback, base::Passed(&converter))); | 141 FROM_HERE, base::Bind(reply_callback, base::Passed(&converter))); |
139 return; | 142 return; |
140 } | 143 } |
(...skipping 18 matching lines...) Expand all Loading... |
159 | 162 |
160 // Reply with the constructed converter. | 163 // Reply with the constructed converter. |
161 reply_runner->PostTask(FROM_HERE, | 164 reply_runner->PostTask(FROM_HERE, |
162 base::Bind(reply_callback, base::Passed(&converter))); | 165 base::Bind(reply_callback, base::Passed(&converter))); |
163 } | 166 } |
164 | 167 |
165 // Close an input device. Closing may put the calling thread to sleep, and | 168 // Close an input device. Closing may put the calling thread to sleep, and |
166 // therefore should be run on a thread where latency is not critical. We | 169 // therefore should be run on a thread where latency is not critical. We |
167 // run it on the FILE thread. | 170 // run it on the FILE thread. |
168 void CloseInputDevice(const base::FilePath& path, | 171 void CloseInputDevice(const base::FilePath& path, |
169 scoped_ptr<EventConverterEvdev> converter) { | 172 std::unique_ptr<EventConverterEvdev> converter) { |
170 TRACE_EVENT1("evdev", "CloseInputDevice", "path", path.value()); | 173 TRACE_EVENT1("evdev", "CloseInputDevice", "path", path.value()); |
171 converter.reset(); | 174 converter.reset(); |
172 } | 175 } |
173 | 176 |
174 } // namespace | 177 } // namespace |
175 | 178 |
176 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( | 179 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( |
177 scoped_ptr<DeviceEventDispatcherEvdev> dispatcher, | 180 std::unique_ptr<DeviceEventDispatcherEvdev> dispatcher, |
178 CursorDelegateEvdev* cursor) | 181 CursorDelegateEvdev* cursor) |
179 : task_runner_(base::ThreadTaskRunnerHandle::Get()), | 182 : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
180 cursor_(cursor), | 183 cursor_(cursor), |
181 #if defined(USE_EVDEV_GESTURES) | 184 #if defined(USE_EVDEV_GESTURES) |
182 gesture_property_provider_(new GesturePropertyProvider), | 185 gesture_property_provider_(new GesturePropertyProvider), |
183 #endif | 186 #endif |
184 dispatcher_(std::move(dispatcher)), | 187 dispatcher_(std::move(dispatcher)), |
185 weak_ptr_factory_(this) { | 188 weak_ptr_factory_(this) { |
186 } | 189 } |
187 | 190 |
188 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { | 191 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { |
189 STLDeleteValues(&converters_); | 192 STLDeleteValues(&converters_); |
190 } | 193 } |
191 | 194 |
192 void InputDeviceFactoryEvdev::AddInputDevice(int id, | 195 void InputDeviceFactoryEvdev::AddInputDevice(int id, |
193 const base::FilePath& path) { | 196 const base::FilePath& path) { |
194 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); | 197 std::unique_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
195 params->id = id; | 198 params->id = id; |
196 params->path = path; | 199 params->path = path; |
197 params->cursor = cursor_; | 200 params->cursor = cursor_; |
198 params->dispatcher = dispatcher_.get(); | 201 params->dispatcher = dispatcher_.get(); |
199 | 202 |
200 #if defined(USE_EVDEV_GESTURES) | 203 #if defined(USE_EVDEV_GESTURES) |
201 params->gesture_property_provider = gesture_property_provider_.get(); | 204 params->gesture_property_provider = gesture_property_provider_.get(); |
202 #endif | 205 #endif |
203 | 206 |
204 OpenInputDeviceReplyCallback reply_callback = | 207 OpenInputDeviceReplyCallback reply_callback = |
(...skipping 12 matching lines...) Expand all Loading... |
217 void InputDeviceFactoryEvdev::RemoveInputDevice(const base::FilePath& path) { | 220 void InputDeviceFactoryEvdev::RemoveInputDevice(const base::FilePath& path) { |
218 DetachInputDevice(path); | 221 DetachInputDevice(path); |
219 } | 222 } |
220 | 223 |
221 void InputDeviceFactoryEvdev::OnStartupScanComplete() { | 224 void InputDeviceFactoryEvdev::OnStartupScanComplete() { |
222 startup_devices_enumerated_ = true; | 225 startup_devices_enumerated_ = true; |
223 NotifyDevicesUpdated(); | 226 NotifyDevicesUpdated(); |
224 } | 227 } |
225 | 228 |
226 void InputDeviceFactoryEvdev::AttachInputDevice( | 229 void InputDeviceFactoryEvdev::AttachInputDevice( |
227 scoped_ptr<EventConverterEvdev> converter) { | 230 std::unique_ptr<EventConverterEvdev> converter) { |
228 if (converter.get()) { | 231 if (converter.get()) { |
229 const base::FilePath& path = converter->path(); | 232 const base::FilePath& path = converter->path(); |
230 | 233 |
231 TRACE_EVENT1("evdev", "AttachInputDevice", "path", path.value()); | 234 TRACE_EVENT1("evdev", "AttachInputDevice", "path", path.value()); |
232 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 235 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
233 | 236 |
234 // If we have an existing device, detach it. We don't want two | 237 // If we have an existing device, detach it. We don't want two |
235 // devices with the same name open at the same time. | 238 // devices with the same name open at the same time. |
236 if (converters_[path]) | 239 if (converters_[path]) |
237 DetachInputDevice(path); | 240 DetachInputDevice(path); |
(...skipping 10 matching lines...) Expand all Loading... |
248 | 251 |
249 --pending_device_changes_; | 252 --pending_device_changes_; |
250 NotifyDevicesUpdated(); | 253 NotifyDevicesUpdated(); |
251 } | 254 } |
252 | 255 |
253 void InputDeviceFactoryEvdev::DetachInputDevice(const base::FilePath& path) { | 256 void InputDeviceFactoryEvdev::DetachInputDevice(const base::FilePath& path) { |
254 TRACE_EVENT1("evdev", "DetachInputDevice", "path", path.value()); | 257 TRACE_EVENT1("evdev", "DetachInputDevice", "path", path.value()); |
255 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 258 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
256 | 259 |
257 // Remove device from map. | 260 // Remove device from map. |
258 scoped_ptr<EventConverterEvdev> converter(converters_[path]); | 261 std::unique_ptr<EventConverterEvdev> converter(converters_[path]); |
259 converters_.erase(path); | 262 converters_.erase(path); |
260 | 263 |
261 if (converter) { | 264 if (converter) { |
262 // Disable the device (to release keys/buttons/etc). | 265 // Disable the device (to release keys/buttons/etc). |
263 converter->SetEnabled(false); | 266 converter->SetEnabled(false); |
264 | 267 |
265 // Cancel libevent notifications from this converter. This part must be | 268 // Cancel libevent notifications from this converter. This part must be |
266 // on UI since the polling happens on UI. | 269 // on UI since the polling happens on UI. |
267 converter->Stop(); | 270 converter->Stop(); |
268 | 271 |
(...skipping 13 matching lines...) Expand all Loading... |
282 } | 285 } |
283 | 286 |
284 void InputDeviceFactoryEvdev::UpdateInputDeviceSettings( | 287 void InputDeviceFactoryEvdev::UpdateInputDeviceSettings( |
285 const InputDeviceSettingsEvdev& settings) { | 288 const InputDeviceSettingsEvdev& settings) { |
286 input_device_settings_ = settings; | 289 input_device_settings_ = settings; |
287 ApplyInputDeviceSettings(); | 290 ApplyInputDeviceSettings(); |
288 } | 291 } |
289 | 292 |
290 void InputDeviceFactoryEvdev::GetTouchDeviceStatus( | 293 void InputDeviceFactoryEvdev::GetTouchDeviceStatus( |
291 const GetTouchDeviceStatusReply& reply) { | 294 const GetTouchDeviceStatusReply& reply) { |
292 scoped_ptr<std::string> status(new std::string); | 295 std::unique_ptr<std::string> status(new std::string); |
293 #if defined(USE_EVDEV_GESTURES) | 296 #if defined(USE_EVDEV_GESTURES) |
294 DumpTouchDeviceStatus(gesture_property_provider_.get(), status.get()); | 297 DumpTouchDeviceStatus(gesture_property_provider_.get(), status.get()); |
295 #endif | 298 #endif |
296 reply.Run(std::move(status)); | 299 reply.Run(std::move(status)); |
297 } | 300 } |
298 | 301 |
299 void InputDeviceFactoryEvdev::GetTouchEventLog( | 302 void InputDeviceFactoryEvdev::GetTouchEventLog( |
300 const base::FilePath& out_dir, | 303 const base::FilePath& out_dir, |
301 const GetTouchEventLogReply& reply) { | 304 const GetTouchEventLogReply& reply) { |
302 scoped_ptr<std::vector<base::FilePath>> log_paths( | 305 std::unique_ptr<std::vector<base::FilePath>> log_paths( |
303 new std::vector<base::FilePath>); | 306 new std::vector<base::FilePath>); |
304 #if defined(USE_EVDEV_GESTURES) | 307 #if defined(USE_EVDEV_GESTURES) |
305 DumpTouchEventLog(converters_, gesture_property_provider_.get(), out_dir, | 308 DumpTouchEventLog(converters_, gesture_property_provider_.get(), out_dir, |
306 std::move(log_paths), reply); | 309 std::move(log_paths), reply); |
307 #else | 310 #else |
308 reply.Run(std::move(log_paths)); | 311 reply.Run(std::move(log_paths)); |
309 #endif | 312 #endif |
310 } | 313 } |
311 | 314 |
312 base::WeakPtr<InputDeviceFactoryEvdev> InputDeviceFactoryEvdev::GetWeakPtr() { | 315 base::WeakPtr<InputDeviceFactoryEvdev> InputDeviceFactoryEvdev::GetWeakPtr() { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 std::vector<int> ids; | 485 std::vector<int> ids; |
483 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 486 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
484 for (size_t i = 0; i < ids.size(); ++i) { | 487 for (size_t i = 0; i < ids.size(); ++i) { |
485 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, | 488 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, |
486 value); | 489 value); |
487 } | 490 } |
488 #endif | 491 #endif |
489 } | 492 } |
490 | 493 |
491 } // namespace ui | 494 } // namespace ui |
OLD | NEW |