OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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_service_win.h" | 5 #include "device/hid/hid_service_win.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 | 8 |
| 9 #include "base/files/file.h" |
9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
10 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
11 #include "device/hid/hid_connection_win.h" | 12 #include "device/hid/hid_connection_win.h" |
12 #include "device/hid/hid_device_info.h" | 13 #include "device/hid/hid_device_info.h" |
13 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
14 | 15 |
15 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
16 | 17 |
17 #define INITGUID | 18 #define INITGUID |
18 | 19 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 void HidServiceWin::PlatformAddDevice(const std::string& device_path) { | 144 void HidServiceWin::PlatformAddDevice(const std::string& device_path) { |
144 HidDeviceInfo device_info; | 145 HidDeviceInfo device_info; |
145 device_info.device_id = device_path; | 146 device_info.device_id = device_path; |
146 | 147 |
147 // Try to open the device. | 148 // Try to open the device. |
148 base::win::ScopedHandle device_handle( | 149 base::win::ScopedHandle device_handle( |
149 CreateFileA(device_path.c_str(), | 150 CreateFileA(device_path.c_str(), |
150 0, | 151 GENERIC_WRITE | GENERIC_READ, |
151 FILE_SHARE_READ, | 152 FILE_SHARE_READ | FILE_SHARE_WRITE, |
152 NULL, | 153 NULL, |
153 OPEN_EXISTING, | 154 OPEN_EXISTING, |
154 FILE_FLAG_OVERLAPPED, | 155 FILE_FLAG_OVERLAPPED, |
155 0)); | 156 0)); |
156 if (!device_handle.IsValid()) | 157 |
157 return; | 158 if (!device_handle.IsValid() && |
| 159 GetLastError() == base::File::FILE_ERROR_ACCESS_DENIED) { |
| 160 base::win::ScopedHandle device_handle( |
| 161 CreateFileA(device_path.c_str(), |
| 162 GENERIC_READ, |
| 163 FILE_SHARE_READ, |
| 164 NULL, |
| 165 OPEN_EXISTING, |
| 166 FILE_FLAG_OVERLAPPED, |
| 167 0)); |
| 168 |
| 169 if (!device_handle.IsValid()) |
| 170 return; |
| 171 } |
158 | 172 |
159 // Get VID/PID pair. | 173 // Get VID/PID pair. |
160 HIDD_ATTRIBUTES attrib = {0}; | 174 HIDD_ATTRIBUTES attrib = {0}; |
161 attrib.Size = sizeof(HIDD_ATTRIBUTES); | 175 attrib.Size = sizeof(HIDD_ATTRIBUTES); |
162 if (!HidD_GetAttributes(device_handle.Get(), &attrib)) | 176 if (!HidD_GetAttributes(device_handle.Get(), &attrib)) |
163 return; | 177 return; |
164 | 178 |
165 device_info.vendor_id = attrib.VendorID; | 179 device_info.vendor_id = attrib.VendorID; |
166 device_info.product_id = attrib.ProductID; | 180 device_info.product_id = attrib.ProductID; |
167 | 181 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 return NULL; | 241 return NULL; |
228 scoped_refptr<HidConnectionWin> connection(new HidConnectionWin(device_info)); | 242 scoped_refptr<HidConnectionWin> connection(new HidConnectionWin(device_info)); |
229 if (!connection->available()) { | 243 if (!connection->available()) { |
230 LOG_GETLASTERROR(ERROR) << "Failed to open device."; | 244 LOG_GETLASTERROR(ERROR) << "Failed to open device."; |
231 return NULL; | 245 return NULL; |
232 } | 246 } |
233 return connection; | 247 return connection; |
234 } | 248 } |
235 | 249 |
236 } // namespace device | 250 } // namespace device |
OLD | NEW |