View | Details | Raw Unified | Return to bug 236911
Collapse All | Expand All

(-)www/chromium/files/patch-services_device_hid_hid__connection__freebsd.cc (-3 / +52 lines)
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,
(-)www/chromium/files/patch-services_device_hid_hid__connection__freebsd.h (-5 / +3 lines)
Lines 1-6 Link Here
1
--- services/device/hid/hid_connection_freebsd.h.orig	2018-12-27 21:14:54.190483000 +0100
1
--- services/device/hid/hid_connection_freebsd.h.orig	2019-03-30 17:42:59.719257000 -0700
2
+++ services/device/hid/hid_connection_freebsd.h	2018-12-28 15:27:41.475526000 +0100
2
+++ services/device/hid/hid_connection_freebsd.h	2019-03-30 21:53:54.126040000 -0700
3
@@ -0,0 +1,70 @@
3
@@ -0,0 +1,68 @@
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 50-57 Link Here
50
+                                ReadCallback callback) override;
50
+                                ReadCallback callback) override;
51
+  void PlatformSendFeatureReport(scoped_refptr<base::RefCountedBytes> buffer,
51
+  void PlatformSendFeatureReport(scoped_refptr<base::RefCountedBytes> buffer,
52
+                                 WriteCallback callback) override;
52
+                                 WriteCallback callback) override;
53
+  void ProcessInputReport(scoped_refptr<base::RefCountedBytes> buffer,
54
+                          size_t size);
55
+
53
+
56
+  // |helper_| lives on the sequence to which |blocking_task_runner_| posts
54
+  // |helper_| lives on the sequence to which |blocking_task_runner_| posts
57
+  // tasks so all calls must be posted there including this object's
55
+  // tasks so all calls must be posted there including this object's
(-)www/chromium/files/patch-services_device_hid_hid__service__freebsd.cc (-7 / +9 lines)
Lines 1-6 Link Here
1
--- services/device/hid/hid_service_freebsd.cc.orig	2019-02-01 16:07:39.219688000 +0100
1
--- services/device/hid/hid_service_freebsd.cc.orig	2019-03-30 17:42:59.721025000 -0700
2
+++ services/device/hid/hid_service_freebsd.cc	2019-02-02 00:41:58.747111000 +0100
2
+++ services/device/hid/hid_service_freebsd.cc	2019-03-30 22:02:19.316167000 -0700
3
@@ -0,0 +1,371 @@
3
@@ -0,0 +1,373 @@
4
+// Copyright 2014 The Chromium Authors. All rights reserved.
4
+// Copyright 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 30-36 Link Here
30
+#include "base/strings/string_util.h"
30
+#include "base/strings/string_util.h"
31
+#include "base/strings/string_split.h"
31
+#include "base/strings/string_split.h"
32
+#include "base/task/post_task.h"
32
+#include "base/task/post_task.h"
33
+#include "base/threading/thread_restrictions.h"
33
+#include "base/threading/scoped_blocking_call.h"
34
+#include "base/threading/thread_task_runner_handle.h"
34
+#include "base/threading/thread_task_runner_handle.h"
35
+#include "components/device_event_log/device_event_log.h"
35
+#include "components/device_event_log/device_event_log.h"
36
+#include "services/device/hid/hid_connection_freebsd.h"
36
+#include "services/device/hid/hid_connection_freebsd.h"
Lines 71-77 Link Here
71
+  }
71
+  }
72
+
72
+
73
+  void Start() {
73
+  void Start() {
74
+    base::internal::AssertBlockingAllowed();
75
+    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
74
+    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
76
+
75
+
77
+    const base::FilePath kDevRoot("/dev");
76
+    const base::FilePath kDevRoot("/dev");
Lines 111-116 Link Here
111
+  }
110
+  }
112
+
111
+
113
+  void OnDeviceAdded(std::string device_id) {
112
+  void OnDeviceAdded(std::string device_id) {
113
+    base::ScopedBlockingCall scoped_blocking_call(
114
+        base::BlockingType::MAY_BLOCK);
114
+    std::string device_node = "/dev/" + device_id;
115
+    std::string device_node = "/dev/" + device_id;
115
+    uint16_t vendor_id = 0xffff;
116
+    uint16_t vendor_id = 0xffff;
116
+    uint16_t product_id = 0xffff;
117
+    uint16_t product_id = 0xffff;
Lines 169-174 Link Here
169
+  }
170
+  }
170
+
171
+
171
+  void OnDeviceRemoved(std::string device_id) {
172
+  void OnDeviceRemoved(std::string device_id) {
173
+    base::ScopedBlockingCall scoped_blocking_call(
174
+        base::BlockingType::MAY_BLOCK);
172
+    task_runner_->PostTask(
175
+    task_runner_->PostTask(
173
+        FROM_HERE, base::Bind(&HidServiceFreeBSD::RemoveDevice, service_,
176
+        FROM_HERE, base::Bind(&HidServiceFreeBSD::RemoveDevice, service_,
174
+                              device_id));
177
+                              device_id));
Lines 312-318 Link Here
312
+// static
315
+// static
313
+void HidServiceFreeBSD::OpenOnBlockingThread(
316
+void HidServiceFreeBSD::OpenOnBlockingThread(
314
+    std::unique_ptr<ConnectParams> params) {
317
+    std::unique_ptr<ConnectParams> params) {
315
+  base::internal::AssertBlockingAllowed();
318
+  base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
316
+  scoped_refptr<base::SequencedTaskRunner> task_runner = params->task_runner;
319
+  scoped_refptr<base::SequencedTaskRunner> task_runner = params->task_runner;
317
+
320
+
318
+  base::FilePath device_path(params->device_info->device_node());
321
+  base::FilePath device_path(params->device_info->device_node());
Lines 355-361 Link Here
355
+
358
+
356
+// static
359
+// static
357
+void HidServiceFreeBSD::FinishOpen(std::unique_ptr<ConnectParams> params) {
360
+void HidServiceFreeBSD::FinishOpen(std::unique_ptr<ConnectParams> params) {
358
+  base::internal::AssertBlockingAllowed();
359
+  scoped_refptr<base::SequencedTaskRunner> task_runner = params->task_runner;
361
+  scoped_refptr<base::SequencedTaskRunner> task_runner = params->task_runner;
360
+
362
+
361
+  task_runner->PostTask(
363
+  task_runner->PostTask(

Return to bug 236911