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

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

Issue 2804313005: Make HidConnection::Read reentrancy safe (Closed)
Patch Set: Rebased. Created 3 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/hid_connection_mac.cc ('k') | no next file » | 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 const ReadCallback& callback, 172 const ReadCallback& callback,
173 PendingHidTransfer* transfer_raw, 173 PendingHidTransfer* transfer_raw,
174 bool signaled) { 174 bool signaled) {
175 if (!file_.IsValid()) { 175 if (!file_.IsValid()) {
176 callback.Run(false, nullptr, 0); 176 callback.Run(false, nullptr, 0);
177 return; 177 return;
178 } 178 }
179 179
180 std::unique_ptr<PendingHidTransfer> transfer = UnlinkTransfer(transfer_raw); 180 std::unique_ptr<PendingHidTransfer> transfer = UnlinkTransfer(transfer_raw);
181 DWORD bytes_transferred; 181 DWORD bytes_transferred;
182 if (signaled && GetOverlappedResult(file_.Get(), transfer->GetOverlapped(), 182 if (!signaled || !GetOverlappedResult(file_.Get(), transfer->GetOverlapped(),
183 &bytes_transferred, FALSE)) { 183 &bytes_transferred, FALSE)) {
184 CompleteRead(buffer, bytes_transferred, callback);
185 } else {
186 HID_PLOG(EVENT) << "HID read failed"; 184 HID_PLOG(EVENT) << "HID read failed";
187 callback.Run(false, nullptr, 0); 185 callback.Run(false, nullptr, 0);
186 return;
188 } 187 }
188
189 if (bytes_transferred < 1) {
190 HID_LOG(EVENT) << "HID read too short.";
191 callback.Run(false, nullptr, 0);
192 return;
193 }
194
195 uint8_t report_id = buffer->data()[0];
196 if (IsReportIdProtected(report_id)) {
197 PlatformRead(callback);
198 return;
199 }
200
201 callback.Run(true, buffer, bytes_transferred);
189 } 202 }
190 203
191 void HidConnectionWin::OnReadFeatureComplete( 204 void HidConnectionWin::OnReadFeatureComplete(
192 scoped_refptr<net::IOBuffer> buffer, 205 scoped_refptr<net::IOBuffer> buffer,
193 const ReadCallback& callback, 206 const ReadCallback& callback,
194 PendingHidTransfer* transfer_raw, 207 PendingHidTransfer* transfer_raw,
195 bool signaled) { 208 bool signaled) {
196 if (!file_.IsValid()) { 209 if (!file_.IsValid()) {
197 callback.Run(false, nullptr, 0); 210 callback.Run(false, nullptr, 0);
198 return; 211 return;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 [transfer](const std::unique_ptr<PendingHidTransfer>& this_transfer) { 248 [transfer](const std::unique_ptr<PendingHidTransfer>& this_transfer) {
236 return transfer == this_transfer.get(); 249 return transfer == this_transfer.get();
237 }); 250 });
238 DCHECK(it != transfers_.end()); 251 DCHECK(it != transfers_.end());
239 std::unique_ptr<PendingHidTransfer> saved_transfer = std::move(*it); 252 std::unique_ptr<PendingHidTransfer> saved_transfer = std::move(*it);
240 transfers_.erase(it); 253 transfers_.erase(it);
241 return saved_transfer; 254 return saved_transfer;
242 } 255 }
243 256
244 } // namespace device 257 } // namespace device
OLDNEW
« no previous file with comments | « device/hid/hid_connection_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698