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/files/file.h" |
9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
11 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
12 #include "base/win/object_watcher.h" | 13 #include "base/win/object_watcher.h" |
13 #include "base/win/scoped_handle.h" | 14 #include "base/win/scoped_handle.h" |
14 #include "device/hid/hid_service.h" | 15 #include "device/hid/hid_service.h" |
15 #include "device/hid/hid_service_win.h" | 16 #include "device/hid/hid_service_win.h" |
16 | 17 |
17 #define INITGUID | 18 #define INITGUID |
18 | 19 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 HidConnectionWin::HidConnectionWin(const HidDeviceInfo& device_info) | 104 HidConnectionWin::HidConnectionWin(const HidDeviceInfo& device_info) |
104 : HidConnection(device_info) { | 105 : HidConnection(device_info) { |
105 DCHECK(thread_checker_.CalledOnValidThread()); | 106 DCHECK(thread_checker_.CalledOnValidThread()); |
106 file_.Set(CreateFileA(device_info.device_id.c_str(), | 107 file_.Set(CreateFileA(device_info.device_id.c_str(), |
107 GENERIC_WRITE | GENERIC_READ, | 108 GENERIC_WRITE | GENERIC_READ, |
108 FILE_SHARE_READ | FILE_SHARE_WRITE, | 109 FILE_SHARE_READ | FILE_SHARE_WRITE, |
109 NULL, | 110 NULL, |
110 OPEN_EXISTING, | 111 OPEN_EXISTING, |
111 FILE_FLAG_OVERLAPPED, | 112 FILE_FLAG_OVERLAPPED, |
112 NULL)); | 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 } |
113 } | 125 } |
114 | 126 |
115 bool HidConnectionWin::available() const { | 127 bool HidConnectionWin::available() const { |
116 return file_.IsValid(); | 128 return file_.IsValid(); |
117 } | 129 } |
118 | 130 |
119 HidConnectionWin::~HidConnectionWin() { | 131 HidConnectionWin::~HidConnectionWin() { |
120 DCHECK(thread_checker_.CalledOnValidThread()); | 132 DCHECK(thread_checker_.CalledOnValidThread()); |
121 CancelIo(file_.Get()); | 133 CancelIo(file_.Get()); |
122 } | 134 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 291 } |
280 } | 292 } |
281 | 293 |
282 void HidConnectionWin::OnTransferCanceled( | 294 void HidConnectionWin::OnTransferCanceled( |
283 scoped_refptr<PendingHidTransfer> transfer) { | 295 scoped_refptr<PendingHidTransfer> transfer) { |
284 transfers_.erase(transfer); | 296 transfers_.erase(transfer); |
285 transfer->callback_.Run(false, 0); | 297 transfer->callback_.Run(false, 0); |
286 } | 298 } |
287 | 299 |
288 } // namespace device | 300 } // namespace device |
OLD | NEW |