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

Side by Side Diff: ui/events/ozone/evdev/input_device_factory_evdev.cc

Issue 2657533008: Merge "Fix double-close in EventConverterEvdevImpl" (Closed)
Patch Set: Created 3 years, 10 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 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
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if (property) { 75 if (property) {
76 std::vector<bool> values(1, value); 76 std::vector<bool> values(1, value);
77 property->SetBoolValue(values); 77 property->SetBoolValue(values);
78 } 78 }
79 } 79 }
80 80
81 #endif 81 #endif
82 82
83 std::unique_ptr<EventConverterEvdev> CreateConverter( 83 std::unique_ptr<EventConverterEvdev> CreateConverter(
84 const OpenInputDeviceParams& params, 84 const OpenInputDeviceParams& params,
85 int fd, 85 ScopedInputDevice fd,
86 const EventDeviceInfo& devinfo) { 86 const EventDeviceInfo& devinfo) {
87 #if defined(USE_EVDEV_GESTURES) 87 #if defined(USE_EVDEV_GESTURES)
88 // Touchpad or mouse: use gestures library. 88 // Touchpad or mouse: use gestures library.
89 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent 89 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent
90 if (devinfo.HasTouchpad() || devinfo.HasMouse()) { 90 if (devinfo.HasTouchpad() || devinfo.HasMouse()) {
91 std::unique_ptr<GestureInterpreterLibevdevCros> gesture_interp = 91 std::unique_ptr<GestureInterpreterLibevdevCros> gesture_interp =
92 base::MakeUnique<GestureInterpreterLibevdevCros>( 92 base::MakeUnique<GestureInterpreterLibevdevCros>(
93 params.id, params.cursor, params.gesture_property_provider, 93 params.id, params.cursor, params.gesture_property_provider,
94 params.dispatcher); 94 params.dispatcher);
95 return base::MakeUnique<EventReaderLibevdevCros>( 95 return base::MakeUnique<EventReaderLibevdevCros>(std::move(fd), params.path,
96 fd, params.path, params.id, devinfo, std::move(gesture_interp)); 96 params.id, devinfo,
97 std::move(gesture_interp));
97 } 98 }
98 #endif 99 #endif
99 100
100 // Touchscreen: use TouchEventConverterEvdev. 101 // Touchscreen: use TouchEventConverterEvdev.
101 if (devinfo.HasTouchscreen()) { 102 if (devinfo.HasTouchscreen()) {
102 std::unique_ptr<TouchEventConverterEvdev> converter( 103 std::unique_ptr<TouchEventConverterEvdev> converter(
103 new TouchEventConverterEvdev(fd, params.path, params.id, devinfo, 104 new TouchEventConverterEvdev(std::move(fd), params.path, params.id,
104 params.dispatcher)); 105 devinfo, params.dispatcher));
105 converter->Initialize(devinfo); 106 converter->Initialize(devinfo);
106 return std::move(converter); 107 return std::move(converter);
107 } 108 }
108 109
109 // Graphics tablet 110 // Graphics tablet
110 if (devinfo.HasTablet()) 111 if (devinfo.HasTablet())
111 return base::WrapUnique<EventConverterEvdev>(new TabletEventConverterEvdev( 112 return base::WrapUnique<EventConverterEvdev>(new TabletEventConverterEvdev(
112 fd, params.path, params.id, params.cursor, devinfo, params.dispatcher)); 113 std::move(fd), params.path, params.id, params.cursor, devinfo,
114 params.dispatcher));
113 115
114 // Everything else: use EventConverterEvdevImpl. 116 // Everything else: use EventConverterEvdevImpl.
115 return base::WrapUnique<EventConverterEvdevImpl>(new EventConverterEvdevImpl( 117 return base::WrapUnique<EventConverterEvdevImpl>(
116 fd, params.path, params.id, devinfo, params.cursor, params.dispatcher)); 118 new EventConverterEvdevImpl(std::move(fd), params.path, params.id,
119 devinfo, params.cursor, params.dispatcher));
117 } 120 }
118 121
119 // Open an input device and construct an EventConverterEvdev. 122 // Open an input device and construct an EventConverterEvdev.
120 std::unique_ptr<EventConverterEvdev> OpenInputDevice( 123 std::unique_ptr<EventConverterEvdev> OpenInputDevice(
121 const OpenInputDeviceParams& params) { 124 const OpenInputDeviceParams& params) {
122 const base::FilePath& path = params.path; 125 const base::FilePath& path = params.path;
123 TRACE_EVENT1("evdev", "OpenInputDevice", "path", path.value()); 126 TRACE_EVENT1("evdev", "OpenInputDevice", "path", path.value());
124 127
125 int fd = open(path.value().c_str(), O_RDWR | O_NONBLOCK); 128 ScopedInputDevice fd(open(path.value().c_str(), O_RDWR | O_NONBLOCK));
126 if (fd < 0) { 129 if (fd.get() < 0) {
127 PLOG(ERROR) << "Cannot open " << path.value(); 130 PLOG(ERROR) << "Cannot open " << path.value();
128 return nullptr; 131 return nullptr;
129 } 132 }
130 133
131 // Use monotonic timestamps for events. The touch code in particular 134 // Use monotonic timestamps for events. The touch code in particular
132 // expects event timestamps to correlate to the monotonic clock 135 // expects event timestamps to correlate to the monotonic clock
133 // (base::TimeTicks). 136 // (base::TimeTicks).
134 unsigned int clk = CLOCK_MONOTONIC; 137 unsigned int clk = CLOCK_MONOTONIC;
135 if (ioctl(fd, EVIOCSCLOCKID, &clk)) 138 if (ioctl(fd.get(), EVIOCSCLOCKID, &clk))
136 PLOG(ERROR) << "failed to set CLOCK_MONOTONIC"; 139 PLOG(ERROR) << "failed to set CLOCK_MONOTONIC";
137 140
138 EventDeviceInfo devinfo; 141 EventDeviceInfo devinfo;
139 if (!devinfo.Initialize(fd, path)) { 142 if (!devinfo.Initialize(fd.get(), path)) {
140 LOG(ERROR) << "Failed to get device information for " << path.value(); 143 LOG(ERROR) << "Failed to get device information for " << path.value();
141 close(fd);
142 return nullptr; 144 return nullptr;
143 } 145 }
144 146
145 return CreateConverter(params, fd, devinfo); 147 return CreateConverter(params, std::move(fd), devinfo);
146 } 148 }
147 149
148 } // namespace 150 } // namespace
149 151
150 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev( 152 InputDeviceFactoryEvdev::InputDeviceFactoryEvdev(
151 std::unique_ptr<DeviceEventDispatcherEvdev> dispatcher, 153 std::unique_ptr<DeviceEventDispatcherEvdev> dispatcher,
152 CursorDelegateEvdev* cursor) 154 CursorDelegateEvdev* cursor)
153 : task_runner_(base::ThreadTaskRunnerHandle::Get()), 155 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
154 cursor_(cursor), 156 cursor_(cursor),
155 #if defined(USE_EVDEV_GESTURES) 157 #if defined(USE_EVDEV_GESTURES)
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 if (enabled == palm_suppression_enabled_) 473 if (enabled == palm_suppression_enabled_)
472 return; 474 return;
473 palm_suppression_enabled_ = enabled; 475 palm_suppression_enabled_ = enabled;
474 476
475 for (const auto& it : converters_) { 477 for (const auto& it : converters_) {
476 it.second->SetEnabled(IsDeviceEnabled(it.second.get())); 478 it.second->SetEnabled(IsDeviceEnabled(it.second.get()));
477 } 479 }
478 } 480 }
479 481
480 } // namespace ui 482 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698