Chromium Code Reviews| Index: ui/events/ozone/evdev/event_factory_evdev.cc |
| diff --git a/ui/events/ozone/evdev/event_factory_evdev.cc b/ui/events/ozone/evdev/event_factory_evdev.cc |
| index 0895c0a14c892a30ab10253c57eed33914e88c80..5fc7b98e3e936c1e2032017ea72a18dfc8a06f40 100644 |
| --- a/ui/events/ozone/evdev/event_factory_evdev.cc |
| +++ b/ui/events/ozone/evdev/event_factory_evdev.cc |
| @@ -23,6 +23,7 @@ |
| #if defined(USE_EVDEV_GESTURES) |
| #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" |
| #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.h" |
| +#include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
| #endif |
| #ifndef EVIOCSCLOCKID |
| @@ -33,6 +34,9 @@ namespace ui { |
| namespace { |
| +// Max number of devices that we track. |
| +const int kMaxDeviceNum = 0xffff; |
| + |
| typedef base::Callback<void(scoped_ptr<EventConverterEvdev>)> |
| OpenInputDeviceReplyCallback; |
| @@ -49,6 +53,7 @@ struct OpenInputDeviceParams { |
| // State shared between devices. Must not be dereferenced on worker thread. |
| EventModifiersEvdev* modifiers; |
| CursorDelegateEvdev* cursor; |
| + GesturePropertyProvider* gesture_property_provider; |
| }; |
| #if defined(USE_EVDEV_GESTURES) |
| @@ -73,7 +78,8 @@ scoped_ptr<EventConverterEvdev> CreateConverter( |
| if (UseGesturesLibraryForDevice(devinfo)) { |
| scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = |
| make_scoped_ptr(new GestureInterpreterLibevdevCros( |
| - params.modifiers, params.cursor, params.dispatch_callback)); |
| + params.id, params.modifiers, params.cursor, |
| + params.gesture_property_provider, params.dispatch_callback)); |
| scoped_ptr<EventReaderLibevdevCros> libevdev_reader = |
| make_scoped_ptr(new EventReaderLibevdevCros( |
| fd, |
| @@ -149,9 +155,12 @@ void CloseInputDevice(const base::FilePath& path, |
| EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, |
| DeviceManager* device_manager) |
| - : last_device_id_(0), |
| + : device_id_counter_(0), |
| device_manager_(device_manager), |
| cursor_(cursor), |
| +#if defined(USE_EVDEV_GESTURES) |
| + gesture_property_provider_(new GesturePropertyProvider), |
| +#endif |
| dispatch_callback_( |
| base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), |
| base::Unretained(this))), |
| @@ -194,11 +203,14 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { |
| TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); |
| scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
| - params->id = NextDeviceId(); |
| + params->id = GenerateDeviceId(event.path()); |
| + if (params->id < 0) |
| + break; |
| params->path = event.path(); |
| params->dispatch_callback = dispatch_callback_; |
| params->modifiers = &modifiers_; |
| params->cursor = cursor_; |
| + params->gesture_property_provider = gesture_property_provider_.get(); |
| OpenInputDeviceReplyCallback reply_callback = |
| base::Bind(&EventFactoryEvdev::AttachInputDevice, |
| @@ -215,6 +227,7 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { |
| break; |
| case DeviceEvent::REMOVE: { |
| TRACE_EVENT1("ozone", "OnDeviceRemoved", "path", event.path().value()); |
| + RevokeDeviceId(event.path()); |
| DetachInputDevice(event.path()); |
| } |
| break; |
| @@ -286,8 +299,30 @@ void EventFactoryEvdev::NotifyHotplugEventObserver( |
| observer->OnTouchscreenDevicesUpdated(touchscreens); |
| } |
| -int EventFactoryEvdev::NextDeviceId() { |
| - return ++last_device_id_; |
| +int EventFactoryEvdev::GenerateDeviceId(const base::FilePath& file_path) { |
| + // Do not generate if the maximum allowed device number is reached. |
| + if (used_device_ids_.size() >= kMaxDeviceNum) |
| + return -1; |
| + |
| + // Generate a new device id for use. |
| + int id = device_id_counter_; |
| + while (used_device_ids_.find(id) != used_device_ids_.end()) |
| + id = (id + 1) & kMaxDeviceNum; |
|
spang
2014/10/15 11:36:41
This is way overkill. If 2 billion devices over th
Shecky Lin
2014/10/16 04:53:53
Done.
|
| + device_id_counter_ = (id + 1) & kMaxDeviceNum; |
| + used_device_ids_.insert(id); |
| + |
| + // If a same device node is opened again, we just replace its old id with a |
| + // new one as this is the behavior we use for converters as well. |
| + device_ids_map_[file_path] = id; |
| + return id; |
| +} |
| + |
| +void EventFactoryEvdev::RevokeDeviceId(const base::FilePath& file_path) { |
| + DeviceIdMap::iterator it = device_ids_map_.find(file_path); |
| + if (it == device_ids_map_.end()) |
| + return; |
| + used_device_ids_.erase(it->second); |
| + device_ids_map_.erase(it); |
| } |
| } // namespace ui |