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

Side by Side Diff: ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.cc

Issue 2639043002: Fix double-close in EventConverterEvdevImpl (Closed)
Patch Set: remove base::debug::Alias Created 3 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/libgestures_glue/event_reader_libevdev_cros.h" 5 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <libevdev/libevdev.h> 8 #include <libevdev/libevdev.h>
9 #include <linux/input.h> 9 #include <linux/input.h>
10 #include <utility> 10 #include <utility>
(...skipping 10 matching lines...) Expand all
21 std::string FormatLog(const char* fmt, va_list args) { 21 std::string FormatLog(const char* fmt, va_list args) {
22 std::string msg = base::StringPrintV(fmt, args); 22 std::string msg = base::StringPrintV(fmt, args);
23 if (!msg.empty() && msg.back() == '\n') 23 if (!msg.empty() && msg.back() == '\n')
24 msg.pop_back(); 24 msg.pop_back();
25 return msg; 25 return msg;
26 } 26 }
27 27
28 } // namespace 28 } // namespace
29 29
30 EventReaderLibevdevCros::EventReaderLibevdevCros( 30 EventReaderLibevdevCros::EventReaderLibevdevCros(
31 int fd, 31 ScopedInputDevice fd,
32 const base::FilePath& path, 32 const base::FilePath& path,
33 int id, 33 int id,
34 const EventDeviceInfo& devinfo, 34 const EventDeviceInfo& devinfo,
35 std::unique_ptr<Delegate> delegate) 35 std::unique_ptr<Delegate> delegate)
36 : EventConverterEvdev(fd, 36 : EventConverterEvdev(fd.get(),
37 path, 37 path,
38 id, 38 id,
39 devinfo.device_type(), 39 devinfo.device_type(),
40 devinfo.name(), 40 devinfo.name(),
41 devinfo.vendor_id(), 41 devinfo.vendor_id(),
42 devinfo.product_id()), 42 devinfo.product_id()),
43 has_keyboard_(devinfo.HasKeyboard()), 43 has_keyboard_(devinfo.HasKeyboard()),
44 has_mouse_(devinfo.HasMouse()), 44 has_mouse_(devinfo.HasMouse()),
45 has_touchpad_(devinfo.HasTouchpad()), 45 has_touchpad_(devinfo.HasTouchpad()),
46 has_caps_lock_led_(devinfo.HasLedEvent(LED_CAPSL)), 46 has_caps_lock_led_(devinfo.HasLedEvent(LED_CAPSL)),
47 delegate_(std::move(delegate)) { 47 delegate_(std::move(delegate)) {
48 // This class assumes it does not deal with internal keyboards. 48 // This class assumes it does not deal with internal keyboards.
49 CHECK(!has_keyboard_ || type() != INPUT_DEVICE_INTERNAL); 49 CHECK(!has_keyboard_ || type() != INPUT_DEVICE_INTERNAL);
50 50
51 memset(&evdev_, 0, sizeof(evdev_)); 51 memset(&evdev_, 0, sizeof(evdev_));
52 evdev_.log = OnLogMessage; 52 evdev_.log = OnLogMessage;
53 evdev_.log_udata = this; 53 evdev_.log_udata = this;
54 evdev_.syn_report = OnSynReport; 54 evdev_.syn_report = OnSynReport;
55 evdev_.syn_report_udata = this; 55 evdev_.syn_report_udata = this;
56 evdev_.fd = fd; 56 evdev_.fd = fd.release();
kpschoedel 2017/01/18 21:31:07 evdev_ owns the fd now, and EvdevClose closes it?
spang 2017/01/18 22:05:37 Correct. https://cs.corp.google.com/chromeos_publi
57 57
58 memset(&evstate_, 0, sizeof(evstate_)); 58 memset(&evstate_, 0, sizeof(evstate_));
59 evdev_.evstate = &evstate_; 59 evdev_.evstate = &evstate_;
60 Event_Init(&evdev_); 60 Event_Init(&evdev_);
61 61
62 Event_Open(&evdev_); 62 Event_Open(&evdev_);
63 63
64 delegate_->OnLibEvdevCrosOpen(&evdev_, &evstate_); 64 delegate_->OnLibEvdevCrosOpen(&evdev_, &evstate_);
65 } 65 }
66 66
67 EventReaderLibevdevCros::~EventReaderLibevdevCros() { 67 EventReaderLibevdevCros::~EventReaderLibevdevCros() {
68 DCHECK(!watching_); 68 DCHECK(!watching_);
69 EvdevClose(&evdev_); 69 EvdevClose(&evdev_);
70 fd_ = -1;
71 } 70 }
72 71
73 EventReaderLibevdevCros::Delegate::~Delegate() {} 72 EventReaderLibevdevCros::Delegate::~Delegate() {}
74 73
75 void EventReaderLibevdevCros::OnFileCanReadWithoutBlocking(int fd) { 74 void EventReaderLibevdevCros::OnFileCanReadWithoutBlocking(int fd) {
76 TRACE_EVENT1("evdev", "EventReaderLibevdevCros::OnFileCanReadWithoutBlocking", 75 TRACE_EVENT1("evdev", "EventReaderLibevdevCros::OnFileCanReadWithoutBlocking",
77 "fd", fd); 76 "fd", fd);
78 77
79 if (EvdevRead(&evdev_)) { 78 if (EvdevRead(&evdev_)) {
80 if (errno == EINTR || errno == EAGAIN) 79 if (errno == EINTR || errno == EAGAIN)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 if (level >= LOGLEVEL_ERROR) 126 if (level >= LOGLEVEL_ERROR)
128 LOG(ERROR) << "libevdev: " << FormatLog(fmt, args); 127 LOG(ERROR) << "libevdev: " << FormatLog(fmt, args);
129 else if (level >= LOGLEVEL_WARNING) 128 else if (level >= LOGLEVEL_WARNING)
130 LOG(WARNING) << "libevdev: " << FormatLog(fmt, args); 129 LOG(WARNING) << "libevdev: " << FormatLog(fmt, args);
131 else 130 else
132 VLOG(3) << "libevdev: " << FormatLog(fmt, args); 131 VLOG(3) << "libevdev: " << FormatLog(fmt, args);
133 va_end(args); 132 va_end(args);
134 } 133 }
135 134
136 } // namespace ui 135 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698