Chromium Code Reviews| 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_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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 ReadFile(file_.Get(), | 130 ReadFile(file_.Get(), |
| 131 buffer->data(), | 131 buffer->data(), |
| 132 static_cast<DWORD>(buffer->size()), | 132 static_cast<DWORD>(buffer->size()), |
| 133 NULL, | 133 NULL, |
| 134 transfer->GetOverlapped())); | 134 transfer->GetOverlapped())); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void HidConnectionWin::PlatformWrite(scoped_refptr<net::IOBuffer> buffer, | 137 void HidConnectionWin::PlatformWrite(scoped_refptr<net::IOBuffer> buffer, |
| 138 size_t size, | 138 size_t size, |
| 139 const WriteCallback& callback) { | 139 const WriteCallback& callback) { |
| 140 // The Windows API always wants either a report ID (if supported) or | 140 size_t expected_size = device_info()->max_output_report_size() + 1; |
| 141 // zero at the front of every output report. | 141 DCHECK(size <= expected_size); |
| 142 // The Windows API always wants either a report ID (if supported) or zero at | |
| 143 // the front of every output report and requires that the buffer be equal to | |
|
Ken Rockot(use gerrit already)
2015/02/20 02:31:46
nit: "requires that the buffer be equal to"
| |
| 144 // the maximum output report supported by this collection. | |
| 145 if (size < expected_size) { | |
| 146 scoped_refptr<net::IOBuffer> tmp_buffer = new net::IOBuffer( | |
| 147 base::checked_cast<int>(expected_size)); | |
| 148 memcpy(tmp_buffer->data(), buffer->data(), size); | |
| 149 memset(tmp_buffer->data() + size, 0, expected_size - size); | |
| 150 buffer = tmp_buffer; | |
| 151 size = expected_size; | |
| 152 } | |
| 142 scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer( | 153 scoped_refptr<PendingHidTransfer> transfer(new PendingHidTransfer( |
| 143 buffer, base::Bind(&HidConnectionWin::OnWriteComplete, this, callback))); | 154 buffer, base::Bind(&HidConnectionWin::OnWriteComplete, this, callback))); |
| 144 transfers_.insert(transfer); | 155 transfers_.insert(transfer); |
| 145 transfer->TakeResultFromWindowsAPI(WriteFile(file_.Get(), | 156 transfer->TakeResultFromWindowsAPI(WriteFile(file_.Get(), |
| 146 buffer->data(), | 157 buffer->data(), |
| 147 static_cast<DWORD>(size), | 158 static_cast<DWORD>(size), |
| 148 NULL, | 159 NULL, |
| 149 transfer->GetOverlapped())); | 160 transfer->GetOverlapped())); |
| 150 } | 161 } |
| 151 | 162 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 if (GetOverlappedResult( | 253 if (GetOverlappedResult( |
| 243 file_.Get(), transfer->GetOverlapped(), &bytes_transferred, FALSE)) { | 254 file_.Get(), transfer->GetOverlapped(), &bytes_transferred, FALSE)) { |
| 244 callback.Run(true); | 255 callback.Run(true); |
| 245 } else { | 256 } else { |
| 246 VPLOG(1) << "HID write failed"; | 257 VPLOG(1) << "HID write failed"; |
| 247 callback.Run(false); | 258 callback.Run(false); |
| 248 } | 259 } |
| 249 } | 260 } |
| 250 | 261 |
| 251 } // namespace device | 262 } // namespace device |
| OLD | NEW |