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

(-)patch-services_device_hid_hid__connection__freebsd.cc (-15 / +15 lines)
Lines 1-5 Link Here
1
--- services/device/hid/hid_connection_freebsd.cc.orig	2019-05-04 09:19:19 UTC
1
--- services/device/hid/hid_connection_freebsd.cc.orig	2020-07-18 19:40:14.410523000 -0700
2
+++ services/device/hid/hid_connection_freebsd.cc
2
+++ services/device/hid/hid_connection_freebsd.cc	2020-07-21 19:49:59.569331000 -0700
3
@@ -0,0 +1,240 @@
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
Lines 26-34 Link Here
26
+
26
+
27
+namespace device {
27
+namespace device {
28
+
28
+
29
+class HidConnectionFreeBSD::BlockingTaskHelper {
29
+class HidConnectionFreeBSD::BlockingTaskRunnerHelper {
30
+ public:
30
+ public:
31
+  BlockingTaskHelper(base::ScopedFD fd,
31
+  BlockingTaskRunnerHelper(base::ScopedFD fd,
32
+                     scoped_refptr<HidDeviceInfo> device_info,
32
+                     scoped_refptr<HidDeviceInfo> device_info,
33
+                     base::WeakPtr<HidConnectionFreeBSD> connection)
33
+                     base::WeakPtr<HidConnectionFreeBSD> connection)
34
+      : fd_(std::move(fd)),
34
+      : fd_(std::move(fd)),
Lines 40-46 Link Here
40
+    has_report_id_ = device_info->has_report_id();
40
+    has_report_id_ = device_info->has_report_id();
41
+  }
41
+  }
42
+
42
+
43
+  ~BlockingTaskHelper() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); }
43
+  ~BlockingTaskRunnerHelper() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); }
44
+
44
+
45
+  // Starts the FileDescriptorWatcher that reads input events from the device.
45
+  // Starts the FileDescriptorWatcher that reads input events from the device.
46
+  // Must be called on a thread that has a base::MessageLoopForIO.
46
+  // Must be called on a thread that has a base::MessageLoopForIO.
Lines 49-55 Link Here
49
+    base::internal::AssertBlockingAllowed();
49
+    base::internal::AssertBlockingAllowed();
50
+
50
+
51
+    file_watcher_ = base::FileDescriptorWatcher::WatchReadable(
51
+    file_watcher_ = base::FileDescriptorWatcher::WatchReadable(
52
+        fd_.get(), base::Bind(&BlockingTaskHelper::OnFileCanReadWithoutBlocking,
52
+        fd_.get(), base::Bind(&BlockingTaskRunnerHelper::OnFileCanReadWithoutBlocking,
53
+                              base::Unretained(this)));
53
+                              base::Unretained(this)));
54
+  }
54
+  }
55
+
55
+
Lines 176-182 Link Here
176
+  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_;
177
+  std::unique_ptr<base::FileDescriptorWatcher::Controller> file_watcher_;
178
+
178
+
179
+  DISALLOW_COPY_AND_ASSIGN(BlockingTaskHelper);
179
+  DISALLOW_COPY_AND_ASSIGN(BlockingTaskRunnerHelper);
180
+};
180
+};
181
+
181
+
182
+HidConnectionFreeBSD::HidConnectionFreeBSD(
182
+HidConnectionFreeBSD::HidConnectionFreeBSD(
Lines 184-195 Link Here
184
+    base::ScopedFD fd,
184
+    base::ScopedFD fd,
185
+    scoped_refptr<base::SequencedTaskRunner> blocking_task_runner)
185
+    scoped_refptr<base::SequencedTaskRunner> blocking_task_runner)
186
+    : HidConnection(device_info),
186
+    : HidConnection(device_info),
187
+      blocking_task_runner_(std::move(blocking_task_runner)),
187
+      helper_(nullptr, base::OnTaskRunnerDeleter(blocking_task_runner)),
188
+      weak_factory_(this) {
188
+      blocking_task_runner_(std::move(blocking_task_runner)) {
189
+  helper_ = std::make_unique<BlockingTaskHelper>(std::move(fd), device_info,
189
+  helper_.reset(new BlockingTaskRunnerHelper(std::move(fd), device_info,
190
+                                                 weak_factory_.GetWeakPtr());
190
+                                                 weak_factory_.GetWeakPtr()));
191
+  blocking_task_runner_->PostTask(
191
+  blocking_task_runner_->PostTask(
192
+      FROM_HERE, base::BindOnce(&BlockingTaskHelper::Start,
192
+      FROM_HERE, base::BindOnce(&BlockingTaskRunnerHelper::Start,
193
+                                base::Unretained(helper_.get())));
193
+                                base::Unretained(helper_.get())));
194
+}
194
+}
195
+
195
+
Lines 208-214 Link Here
208
+
208
+
209
+  blocking_task_runner_->PostTask(
209
+  blocking_task_runner_->PostTask(
210
+      FROM_HERE,
210
+      FROM_HERE,
211
+      base::BindOnce(&BlockingTaskHelper::Write, base::Unretained(helper_.get()),
211
+      base::BindOnce(&BlockingTaskRunnerHelper::Write, base::Unretained(helper_.get()),
212
+                 buffer, std::move(callback)));
212
+                 buffer, std::move(callback)));
213
+}
213
+}
214
+
214
+
Lines 224-230 Link Here
224
+
224
+
225
+  blocking_task_runner_->PostTask(
225
+  blocking_task_runner_->PostTask(
226
+      FROM_HERE,
226
+      FROM_HERE,
227
+      base::BindOnce(&BlockingTaskHelper::GetFeatureReport,
227
+      base::BindOnce(&BlockingTaskRunnerHelper::GetFeatureReport,
228
+                 base::Unretained(helper_.get()), report_id,
228
+                 base::Unretained(helper_.get()), report_id,
229
+                 buffer, std::move(callback)));
229
+                 buffer, std::move(callback)));
230
+}
230
+}
Lines 236-242 Link Here
236
+      FROM_HERE, base::BlockingType::MAY_BLOCK);
236
+      FROM_HERE, base::BlockingType::MAY_BLOCK);
237
+  blocking_task_runner_->PostTask(
237
+  blocking_task_runner_->PostTask(
238
+      FROM_HERE,
238
+      FROM_HERE,
239
+      base::BindOnce(&BlockingTaskHelper::SendFeatureReport,
239
+      base::BindOnce(&BlockingTaskRunnerHelper::SendFeatureReport,
240
+                 base::Unretained(helper_.get()), buffer, std::move(callback)));
240
+                 base::Unretained(helper_.get()), buffer, std::move(callback)));
241
+}
241
+}
242
+
242
+
(-)patch-services_device_hid_hid__connection__freebsd.h (-11 / +8 lines)
Lines 1-6 Link Here
1
--- services/device/hid/hid_connection_freebsd.h.orig	2019-05-01 15:21:27 UTC
1
--- services/device/hid/hid_connection_freebsd.h.orig	2020-07-18 19:40:14.412550000 -0700
2
+++ services/device/hid/hid_connection_freebsd.h
2
+++ services/device/hid/hid_connection_freebsd.h	2020-07-21 19:15:28.613027000 -0700
3
@@ -0,0 +1,68 @@
3
@@ -0,0 +1,65 @@
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 13-22 Link Here
13
+
13
+
14
+#include "base/files/scoped_file.h"
14
+#include "base/files/scoped_file.h"
15
+#include "base/macros.h"
15
+#include "base/macros.h"
16
+#include "base/memory/ptr_util.h"
16
+#include "base/memory/weak_ptr.h"
17
+#include "base/memory/ref_counted_memory.h"
17
+#include "base/memory/ref_counted_memory.h"
18
+#include "base/memory/weak_ptr.h"
18
+#include "base/sequenced_task_runner.h"
19
+#include "base/sequence_checker.h"
20
+#include "services/device/hid/hid_connection.h"
19
+#include "services/device/hid/hid_connection.h"
21
+
20
+
22
+namespace base {
21
+namespace base {
Lines 38-44 Link Here
38
+
37
+
39
+ private:
38
+ private:
40
+  friend class base::RefCountedThreadSafe<HidConnectionFreeBSD>;
39
+  friend class base::RefCountedThreadSafe<HidConnectionFreeBSD>;
41
+  class BlockingTaskHelper;
40
+  class BlockingTaskRunnerHelper;
42
+
41
+
43
+  ~HidConnectionFreeBSD() override;
42
+  ~HidConnectionFreeBSD() override;
44
+
43
+
Lines 54-68 Link Here
54
+  // |helper_| lives on the sequence to which |blocking_task_runner_| posts
53
+  // |helper_| lives on the sequence to which |blocking_task_runner_| posts
55
+  // tasks so all calls must be posted there including this object's
54
+  // tasks so all calls must be posted there including this object's
56
+  // destruction.
55
+  // destruction.
57
+  std::unique_ptr<BlockingTaskHelper> helper_;
56
+  std::unique_ptr<BlockingTaskRunnerHelper, base::OnTaskRunnerDeleter> helper_;
58
+
57
+
59
+  const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
58
+  const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
60
+  const scoped_refptr<base::SequencedTaskRunner> task_runner_;
59
+  const scoped_refptr<base::SequencedTaskRunner> task_runner_;
61
+
60
+
62
+  SEQUENCE_CHECKER(sequence_checker_);
61
+  base::WeakPtrFactory<HidConnectionFreeBSD> weak_factory_{this};
63
+
62
+
64
+  base::WeakPtrFactory<HidConnectionFreeBSD> weak_factory_;
65
+
66
+  DISALLOW_COPY_AND_ASSIGN(HidConnectionFreeBSD);
63
+  DISALLOW_COPY_AND_ASSIGN(HidConnectionFreeBSD);
67
+};
64
+};
68
+
65
+
(-)patch-services_device_hid_hid__service__freebsd.cc (-17 / +16 lines)
Lines 1-6 Link Here
1
--- services/device/hid/hid_service_freebsd.cc.orig	2020-03-17 15:11:01 UTC
1
--- services/device/hid/hid_service_freebsd.cc.orig	2020-07-18 19:40:14.415772000 -0700
2
+++ services/device/hid/hid_service_freebsd.cc
2
+++ services/device/hid/hid_service_freebsd.cc	2020-07-21 20:00:55.322907000 -0700
3
@@ -0,0 +1,383 @@
3
@@ -0,0 +1,382 @@
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 48-54 Link Here
48
+        callback(std::move(callback)),
48
+        callback(std::move(callback)),
49
+        task_runner(base::ThreadTaskRunnerHandle::Get()),
49
+        task_runner(base::ThreadTaskRunnerHandle::Get()),
50
+        blocking_task_runner(
50
+        blocking_task_runner(
51
+            base::CreateSequencedTaskRunner(kBlockingTaskTraits)) {}
51
+            base::ThreadPool::CreateSequencedTaskRunner(kBlockingTaskTraits)) {}
52
+  ~ConnectParams() {}
52
+  ~ConnectParams() {}
53
+
53
+
54
+  scoped_refptr<HidDeviceInfo> device_info;
54
+  scoped_refptr<HidDeviceInfo> device_info;
Lines 58-66 Link Here
58
+  base::ScopedFD fd;
58
+  base::ScopedFD fd;
59
+};
59
+};
60
+
60
+
61
+class HidServiceFreeBSD::BlockingTaskHelper {
61
+class HidServiceFreeBSD::BlockingTaskRunnerHelper {
62
+ public:
62
+ public:
63
+  BlockingTaskHelper(base::WeakPtr<HidServiceFreeBSD> service)
63
+  BlockingTaskRunnerHelper(base::WeakPtr<HidServiceFreeBSD> service)
64
+      : service_(std::move(service)),
64
+      : service_(std::move(service)),
65
+        task_runner_(base::ThreadTaskRunnerHandle::Get()) {
65
+        task_runner_(base::ThreadTaskRunnerHandle::Get()) {
66
+    DETACH_FROM_SEQUENCE(sequence_checker_);
66
+    DETACH_FROM_SEQUENCE(sequence_checker_);
Lines 69-75 Link Here
69
+    devd_buffer_ = new net::IOBufferWithSize(1024);
69
+    devd_buffer_ = new net::IOBufferWithSize(1024);
70
+  }
70
+  }
71
+
71
+
72
+  ~BlockingTaskHelper() {
72
+  ~BlockingTaskRunnerHelper() {
73
+  }
73
+  }
74
+
74
+
75
+  void Start() {
75
+  void Start() {
Lines 173-179 Link Here
173
+        report_descriptor,
173
+        report_descriptor,
174
+	device_node));
174
+	device_node));
175
+
175
+
176
+    task_runner_->PostTask(FROM_HERE, base::Bind(&HidServiceFreeBSD::AddDevice,
176
+    task_runner_->PostTask(FROM_HERE, base::BindOnce(&HidServiceFreeBSD::AddDevice,
177
+                                                 service_, device_info));
177
+                                                 service_, device_info));
178
+  }
178
+  }
179
+
179
+
Lines 231-237 Link Here
231
+
231
+
232
+    devd_fd_.reset(devd_fd);
232
+    devd_fd_.reset(devd_fd);
233
+    file_watcher_ = base::FileDescriptorWatcher::WatchReadable(
233
+    file_watcher_ = base::FileDescriptorWatcher::WatchReadable(
234
+        devd_fd_.get(), base::Bind(&BlockingTaskHelper::OnDevdMessageCanBeRead,
234
+        devd_fd_.get(), base::Bind(&BlockingTaskRunnerHelper::OnDevdMessageCanBeRead,
235
+                                   base::Unretained(this)));
235
+                                   base::Unretained(this)));
236
+  }
236
+  }
237
+
237
+
Lines 265-271 Link Here
265
+          if (permissions_checks_attempts_.find(device_name) == permissions_checks_attempts_.end()) {
265
+          if (permissions_checks_attempts_.find(device_name) == permissions_checks_attempts_.end()) {
266
+            permissions_checks_attempts_.insert(std::pair<std::string, int>(device_name, kMaxPermissionChecks));
266
+            permissions_checks_attempts_.insert(std::pair<std::string, int>(device_name, kMaxPermissionChecks));
267
+            timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
267
+            timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
268
+                          this, &BlockingTaskHelper::CheckPendingPermissionChange);
268
+                          this, &BlockingTaskRunnerHelper::CheckPendingPermissionChange);
269
+          }
269
+          }
270
+        }
270
+        }
271
+      }
271
+      }
Lines 298-315 Link Here
298
+  scoped_refptr<net::IOBufferWithSize> devd_buffer_;
298
+  scoped_refptr<net::IOBufferWithSize> devd_buffer_;
299
+  std::map<std::string, int> permissions_checks_attempts_;
299
+  std::map<std::string, int> permissions_checks_attempts_;
300
+
300
+
301
+  DISALLOW_COPY_AND_ASSIGN(BlockingTaskHelper);
301
+  DISALLOW_COPY_AND_ASSIGN(BlockingTaskRunnerHelper);
302
+};
302
+};
303
+
303
+
304
+HidServiceFreeBSD::HidServiceFreeBSD()
304
+HidServiceFreeBSD::HidServiceFreeBSD()
305
+    : task_runner_(base::ThreadTaskRunnerHandle::Get()),
305
+    : blocking_task_runner_(
306
+      blocking_task_runner_(
306
+          base::ThreadPool::CreateSequencedTaskRunner(kBlockingTaskTraits)),
307
+          base::CreateSequencedTaskRunner(kBlockingTaskTraits)),
307
+      helper_(nullptr, base::OnTaskRunnerDeleter(blocking_task_runner_)) {
308
+      weak_factory_(this) {
308
+  helper_.reset(new BlockingTaskRunnerHelper(weak_factory_.GetWeakPtr()));
309
+  helper_ = std::make_unique<BlockingTaskHelper>(weak_factory_.GetWeakPtr());
310
+  blocking_task_runner_->PostTask(
309
+  blocking_task_runner_->PostTask(
311
+      FROM_HERE,
310
+      FROM_HERE,
312
+      base::Bind(&BlockingTaskHelper::Start, base::Unretained(helper_.get())));
311
+      base::BindOnce(&BlockingTaskRunnerHelper::Start, base::Unretained(helper_.get())));
313
+}
312
+}
314
+
313
+
315
+HidServiceFreeBSD::~HidServiceFreeBSD() {
314
+HidServiceFreeBSD::~HidServiceFreeBSD() {
(-)patch-services_device_hid_hid__service__freebsd.h (-7 / +6 lines)
Lines 1-6 Link Here
1
--- services/device/hid/hid_service_freebsd.h.orig	2020-03-17 15:11:01 UTC
1
--- services/device/hid/hid_service_freebsd.h.orig	2020-07-18 19:40:14.418200000 -0700
2
+++ services/device/hid/hid_service_freebsd.h
2
+++ services/device/hid/hid_service_freebsd.h	2020-07-21 19:52:08.796704000 -0700
3
@@ -0,0 +1,47 @@
3
@@ -0,0 +1,46 @@
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-46 Link Here
30
+
30
+
31
+ private:
31
+ private:
32
+  struct ConnectParams;
32
+  struct ConnectParams;
33
+  class BlockingTaskHelper;
33
+  class BlockingTaskRunnerHelper;
34
+
34
+
35
+  static void OpenOnBlockingThread(std::unique_ptr<ConnectParams> params);
35
+  static void OpenOnBlockingThread(std::unique_ptr<ConnectParams> params);
36
+  static void FinishOpen(std::unique_ptr<ConnectParams> params);
36
+  static void FinishOpen(std::unique_ptr<ConnectParams> params);
37
+
37
+
38
+  const scoped_refptr<base::SequencedTaskRunner> task_runner_;
39
+  const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
38
+  const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
40
+  // |helper_| lives on the sequence |blocking_task_runner_| posts to and holds
39
+  // |helper_| lives on the sequence |blocking_task_runner_| posts to and holds
41
+  // a weak reference back to the service that owns it.
40
+  // a weak reference back to the service that owns it.
42
+  std::unique_ptr<BlockingTaskHelper> helper_;
41
+  std::unique_ptr<BlockingTaskRunnerHelper, base::OnTaskRunnerDeleter> helper_;
43
+  base::WeakPtrFactory<HidServiceFreeBSD> weak_factory_;
42
+  base::WeakPtrFactory<HidServiceFreeBSD> weak_factory_{this};
44
+
43
+
45
+  DISALLOW_COPY_AND_ASSIGN(HidServiceFreeBSD);
44
+  DISALLOW_COPY_AND_ASSIGN(HidServiceFreeBSD);
46
+};
45
+};

Return to bug 247744