OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/usb/mojo/device_impl.h" | 5 #include "device/usb/mojo/device_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <numeric> | 10 #include <numeric> |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 [index](const UsbInterfaceDescriptor& interface) { | 174 [index](const UsbInterfaceDescriptor& interface) { |
175 return interface.interface_number == (index & 0xff); | 175 return interface.interface_number == (index & 0xff); |
176 }); | 176 }); |
177 if (interface_it != config->interfaces.end()) | 177 if (interface_it != config->interfaces.end()) |
178 interface = &*interface_it; | 178 interface = &*interface_it; |
179 } | 179 } |
180 if (interface == nullptr) | 180 if (interface == nullptr) |
181 return false; | 181 return false; |
182 | 182 |
183 return permission_provider_->HasFunctionPermission( | 183 return permission_provider_->HasFunctionPermission( |
184 interface->first_interface, config->configuration_value, *device_info_); | 184 interface->first_interface, config->configuration_value, device_); |
185 } else if (config) { | 185 } else if (config) { |
186 return permission_provider_->HasConfigurationPermission( | 186 return permission_provider_->HasConfigurationPermission( |
187 config->configuration_value, *device_info_); | 187 config->configuration_value, device_); |
188 } else { | 188 } else { |
189 // Client must already have device permission to have gotten this far. | 189 // Client must already have device permission to have gotten this far. |
190 return true; | 190 return true; |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 void DeviceImpl::OnOpen(const OpenCallback& callback, | 194 void DeviceImpl::OnOpen(const OpenCallback& callback, |
195 scoped_refptr<UsbDeviceHandle> handle) { | 195 scoped_refptr<UsbDeviceHandle> handle) { |
196 device_handle_ = handle; | 196 device_handle_ = handle; |
197 callback.Run(handle ? OpenDeviceError::OK : OpenDeviceError::ACCESS_DENIED); | 197 callback.Run(handle ? OpenDeviceError::OK : OpenDeviceError::ACCESS_DENIED); |
(...skipping 19 matching lines...) Expand all Loading... |
217 } | 217 } |
218 | 218 |
219 void DeviceImpl::SetConfiguration(uint8_t value, | 219 void DeviceImpl::SetConfiguration(uint8_t value, |
220 const SetConfigurationCallback& callback) { | 220 const SetConfigurationCallback& callback) { |
221 if (!device_handle_) { | 221 if (!device_handle_) { |
222 callback.Run(false); | 222 callback.Run(false); |
223 return; | 223 return; |
224 } | 224 } |
225 | 225 |
226 if (permission_provider_ && | 226 if (permission_provider_ && |
227 permission_provider_->HasConfigurationPermission(value, *device_info_)) { | 227 permission_provider_->HasConfigurationPermission(value, device_)) { |
228 device_handle_->SetConfiguration(value, WrapMojoCallback(callback)); | 228 device_handle_->SetConfiguration(value, WrapMojoCallback(callback)); |
229 } else { | 229 } else { |
230 callback.Run(false); | 230 callback.Run(false); |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 void DeviceImpl::ClaimInterface(uint8_t interface_number, | 234 void DeviceImpl::ClaimInterface(uint8_t interface_number, |
235 const ClaimInterfaceCallback& callback) { | 235 const ClaimInterfaceCallback& callback) { |
236 if (!device_handle_) { | 236 if (!device_handle_) { |
237 callback.Run(false); | 237 callback.Run(false); |
(...skipping 12 matching lines...) Expand all Loading... |
250 return interface.interface_number == interface_number; | 250 return interface.interface_number == interface_number; |
251 }); | 251 }); |
252 if (interface_it == config->interfaces.end()) { | 252 if (interface_it == config->interfaces.end()) { |
253 callback.Run(false); | 253 callback.Run(false); |
254 return; | 254 return; |
255 } | 255 } |
256 | 256 |
257 if (permission_provider_ && | 257 if (permission_provider_ && |
258 permission_provider_->HasFunctionPermission(interface_it->first_interface, | 258 permission_provider_->HasFunctionPermission(interface_it->first_interface, |
259 config->configuration_value, | 259 config->configuration_value, |
260 *device_info_)) { | 260 device_)) { |
261 device_handle_->ClaimInterface(interface_number, | 261 device_handle_->ClaimInterface(interface_number, |
262 WrapMojoCallback(callback)); | 262 WrapMojoCallback(callback)); |
263 } else { | 263 } else { |
264 callback.Run(false); | 264 callback.Run(false); |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 void DeviceImpl::ReleaseInterface(uint8_t interface_number, | 268 void DeviceImpl::ReleaseInterface(uint8_t interface_number, |
269 const ReleaseInterfaceCallback& callback) { | 269 const ReleaseInterfaceCallback& callback) { |
270 if (!device_handle_) { | 270 if (!device_handle_) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); | 442 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); |
443 } | 443 } |
444 | 444 |
445 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { | 445 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { |
446 DCHECK_EQ(device_, device); | 446 DCHECK_EQ(device_, device); |
447 delete this; | 447 delete this; |
448 } | 448 } |
449 | 449 |
450 } // namespace usb | 450 } // namespace usb |
451 } // namespace device | 451 } // namespace device |
OLD | NEW |