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

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

Issue 656583003: Fix type truncation warnings in HID code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile Created 6 years, 2 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_unittest.cc ('k') | device/hid/hid_device_info.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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/numerics/safe_conversions.h"
12 #include "base/profiler/scoped_profile.h" 13 #include "base/profiler/scoped_profile.h"
13 #include "base/win/object_watcher.h" 14 #include "base/win/object_watcher.h"
14 15
15 #define INITGUID 16 #define INITGUID
16 17
17 #include <windows.h> 18 #include <windows.h>
18 #include <hidclass.h> 19 #include <hidclass.h>
19 20
20 extern "C" { 21 extern "C" {
21 #include <hidsdi.h> 22 #include <hidsdi.h>
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 129 }
129 130
130 void HidConnectionWin::PlatformClose() { 131 void HidConnectionWin::PlatformClose() {
131 CancelIo(file_.Get()); 132 CancelIo(file_.Get());
132 } 133 }
133 134
134 void HidConnectionWin::PlatformRead( 135 void HidConnectionWin::PlatformRead(
135 const HidConnection::ReadCallback& callback) { 136 const HidConnection::ReadCallback& callback) {
136 // Windows will always include the report ID (including zero if report IDs 137 // Windows will always include the report ID (including zero if report IDs
137 // are not in use) in the buffer. 138 // are not in use) in the buffer.
138 scoped_refptr<net::IOBufferWithSize> buffer = 139 scoped_refptr<net::IOBufferWithSize> buffer = new net::IOBufferWithSize(
139 new net::IOBufferWithSize(device_info().max_input_report_size + 1); 140 base::checked_cast<int>(device_info().max_input_report_size + 1));
140 scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer( 141 scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer(
141 buffer, 142 buffer,
142 base::Bind(&HidConnectionWin::OnReadComplete, this, buffer, callback))); 143 base::Bind(&HidConnectionWin::OnReadComplete, this, buffer, callback)));
143 transfers_.insert(transfer); 144 transfers_.insert(transfer);
144 transfer->TakeResultFromWindowsAPI( 145 transfer->TakeResultFromWindowsAPI(
145 ReadFile(file_.Get(), 146 ReadFile(file_.Get(),
146 buffer->data(), 147 buffer->data(),
147 static_cast<DWORD>(buffer->size()), 148 static_cast<DWORD>(buffer->size()),
148 NULL, 149 NULL,
149 transfer->GetOverlapped())); 150 transfer->GetOverlapped()));
(...skipping 10 matching lines...) Expand all
160 transfer->TakeResultFromWindowsAPI(WriteFile(file_.Get(), 161 transfer->TakeResultFromWindowsAPI(WriteFile(file_.Get(),
161 buffer->data(), 162 buffer->data(),
162 static_cast<DWORD>(size), 163 static_cast<DWORD>(size),
163 NULL, 164 NULL,
164 transfer->GetOverlapped())); 165 transfer->GetOverlapped()));
165 } 166 }
166 167
167 void HidConnectionWin::PlatformGetFeatureReport(uint8_t report_id, 168 void HidConnectionWin::PlatformGetFeatureReport(uint8_t report_id,
168 const ReadCallback& callback) { 169 const ReadCallback& callback) {
169 // The first byte of the destination buffer is the report ID being requested. 170 // The first byte of the destination buffer is the report ID being requested.
170 scoped_refptr<net::IOBufferWithSize> buffer = 171 scoped_refptr<net::IOBufferWithSize> buffer = new net::IOBufferWithSize(
171 new net::IOBufferWithSize(device_info().max_feature_report_size + 1); 172 base::checked_cast<int>(device_info().max_feature_report_size + 1));
172 buffer->data()[0] = report_id; 173 buffer->data()[0] = report_id;
173 174
174 scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer( 175 scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer(
175 buffer, 176 buffer,
176 base::Bind( 177 base::Bind(
177 &HidConnectionWin::OnReadFeatureComplete, this, buffer, callback))); 178 &HidConnectionWin::OnReadFeatureComplete, this, buffer, callback)));
178 transfers_.insert(transfer); 179 transfers_.insert(transfer);
179 transfer->TakeResultFromWindowsAPI( 180 transfer->TakeResultFromWindowsAPI(
180 DeviceIoControl(file_.Get(), 181 DeviceIoControl(file_.Get(),
181 IOCTL_HID_GET_FEATURE, 182 IOCTL_HID_GET_FEATURE,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 if (GetOverlappedResult( 258 if (GetOverlappedResult(
258 file_.Get(), transfer->GetOverlapped(), &bytes_transferred, FALSE)) { 259 file_.Get(), transfer->GetOverlapped(), &bytes_transferred, FALSE)) {
259 callback.Run(true); 260 callback.Run(true);
260 } else { 261 } else {
261 VPLOG(1) << "HID write failed"; 262 VPLOG(1) << "HID write failed";
262 callback.Run(false); 263 callback.Run(false);
263 } 264 }
264 } 265 }
265 266
266 } // namespace device 267 } // namespace device
OLDNEW
« no previous file with comments | « device/hid/hid_connection_unittest.cc ('k') | device/hid/hid_device_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698