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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(const HidDeviceInfo& device_info, |
| 106 base::win::ScopedHandle file) |
106 : HidConnection(device_info) { | 107 : HidConnection(device_info) { |
107 file_.Set(CreateFileA(device_info.device_id.c_str(), | 108 file_ = file.Pass(); |
108 GENERIC_WRITE | GENERIC_READ, | |
109 FILE_SHARE_READ | FILE_SHARE_WRITE, | |
110 NULL, | |
111 OPEN_EXISTING, | |
112 FILE_FLAG_OVERLAPPED, | |
113 NULL)); | |
114 | |
115 if (!file_.IsValid() && | |
116 GetLastError() == base::File::FILE_ERROR_ACCESS_DENIED) { | |
117 file_.Set(CreateFileA(device_info.device_id.c_str(), | |
118 GENERIC_READ, | |
119 FILE_SHARE_READ, | |
120 NULL, | |
121 OPEN_EXISTING, | |
122 FILE_FLAG_OVERLAPPED, | |
123 NULL)); | |
124 } | |
125 } | 109 } |
126 | 110 |
127 HidConnectionWin::~HidConnectionWin() { | 111 HidConnectionWin::~HidConnectionWin() { |
128 } | 112 } |
129 | 113 |
130 void HidConnectionWin::PlatformClose() { | 114 void HidConnectionWin::PlatformClose() { |
131 CancelIo(file_.Get()); | 115 CancelIo(file_.Get()); |
132 } | 116 } |
133 | 117 |
134 void HidConnectionWin::PlatformRead( | 118 void HidConnectionWin::PlatformRead( |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 if (GetOverlappedResult( | 241 if (GetOverlappedResult( |
258 file_.Get(), transfer->GetOverlapped(), &bytes_transferred, FALSE)) { | 242 file_.Get(), transfer->GetOverlapped(), &bytes_transferred, FALSE)) { |
259 callback.Run(true); | 243 callback.Run(true); |
260 } else { | 244 } else { |
261 VPLOG(1) << "HID write failed"; | 245 VPLOG(1) << "HID write failed"; |
262 callback.Run(false); | 246 callback.Run(false); |
263 } | 247 } |
264 } | 248 } |
265 | 249 |
266 } // namespace device | 250 } // namespace device |
OLD | NEW |