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

Side by Side Diff: device/hid/hid_connection_linux.cc

Issue 1874313002: Convert device to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
« no previous file with comments | « device/hid/device_monitor_linux.cc ('k') | device/hid/hid_connection_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « device/hid/device_monitor_linux.cc ('k') | device/hid/hid_connection_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698