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

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

Issue 825523003: Convert HidDeviceInfo from a struct to a refcounted class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added TODO to remove friend class definitions. Created 5 years, 11 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/hid_connection_win.h ('k') | device/hid/hid_device_filter.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_win.h" 5 #include "device/hid/hid_connection_win.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 callback_.Run(this, true); 96 callback_.Run(this, true);
97 Release(); 97 Release();
98 } 98 }
99 99
100 void PendingHidTransfer::WillDestroyCurrentMessageLoop() { 100 void PendingHidTransfer::WillDestroyCurrentMessageLoop() {
101 watcher_.StopWatching(); 101 watcher_.StopWatching();
102 callback_.Run(this, false); 102 callback_.Run(this, false);
103 } 103 }
104 104
105 HidConnectionWin::HidConnectionWin(const HidDeviceInfo& device_info, 105 HidConnectionWin::HidConnectionWin(scoped_refptr<HidDeviceInfo> device_info,
106 base::win::ScopedHandle file) 106 base::win::ScopedHandle file)
107 : HidConnection(device_info) { 107 : HidConnection(device_info) {
108 file_ = file.Pass(); 108 file_ = file.Pass();
109 } 109 }
110 110
111 HidConnectionWin::~HidConnectionWin() { 111 HidConnectionWin::~HidConnectionWin() {
112 } 112 }
113 113
114 void HidConnectionWin::PlatformClose() { 114 void HidConnectionWin::PlatformClose() {
115 CancelIo(file_.Get()); 115 CancelIo(file_.Get());
116 } 116 }
117 117
118 void HidConnectionWin::PlatformRead( 118 void HidConnectionWin::PlatformRead(
119 const HidConnection::ReadCallback& callback) { 119 const HidConnection::ReadCallback& callback) {
120 // Windows will always include the report ID (including zero if report IDs 120 // Windows will always include the report ID (including zero if report IDs
121 // are not in use) in the buffer. 121 // are not in use) in the buffer.
122 scoped_refptr<net::IOBufferWithSize> buffer = new net::IOBufferWithSize( 122 scoped_refptr<net::IOBufferWithSize> buffer = new net::IOBufferWithSize(
123 base::checked_cast<int>(device_info().max_input_report_size + 1)); 123 base::checked_cast<int>(device_info()->max_input_report_size() + 1));
124 scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer( 124 scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer(
125 buffer, 125 buffer,
126 base::Bind(&HidConnectionWin::OnReadComplete, this, buffer, callback))); 126 base::Bind(&HidConnectionWin::OnReadComplete, this, buffer, callback)));
127 transfers_.insert(transfer); 127 transfers_.insert(transfer);
128 transfer->TakeResultFromWindowsAPI( 128 transfer->TakeResultFromWindowsAPI(
129 ReadFile(file_.Get(), 129 ReadFile(file_.Get(),
130 buffer->data(), 130 buffer->data(),
131 static_cast<DWORD>(buffer->size()), 131 static_cast<DWORD>(buffer->size()),
132 NULL, 132 NULL,
133 transfer->GetOverlapped())); 133 transfer->GetOverlapped()));
(...skipping 11 matching lines...) Expand all
145 buffer->data(), 145 buffer->data(),
146 static_cast<DWORD>(size), 146 static_cast<DWORD>(size),
147 NULL, 147 NULL,
148 transfer->GetOverlapped())); 148 transfer->GetOverlapped()));
149 } 149 }
150 150
151 void HidConnectionWin::PlatformGetFeatureReport(uint8_t report_id, 151 void HidConnectionWin::PlatformGetFeatureReport(uint8_t report_id,
152 const ReadCallback& callback) { 152 const ReadCallback& callback) {
153 // The first byte of the destination buffer is the report ID being requested. 153 // The first byte of the destination buffer is the report ID being requested.
154 scoped_refptr<net::IOBufferWithSize> buffer = new net::IOBufferWithSize( 154 scoped_refptr<net::IOBufferWithSize> buffer = new net::IOBufferWithSize(
155 base::checked_cast<int>(device_info().max_feature_report_size + 1)); 155 base::checked_cast<int>(device_info()->max_feature_report_size() + 1));
156 buffer->data()[0] = report_id; 156 buffer->data()[0] = report_id;
157 157
158 scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer( 158 scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer(
159 buffer, 159 buffer,
160 base::Bind( 160 base::Bind(
161 &HidConnectionWin::OnReadFeatureComplete, this, buffer, callback))); 161 &HidConnectionWin::OnReadFeatureComplete, this, buffer, callback)));
162 transfers_.insert(transfer); 162 transfers_.insert(transfer);
163 transfer->TakeResultFromWindowsAPI( 163 transfer->TakeResultFromWindowsAPI(
164 DeviceIoControl(file_.Get(), 164 DeviceIoControl(file_.Get(),
165 IOCTL_HID_GET_FEATURE, 165 IOCTL_HID_GET_FEATURE,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 if (GetOverlappedResult( 241 if (GetOverlappedResult(
242 file_.Get(), transfer->GetOverlapped(), &bytes_transferred, FALSE)) { 242 file_.Get(), transfer->GetOverlapped(), &bytes_transferred, FALSE)) {
243 callback.Run(true); 243 callback.Run(true);
244 } else { 244 } else {
245 VPLOG(1) << "HID write failed"; 245 VPLOG(1) << "HID write failed";
246 callback.Run(false); 246 callback.Run(false);
247 } 247 }
248 } 248 }
249 249
250 } // namespace device 250 } // namespace device
OLDNEW
« no previous file with comments | « device/hid/hid_connection_win.h ('k') | device/hid/hid_device_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698