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 <memory> | 10 #include <memory> |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 [index](const UsbInterfaceDescriptor& this_iface) { | 179 [index](const UsbInterfaceDescriptor& this_iface) { |
180 return this_iface.interface_number == (index & 0xff); | 180 return this_iface.interface_number == (index & 0xff); |
181 }); | 181 }); |
182 if (interface_it != config->interfaces.end()) | 182 if (interface_it != config->interfaces.end()) |
183 interface = &*interface_it; | 183 interface = &*interface_it; |
184 } | 184 } |
185 if (interface == nullptr) | 185 if (interface == nullptr) |
186 return false; | 186 return false; |
187 | 187 |
188 return permission_provider_->HasFunctionPermission( | 188 return permission_provider_->HasFunctionPermission( |
189 interface->first_interface, config->configuration_value, *device_info_); | 189 interface->first_interface, config->configuration_value, device_); |
190 } else if (config) { | 190 } else if (config) { |
191 return permission_provider_->HasConfigurationPermission( | 191 return permission_provider_->HasConfigurationPermission( |
192 config->configuration_value, *device_info_); | 192 config->configuration_value, device_); |
193 } else { | 193 } else { |
194 // Client must already have device permission to have gotten this far. | 194 // Client must already have device permission to have gotten this far. |
195 return true; | 195 return true; |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
199 void DeviceImpl::OnOpen(const OpenCallback& callback, | 199 void DeviceImpl::OnOpen(const OpenCallback& callback, |
200 scoped_refptr<UsbDeviceHandle> handle) { | 200 scoped_refptr<UsbDeviceHandle> handle) { |
201 device_handle_ = handle; | 201 device_handle_ = handle; |
202 if (device_handle_ && permission_provider_) | 202 if (device_handle_ && permission_provider_) |
(...skipping 21 matching lines...) Expand all Loading... |
224 } | 224 } |
225 | 225 |
226 void DeviceImpl::SetConfiguration(uint8_t value, | 226 void DeviceImpl::SetConfiguration(uint8_t value, |
227 const SetConfigurationCallback& callback) { | 227 const SetConfigurationCallback& callback) { |
228 if (!device_handle_) { | 228 if (!device_handle_) { |
229 callback.Run(false); | 229 callback.Run(false); |
230 return; | 230 return; |
231 } | 231 } |
232 | 232 |
233 if (permission_provider_ && | 233 if (permission_provider_ && |
234 permission_provider_->HasConfigurationPermission(value, *device_info_)) { | 234 permission_provider_->HasConfigurationPermission(value, device_)) { |
235 device_handle_->SetConfiguration(value, WrapMojoCallback(callback)); | 235 device_handle_->SetConfiguration(value, WrapMojoCallback(callback)); |
236 } else { | 236 } else { |
237 callback.Run(false); | 237 callback.Run(false); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 void DeviceImpl::ClaimInterface(uint8_t interface_number, | 241 void DeviceImpl::ClaimInterface(uint8_t interface_number, |
242 const ClaimInterfaceCallback& callback) { | 242 const ClaimInterfaceCallback& callback) { |
243 if (!device_handle_) { | 243 if (!device_handle_) { |
244 callback.Run(false); | 244 callback.Run(false); |
(...skipping 12 matching lines...) Expand all Loading... |
257 return interface.interface_number == interface_number; | 257 return interface.interface_number == interface_number; |
258 }); | 258 }); |
259 if (interface_it == config->interfaces.end()) { | 259 if (interface_it == config->interfaces.end()) { |
260 callback.Run(false); | 260 callback.Run(false); |
261 return; | 261 return; |
262 } | 262 } |
263 | 263 |
264 if (permission_provider_ && | 264 if (permission_provider_ && |
265 permission_provider_->HasFunctionPermission(interface_it->first_interface, | 265 permission_provider_->HasFunctionPermission(interface_it->first_interface, |
266 config->configuration_value, | 266 config->configuration_value, |
267 *device_info_)) { | 267 device_)) { |
268 device_handle_->ClaimInterface(interface_number, | 268 device_handle_->ClaimInterface(interface_number, |
269 WrapMojoCallback(callback)); | 269 WrapMojoCallback(callback)); |
270 } else { | 270 } else { |
271 callback.Run(false); | 271 callback.Run(false); |
272 } | 272 } |
273 } | 273 } |
274 | 274 |
275 void DeviceImpl::ReleaseInterface(uint8_t interface_number, | 275 void DeviceImpl::ReleaseInterface(uint8_t interface_number, |
276 const ReleaseInterfaceCallback& callback) { | 276 const ReleaseInterfaceCallback& callback) { |
277 if (!device_handle_) { | 277 if (!device_handle_) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); | 450 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); |
451 } | 451 } |
452 | 452 |
453 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { | 453 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { |
454 DCHECK_EQ(device_, device); | 454 DCHECK_EQ(device_, device); |
455 delete this; | 455 delete this; |
456 } | 456 } |
457 | 457 |
458 } // namespace usb | 458 } // namespace usb |
459 } // namespace device | 459 } // namespace device |
OLD | NEW |