| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 | 185 |
| 186 void DeviceImpl::OnOpen(const OpenCallback& callback, | 186 void DeviceImpl::OnOpen(const OpenCallback& callback, |
| 187 scoped_refptr<UsbDeviceHandle> handle) { | 187 scoped_refptr<UsbDeviceHandle> handle) { |
| 188 device_handle_ = handle; | 188 device_handle_ = handle; |
| 189 callback.Run(handle ? OpenDeviceError::OK : OpenDeviceError::ACCESS_DENIED); | 189 callback.Run(handle ? OpenDeviceError::OK : OpenDeviceError::ACCESS_DENIED); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) { | 192 void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) { |
| 193 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); |
| 194 device_info_->active_configuration = config ? config->configuration_value : 0; |
| 193 callback.Run(device_info_->Clone()); | 195 callback.Run(device_info_->Clone()); |
| 194 } | 196 } |
| 195 | 197 |
| 196 void DeviceImpl::GetConfiguration(const GetConfigurationCallback& callback) { | |
| 197 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); | |
| 198 callback.Run(config ? config->configuration_value : 0); | |
| 199 } | |
| 200 | |
| 201 void DeviceImpl::Open(const OpenCallback& callback) { | 198 void DeviceImpl::Open(const OpenCallback& callback) { |
| 202 if (device_handle_) | 199 if (device_handle_) |
| 203 callback.Run(OpenDeviceError::ALREADY_OPEN); | 200 callback.Run(OpenDeviceError::ALREADY_OPEN); |
| 204 else | 201 else |
| 205 device_->Open( | 202 device_->Open( |
| 206 base::Bind(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), callback)); | 203 base::Bind(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), callback)); |
| 207 } | 204 } |
| 208 | 205 |
| 209 void DeviceImpl::Close(const CloseCallback& callback) { | 206 void DeviceImpl::Close(const CloseCallback& callback) { |
| 210 CloseHandle(); | 207 CloseHandle(); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); | 423 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); |
| 427 } | 424 } |
| 428 | 425 |
| 429 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { | 426 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { |
| 430 DCHECK_EQ(device_, device); | 427 DCHECK_EQ(device_, device); |
| 431 delete this; | 428 delete this; |
| 432 } | 429 } |
| 433 | 430 |
| 434 } // namespace usb | 431 } // namespace usb |
| 435 } // namespace device | 432 } // namespace device |
| OLD | NEW |