OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "device/hid/hid_connection_linux.h" | 5 #include "device/hid/hid_connection_linux.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <linux/hidraw.h> | 8 #include <linux/hidraw.h> |
9 #include <sys/ioctl.h> | 9 #include <sys/ioctl.h> |
| 10 |
| 11 #include <memory> |
10 #include <string> | 12 #include <string> |
11 #include <utility> | 13 #include <utility> |
12 | 14 |
13 #include "base/bind.h" | 15 #include "base/bind.h" |
14 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
15 #include "base/macros.h" | 17 #include "base/macros.h" |
16 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
17 #include "base/message_loop/message_pump_libevent.h" | 19 #include "base/message_loop/message_pump_libevent.h" |
18 #include "base/posix/eintr_wrapper.h" | 20 #include "base/posix/eintr_wrapper.h" |
19 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
(...skipping 27 matching lines...) Expand all Loading... |
47 has_report_id_ = device_info->has_report_id(); | 49 has_report_id_ = device_info->has_report_id(); |
48 } | 50 } |
49 | 51 |
50 ~FileThreadHelper() override { | 52 ~FileThreadHelper() override { |
51 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
52 base::MessageLoop::current()->RemoveDestructionObserver(this); | 54 base::MessageLoop::current()->RemoveDestructionObserver(this); |
53 } | 55 } |
54 | 56 |
55 // Starts the FileDescriptorWatcher that reads input events from the device. | 57 // Starts the FileDescriptorWatcher that reads input events from the device. |
56 // Must be called on a thread that has a base::MessageLoopForIO. | 58 // Must be called on a thread that has a base::MessageLoopForIO. |
57 static void Start(scoped_ptr<FileThreadHelper> self) { | 59 static void Start(std::unique_ptr<FileThreadHelper> self) { |
58 base::ThreadRestrictions::AssertIOAllowed(); | 60 base::ThreadRestrictions::AssertIOAllowed(); |
59 self->thread_checker_.DetachFromThread(); | 61 self->thread_checker_.DetachFromThread(); |
60 | 62 |
61 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( | 63 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( |
62 self->platform_file_, true, base::MessageLoopForIO::WATCH_READ, | 64 self->platform_file_, true, base::MessageLoopForIO::WATCH_READ, |
63 &self->file_watcher_, self.get())) { | 65 &self->file_watcher_, self.get())) { |
64 HID_LOG(ERROR) << "Failed to start watching device file."; | 66 HID_LOG(ERROR) << "Failed to start watching device file."; |
65 } | 67 } |
66 | 68 |
67 // |self| is now owned by the current message loop. | 69 // |self| is now owned by the current message loop. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 base::File device_file, | 135 base::File device_file, |
134 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) | 136 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) |
135 : HidConnection(device_info), | 137 : HidConnection(device_info), |
136 file_task_runner_(file_task_runner), | 138 file_task_runner_(file_task_runner), |
137 weak_factory_(this) { | 139 weak_factory_(this) { |
138 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 140 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
139 device_file_ = std::move(device_file); | 141 device_file_ = std::move(device_file); |
140 | 142 |
141 // The helper is passed a weak pointer to this connection so that it can be | 143 // The helper is passed a weak pointer to this connection so that it can be |
142 // cleaned up after the connection is closed. | 144 // cleaned up after the connection is closed. |
143 scoped_ptr<FileThreadHelper> helper( | 145 std::unique_ptr<FileThreadHelper> helper( |
144 new FileThreadHelper(device_file_.GetPlatformFile(), device_info, | 146 new FileThreadHelper(device_file_.GetPlatformFile(), device_info, |
145 weak_factory_.GetWeakPtr(), task_runner_)); | 147 weak_factory_.GetWeakPtr(), task_runner_)); |
146 helper_ = helper.get(); | 148 helper_ = helper.get(); |
147 file_task_runner_->PostTask( | 149 file_task_runner_->PostTask( |
148 FROM_HERE, base::Bind(&FileThreadHelper::Start, base::Passed(&helper))); | 150 FROM_HERE, base::Bind(&FileThreadHelper::Start, base::Passed(&helper))); |
149 } | 151 } |
150 | 152 |
151 HidConnectionLinux::~HidConnectionLinux() { | 153 HidConnectionLinux::~HidConnectionLinux() { |
152 DCHECK(helper_ == nullptr); | 154 DCHECK(helper_ == nullptr); |
153 } | 155 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 PendingHidReport report = pending_reports_.front(); | 319 PendingHidReport report = pending_reports_.front(); |
318 | 320 |
319 pending_reports_.pop(); | 321 pending_reports_.pop(); |
320 if (CompleteRead(report.buffer, report.size, read.callback)) { | 322 if (CompleteRead(report.buffer, report.size, read.callback)) { |
321 pending_reads_.pop(); | 323 pending_reads_.pop(); |
322 } | 324 } |
323 } | 325 } |
324 } | 326 } |
325 | 327 |
326 } // namespace device | 328 } // namespace device |
OLD | NEW |