Lines 1-6
Link Here
|
1 |
--- services/device/hid/hid_connection_freebsd.cc.orig 2019-02-01 16:07:39.214979000 +0100 |
1 |
--- services/device/hid/hid_connection_freebsd.cc.orig 2019-03-30 17:42:59.718158000 -0700 |
2 |
+++ services/device/hid/hid_connection_freebsd.cc 2019-02-02 01:21:12.648154000 +0100 |
2 |
+++ services/device/hid/hid_connection_freebsd.cc 2019-03-30 21:54:38.653951000 -0700 |
3 |
@@ -0,0 +1,191 @@ |
3 |
@@ -0,0 +1,240 @@ |
4 |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
4 |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
5 |
+// Use of this source code is governed by a BSD-style license that can be |
5 |
+// Use of this source code is governed by a BSD-style license that can be |
6 |
+// found in the LICENSE file. |
6 |
+// found in the LICENSE file. |
Lines 18-23
Link Here
|
18 |
+#include "base/single_thread_task_runner.h" |
18 |
+#include "base/single_thread_task_runner.h" |
19 |
+#include "base/strings/stringprintf.h" |
19 |
+#include "base/strings/stringprintf.h" |
20 |
+#include "base/task/post_task.h" |
20 |
+#include "base/task/post_task.h" |
|
|
21 |
+#include "base/threading/scoped_blocking_call.h" |
21 |
+#include "base/threading/thread_restrictions.h" |
22 |
+#include "base/threading/thread_restrictions.h" |
22 |
+#include "base/threading/thread_task_runner_handle.h" |
23 |
+#include "base/threading/thread_task_runner_handle.h" |
23 |
+#include "components/device_event_log/device_event_log.h" |
24 |
+#include "components/device_event_log/device_event_log.h" |
Lines 46-56
Link Here
|
46 |
+ void Start() { |
47 |
+ void Start() { |
47 |
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
48 |
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
48 |
+ base::internal::AssertBlockingAllowed(); |
49 |
+ base::internal::AssertBlockingAllowed(); |
|
|
50 |
+ |
51 |
+ file_watcher_ = base::FileDescriptorWatcher::WatchReadable( |
52 |
+ fd_.get(), base::Bind(&BlockingTaskHelper::OnFileCanReadWithoutBlocking, |
53 |
+ base::Unretained(this))); |
49 |
+ } |
54 |
+ } |
50 |
+ |
55 |
+ |
51 |
+ void Write(scoped_refptr<base::RefCountedBytes> buffer, |
56 |
+ void Write(scoped_refptr<base::RefCountedBytes> buffer, |
52 |
+ WriteCallback callback) { |
57 |
+ WriteCallback callback) { |
53 |
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
58 |
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
|
|
59 |
+ base::ScopedBlockingCall scoped_blocking_call( |
60 |
+ base::BlockingType::MAY_BLOCK); |
61 |
+ |
54 |
+ auto data = buffer->front(); |
62 |
+ auto data = buffer->front(); |
55 |
+ size_t size = buffer->size(); |
63 |
+ size_t size = buffer->size(); |
56 |
+ // if report id is 0, it shouldn't be included |
64 |
+ // if report id is 0, it shouldn't be included |
Lines 74-79
Link Here
|
74 |
+ scoped_refptr<base::RefCountedBytes> buffer, |
82 |
+ scoped_refptr<base::RefCountedBytes> buffer, |
75 |
+ ReadCallback callback) { |
83 |
+ ReadCallback callback) { |
76 |
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
84 |
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
|
|
85 |
+ base::ScopedBlockingCall scoped_blocking_call( |
86 |
+ base::BlockingType::MAY_BLOCK); |
77 |
+ struct usb_gen_descriptor ugd; |
87 |
+ struct usb_gen_descriptor ugd; |
78 |
+ ugd.ugd_report_type = UHID_FEATURE_REPORT; |
88 |
+ ugd.ugd_report_type = UHID_FEATURE_REPORT; |
79 |
+ ugd.ugd_data = buffer->front(); |
89 |
+ ugd.ugd_data = buffer->front(); |
Lines 122-127
Link Here
|
122 |
+ } |
132 |
+ } |
123 |
+ |
133 |
+ |
124 |
+ private: |
134 |
+ private: |
|
|
135 |
+ void OnFileCanReadWithoutBlocking() { |
136 |
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
137 |
+ |
138 |
+ scoped_refptr<base::RefCountedBytes> buffer(new base::RefCountedBytes(report_buffer_size_)); |
139 |
+ unsigned char* data = buffer->front(); |
140 |
+ size_t length = report_buffer_size_; |
141 |
+ if (!has_report_id_) { |
142 |
+ // FreeBSD will not prefix the buffer with a report ID if report IDs are not |
143 |
+ // used by the device. Prefix the buffer with 0. |
144 |
+ *data++ = 0; |
145 |
+ length--; |
146 |
+ } |
147 |
+ |
148 |
+ ssize_t bytes_read = HANDLE_EINTR(read(fd_.get(), data, length)); |
149 |
+ if (bytes_read < 0) { |
150 |
+ if (errno != EAGAIN) { |
151 |
+ HID_PLOG(EVENT) << "Read failed"; |
152 |
+ // This assumes that the error is unrecoverable and disables reading |
153 |
+ // from the device until it has been re-opened. |
154 |
+ // TODO(reillyg): Investigate starting and stopping the file descriptor |
155 |
+ // watcher in response to pending read requests so that per-request |
156 |
+ // errors can be returned to the client. |
157 |
+ file_watcher_.reset(); |
158 |
+ } |
159 |
+ return; |
160 |
+ } |
161 |
+ if (!has_report_id_) { |
162 |
+ // Behave as if the byte prefixed above as the the report ID was read. |
163 |
+ bytes_read++; |
164 |
+ } |
165 |
+ |
166 |
+ origin_task_runner_->PostTask( |
167 |
+ FROM_HERE, base::BindOnce(&HidConnectionFreeBSD::ProcessInputReport, |
168 |
+ connection_, buffer, bytes_read)); |
169 |
+ } |
170 |
+ |
125 |
+ SEQUENCE_CHECKER(sequence_checker_); |
171 |
+ SEQUENCE_CHECKER(sequence_checker_); |
126 |
+ base::ScopedFD fd_; |
172 |
+ base::ScopedFD fd_; |
127 |
+ size_t report_buffer_size_; |
173 |
+ size_t report_buffer_size_; |
Lines 128-133
Link Here
|
128 |
+ bool has_report_id_; |
174 |
+ bool has_report_id_; |
129 |
+ base::WeakPtr<HidConnectionFreeBSD> connection_; |
175 |
+ base::WeakPtr<HidConnectionFreeBSD> connection_; |
130 |
+ const scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; |
176 |
+ const scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; |
|
|
177 |
+ std::unique_ptr<base::FileDescriptorWatcher::Controller> file_watcher_; |
131 |
+ |
178 |
+ |
132 |
+ DISALLOW_COPY_AND_ASSIGN(BlockingTaskHelper); |
179 |
+ DISALLOW_COPY_AND_ASSIGN(BlockingTaskHelper); |
133 |
+}; |
180 |
+}; |
Lines 185-190
Link Here
|
185 |
+void HidConnectionFreeBSD::PlatformSendFeatureReport( |
232 |
+void HidConnectionFreeBSD::PlatformSendFeatureReport( |
186 |
+ scoped_refptr<base::RefCountedBytes> buffer, |
233 |
+ scoped_refptr<base::RefCountedBytes> buffer, |
187 |
+ WriteCallback callback) { |
234 |
+ WriteCallback callback) { |
|
|
235 |
+ base::ScopedBlockingCall scoped_blocking_call( |
236 |
+ base::BlockingType::MAY_BLOCK); |
188 |
+ blocking_task_runner_->PostTask( |
237 |
+ blocking_task_runner_->PostTask( |
189 |
+ FROM_HERE, |
238 |
+ FROM_HERE, |
190 |
+ base::BindOnce(&BlockingTaskHelper::SendFeatureReport, |
239 |
+ base::BindOnce(&BlockingTaskHelper::SendFeatureReport, |