| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/usb/usb_api.h" | 5 #include "chrome/browser/extensions/api/usb/usb_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/extensions/api/usb/usb_device_resource.h" | 11 #include "chrome/browser/extensions/api/usb/usb_device_resource.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/usb/usb_service.h" | 14 #include "chrome/browser/usb/usb_service.h" |
| 15 #include "chrome/browser/usb/usb_service_factory.h" | 15 #include "chrome/browser/usb/usb_service_factory.h" |
| 16 #include "chrome/common/extensions/api/usb.h" | 16 #include "chrome/common/extensions/api/usb.h" |
| 17 #include "chrome/common/extensions/permissions/permissions_data.h" | 17 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 18 #include "chrome/common/extensions/permissions/usb_device_permission.h" | 18 #include "chrome/common/extensions/permissions/usb_device_permission.h" |
| 19 | 19 |
| 20 namespace BulkTransfer = extensions::api::usb::BulkTransfer; | 20 namespace BulkTransfer = extensions::api::usb::BulkTransfer; |
| 21 namespace ClaimInterface = extensions::api::usb::ClaimInterface; | 21 namespace ClaimInterface = extensions::api::usb::ClaimInterface; |
| 22 namespace ListInterfaces = extensions::api::usb::ListInterfaces; | 22 namespace ListInterfaces = extensions::api::usb::ListInterfaces; |
| 23 namespace CloseDevice = extensions::api::usb::CloseDevice; | 23 namespace CloseDevice = extensions::api::usb::CloseDevice; |
| 24 namespace ControlTransfer = extensions::api::usb::ControlTransfer; | 24 namespace ControlTransfer = extensions::api::usb::ControlTransfer; |
| 25 namespace FindDevices = extensions::api::usb::FindDevices; | 25 namespace FindDevices = extensions::api::usb::FindDevices; |
| 26 namespace GetDevices = extensions::api::usb::GetDevices; |
| 27 namespace OpenDevice = extensions::api::usb::OpenDevice; |
| 26 namespace InterruptTransfer = extensions::api::usb::InterruptTransfer; | 28 namespace InterruptTransfer = extensions::api::usb::InterruptTransfer; |
| 27 namespace IsochronousTransfer = extensions::api::usb::IsochronousTransfer; | 29 namespace IsochronousTransfer = extensions::api::usb::IsochronousTransfer; |
| 28 namespace ReleaseInterface = extensions::api::usb::ReleaseInterface; | 30 namespace ReleaseInterface = extensions::api::usb::ReleaseInterface; |
| 29 namespace ResetDevice = extensions::api::usb::ResetDevice; | 31 namespace ResetDevice = extensions::api::usb::ResetDevice; |
| 30 namespace SetInterfaceAlternateSetting = | 32 namespace SetInterfaceAlternateSetting = |
| 31 extensions::api::usb::SetInterfaceAlternateSetting; | 33 extensions::api::usb::SetInterfaceAlternateSetting; |
| 32 namespace usb = extensions::api::usb; | 34 namespace usb = extensions::api::usb; |
| 33 | 35 |
| 34 using std::string; | 36 using std::string; |
| 35 using std::vector; | 37 using std::vector; |
| 36 using usb::ControlTransferInfo; | 38 using usb::ControlTransferInfo; |
| 37 using usb::Device; | 39 using usb::Device; |
| 40 using usb::DeviceHandle; |
| 38 using usb::Direction; | 41 using usb::Direction; |
| 39 using usb::EndpointDescriptor; | 42 using usb::EndpointDescriptor; |
| 40 using usb::GenericTransferInfo; | 43 using usb::GenericTransferInfo; |
| 41 using usb::InterfaceDescriptor; | 44 using usb::InterfaceDescriptor; |
| 42 using usb::IsochronousTransferInfo; | 45 using usb::IsochronousTransferInfo; |
| 43 using usb::Recipient; | 46 using usb::Recipient; |
| 44 using usb::RequestType; | 47 using usb::RequestType; |
| 45 using usb::SynchronizationType; | 48 using usb::SynchronizationType; |
| 46 using usb::TransferType; | 49 using usb::TransferType; |
| 47 using usb::UsageType; | 50 using usb::UsageType; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 68 static const char kErrorConvertRecipient[] = "Invalid transfer recipient."; | 71 static const char kErrorConvertRecipient[] = "Invalid transfer recipient."; |
| 69 static const char kErrorConvertRequestType[] = "Invalid request type."; | 72 static const char kErrorConvertRequestType[] = "Invalid request type."; |
| 70 static const char kErrorConvertSynchronizationType[] = | 73 static const char kErrorConvertSynchronizationType[] = |
| 71 "Invalid synchronization type"; | 74 "Invalid synchronization type"; |
| 72 static const char kErrorConvertTransferType[] = "Invalid endpoint type."; | 75 static const char kErrorConvertTransferType[] = "Invalid endpoint type."; |
| 73 static const char kErrorConvertUsageType[] = "Invalid usage type."; | 76 static const char kErrorConvertUsageType[] = "Invalid usage type."; |
| 74 static const char kErrorMalformedParameters[] = "Error parsing parameters."; | 77 static const char kErrorMalformedParameters[] = "Error parsing parameters."; |
| 75 static const char kErrorNoDevice[] = "No such device."; | 78 static const char kErrorNoDevice[] = "No such device."; |
| 76 static const char kErrorPermissionDenied[] = | 79 static const char kErrorPermissionDenied[] = |
| 77 "Permission to access device was denied"; | 80 "Permission to access device was denied"; |
| 78 static const char kErrorInvalidTransferLength[] = "Transfer length must be a " | 81 static const char kErrorInvalidTransferLength[] = |
| 79 "positive number less than 104,857,600."; | 82 "Transfer length must be a positive number less than 104,857,600."; |
| 80 static const char kErrorInvalidNumberOfPackets[] = "Number of packets must be " | 83 static const char kErrorInvalidNumberOfPackets[] = |
| 81 "a positive number less than 4,194,304."; | 84 "Number of packets must be a positive number less than 4,194,304."; |
| 82 static const char kErrorInvalidPacketLength[] = "Packet length must be a " | 85 static const char kErrorInvalidPacketLength[] = |
| 83 "positive number less than 65,536."; | 86 "Packet length must be a positive number less than 65,536."; |
| 84 static const char kErrorResetDevice[] = | 87 static const char kErrorResetDevice[] = |
| 85 "Error resetting the device. The device has been closed."; | 88 "Error resetting the device. The device has been closed."; |
| 86 | 89 |
| 87 static const size_t kMaxTransferLength = 100 * 1024 * 1024; | 90 static const size_t kMaxTransferLength = 100 * 1024 * 1024; |
| 88 static const int kMaxPackets = 4 * 1024 * 1024; | 91 static const int kMaxPackets = 4 * 1024 * 1024; |
| 89 static const int kMaxPacketLength = 64 * 1024; | 92 static const int kMaxPacketLength = 64 * 1024; |
| 90 | 93 |
| 91 static UsbDevice* device_for_test_ = NULL; | 94 static UsbDeviceHandle* device_for_test_ = NULL; |
| 92 | 95 |
| 93 static bool ConvertDirectionToApi(const UsbEndpointDirection& input, | 96 static bool ConvertDirectionToApi(const UsbEndpointDirection& input, |
| 94 Direction* output) { | 97 Direction* output) { |
| 95 switch (input) { | 98 switch (input) { |
| 96 case USB_DIRECTION_INBOUND: | 99 case USB_DIRECTION_INBOUND: |
| 97 *output = usb::DIRECTION_IN; | 100 *output = usb::DIRECTION_IN; |
| 98 return true; | 101 return true; |
| 99 case USB_DIRECTION_OUTBOUND: | 102 case USB_DIRECTION_OUTBOUND: |
| 100 *output = usb::DIRECTION_OUT; | 103 *output = usb::DIRECTION_OUT; |
| 101 return true; | 104 return true; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 case USB_TRANSFER_BULK: | 146 case USB_TRANSFER_BULK: |
| 144 *output = usb::TRANSFER_TYPE_BULK; | 147 *output = usb::TRANSFER_TYPE_BULK; |
| 145 return true; | 148 return true; |
| 146 default: | 149 default: |
| 147 NOTREACHED(); | 150 NOTREACHED(); |
| 148 return false; | 151 return false; |
| 149 } | 152 } |
| 150 } | 153 } |
| 151 | 154 |
| 152 static bool ConvertUsageTypeToApi(const UsbUsageType& input, | 155 static bool ConvertUsageTypeToApi(const UsbUsageType& input, |
| 153 extensions::api::usb::UsageType* output) { | 156 extensions::api::usb::UsageType* output) { |
| 154 switch (input) { | 157 switch (input) { |
| 155 case USB_USAGE_DATA: | 158 case USB_USAGE_DATA: |
| 156 *output = usb::USAGE_TYPE_DATA; | 159 *output = usb::USAGE_TYPE_DATA; |
| 157 return true; | 160 return true; |
| 158 case USB_USAGE_FEEDBACK: | 161 case USB_USAGE_FEEDBACK: |
| 159 *output = usb::USAGE_TYPE_FEEDBACK; | 162 *output = usb::USAGE_TYPE_FEEDBACK; |
| 160 return true; | 163 return true; |
| 161 case USB_USAGE_EXPLICIT_FEEDBACK: | 164 case USB_USAGE_EXPLICIT_FEEDBACK: |
| 162 *output = usb::USAGE_TYPE_EXPLICITFEEDBACK; | 165 *output = usb::USAGE_TYPE_EXPLICITFEEDBACK; |
| 163 return true; | 166 return true; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 176 case usb::DIRECTION_OUT: | 179 case usb::DIRECTION_OUT: |
| 177 *output = USB_DIRECTION_OUTBOUND; | 180 *output = USB_DIRECTION_OUTBOUND; |
| 178 return true; | 181 return true; |
| 179 default: | 182 default: |
| 180 NOTREACHED(); | 183 NOTREACHED(); |
| 181 return false; | 184 return false; |
| 182 } | 185 } |
| 183 } | 186 } |
| 184 | 187 |
| 185 static bool ConvertRequestType(const RequestType& input, | 188 static bool ConvertRequestType(const RequestType& input, |
| 186 UsbDevice::TransferRequestType* output) { | 189 UsbDeviceHandle::TransferRequestType* output) { |
| 187 switch (input) { | 190 switch (input) { |
| 188 case usb::REQUEST_TYPE_STANDARD: | 191 case usb::REQUEST_TYPE_STANDARD: |
| 189 *output = UsbDevice::STANDARD; | 192 *output = UsbDeviceHandle::STANDARD; |
| 190 return true; | 193 return true; |
| 191 case usb::REQUEST_TYPE_CLASS: | 194 case usb::REQUEST_TYPE_CLASS: |
| 192 *output = UsbDevice::CLASS; | 195 *output = UsbDeviceHandle::CLASS; |
| 193 return true; | 196 return true; |
| 194 case usb::REQUEST_TYPE_VENDOR: | 197 case usb::REQUEST_TYPE_VENDOR: |
| 195 *output = UsbDevice::VENDOR; | 198 *output = UsbDeviceHandle::VENDOR; |
| 196 return true; | 199 return true; |
| 197 case usb::REQUEST_TYPE_RESERVED: | 200 case usb::REQUEST_TYPE_RESERVED: |
| 198 *output = UsbDevice::RESERVED; | 201 *output = UsbDeviceHandle::RESERVED; |
| 199 return true; | 202 return true; |
| 200 default: | 203 default: |
| 201 NOTREACHED(); | 204 NOTREACHED(); |
| 202 return false; | 205 return false; |
| 203 } | 206 } |
| 204 } | 207 } |
| 205 | 208 |
| 206 static bool ConvertRecipient(const Recipient& input, | 209 static bool ConvertRecipient(const Recipient& input, |
| 207 UsbDevice::TransferRecipient* output) { | 210 UsbDeviceHandle::TransferRecipient* output) { |
| 208 switch (input) { | 211 switch (input) { |
| 209 case usb::RECIPIENT_DEVICE: | 212 case usb::RECIPIENT_DEVICE: |
| 210 *output = UsbDevice::DEVICE; | 213 *output = UsbDeviceHandle::DEVICE; |
| 211 return true; | 214 return true; |
| 212 case usb::RECIPIENT_INTERFACE: | 215 case usb::RECIPIENT_INTERFACE: |
| 213 *output = UsbDevice::INTERFACE; | 216 *output = UsbDeviceHandle::INTERFACE; |
| 214 return true; | 217 return true; |
| 215 case usb::RECIPIENT_ENDPOINT: | 218 case usb::RECIPIENT_ENDPOINT: |
| 216 *output = UsbDevice::ENDPOINT; | 219 *output = UsbDeviceHandle::ENDPOINT; |
| 217 return true; | 220 return true; |
| 218 case usb::RECIPIENT_OTHER: | 221 case usb::RECIPIENT_OTHER: |
| 219 *output = UsbDevice::OTHER; | 222 *output = UsbDeviceHandle::OTHER; |
| 220 return true; | 223 return true; |
| 221 default: | 224 default: |
| 222 NOTREACHED(); | 225 NOTREACHED(); |
| 223 return false; | 226 return false; |
| 224 } | 227 } |
| 225 } | 228 } |
| 226 | 229 |
| 227 template<class T> | 230 template <class T> |
| 228 static bool GetTransferSize(const T& input, size_t* output) { | 231 static bool GetTransferSize(const T& input, size_t* output) { |
| 229 if (input.direction == usb::DIRECTION_IN) { | 232 if (input.direction == usb::DIRECTION_IN) { |
| 230 const int* length = input.length.get(); | 233 const int* length = input.length.get(); |
| 231 if (length && *length >= 0 && | 234 if (length && *length >= 0 && |
| 232 static_cast<size_t>(*length) < kMaxTransferLength) { | 235 static_cast<size_t>(*length) < kMaxTransferLength) { |
| 233 *output = *length; | 236 *output = *length; |
| 234 return true; | 237 return true; |
| 235 } | 238 } |
| 236 } else if (input.direction == usb::DIRECTION_OUT) { | 239 } else if (input.direction == usb::DIRECTION_OUT) { |
| 237 if (input.data.get()) { | 240 if (input.data.get()) { |
| 238 *output = input.data->size(); | 241 *output = input.data->size(); |
| 239 return true; | 242 return true; |
| 240 } | 243 } |
| 241 } | 244 } |
| 242 return false; | 245 return false; |
| 243 } | 246 } |
| 244 | 247 |
| 245 template<class T> | 248 template <class T> |
| 246 static scoped_refptr<net::IOBuffer> CreateBufferForTransfer( | 249 static scoped_refptr<net::IOBuffer> CreateBufferForTransfer( |
| 247 const T& input, UsbEndpointDirection direction, size_t size) { | 250 const T& input, UsbEndpointDirection direction, size_t size) { |
| 248 | 251 |
| 249 if (size >= kMaxTransferLength) | 252 if (size >= kMaxTransferLength) |
| 250 return NULL; | 253 return NULL; |
| 251 | 254 |
| 252 // Allocate a |size|-bytes buffer, or a one-byte buffer if |size| is 0. This | 255 // Allocate a |size|-bytes buffer, or a one-byte buffer if |size| is 0. This |
| 253 // is due to an impedance mismatch between IOBuffer and URBs. An IOBuffer | 256 // is due to an impedance mismatch between IOBuffer and URBs. An IOBuffer |
| 254 // cannot represent a zero-length buffer, while an URB can. | 257 // cannot represent a zero-length buffer, while an URB can. |
| 255 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(std::max( | 258 scoped_refptr<net::IOBuffer> buffer = |
| 256 static_cast<size_t>(1), size)); | 259 new net::IOBuffer(std::max(static_cast<size_t>(1), size)); |
| 257 | 260 |
| 258 if (direction == USB_DIRECTION_INBOUND) { | 261 if (direction == USB_DIRECTION_INBOUND) { |
| 259 return buffer; | 262 return buffer; |
| 260 } else if (direction == USB_DIRECTION_OUTBOUND) { | 263 } else if (direction == USB_DIRECTION_OUTBOUND) { |
| 261 if (input.data.get() && size <= input.data->size()) { | 264 if (input.data.get() && size <= input.data->size()) { |
| 262 memcpy(buffer->data(), input.data->data(), size); | 265 memcpy(buffer->data(), input.data->data(), size); |
| 263 return buffer; | 266 return buffer; |
| 264 } | 267 } |
| 265 } | 268 } |
| 266 NOTREACHED(); | 269 NOTREACHED(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 291 return ""; | 294 return ""; |
| 292 } | 295 } |
| 293 } | 296 } |
| 294 | 297 |
| 295 static base::DictionaryValue* CreateTransferInfo( | 298 static base::DictionaryValue* CreateTransferInfo( |
| 296 UsbTransferStatus status, | 299 UsbTransferStatus status, |
| 297 scoped_refptr<net::IOBuffer> data, | 300 scoped_refptr<net::IOBuffer> data, |
| 298 size_t length) { | 301 size_t length) { |
| 299 base::DictionaryValue* result = new base::DictionaryValue(); | 302 base::DictionaryValue* result = new base::DictionaryValue(); |
| 300 result->SetInteger(kResultCodeKey, status); | 303 result->SetInteger(kResultCodeKey, status); |
| 301 result->Set(kDataKey, base::BinaryValue::CreateWithCopiedBuffer(data->data(), | 304 if (data.get()) { |
| 302 length)); | 305 result->Set( |
| 306 kDataKey, |
| 307 base::BinaryValue::CreateWithCopiedBuffer(data->data(), length)); |
| 308 } |
| 303 return result; | 309 return result; |
| 304 } | 310 } |
| 305 | 311 |
| 306 static base::Value* PopulateDevice(int handle, int vendor_id, int product_id) { | 312 static base::Value* PopulateDevice(int device_id, int vendor_id, |
| 313 int product_id) { |
| 307 Device device; | 314 Device device; |
| 308 device.handle = handle; | 315 device.device = device_id; |
| 309 device.vendor_id = vendor_id; | 316 device.vendor_id = vendor_id; |
| 310 device.product_id = product_id; | 317 device.product_id = product_id; |
| 311 return device.ToValue().release(); | 318 return device.ToValue().release(); |
| 312 } | 319 } |
| 313 | 320 |
| 314 static base::Value* PopulateInterfaceDescriptor(int interface_number, | 321 static base::Value* PopulateDeviceHandle(int handle, int vendor_id, |
| 315 int alternate_setting, int interface_class, int interface_subclass, | 322 int product_id) { |
| 316 int interface_protocol, | 323 DeviceHandle device_handle; |
| 317 std::vector<linked_ptr<EndpointDescriptor> >* endpoints) { | 324 device_handle.handle = handle; |
| 325 device_handle.vendor_id = vendor_id; |
| 326 device_handle.product_id = product_id; |
| 327 return device_handle.ToValue().release(); |
| 328 } |
| 329 |
| 330 static base::Value* PopulateInterfaceDescriptor( |
| 331 int interface_number, int alternate_setting, int interface_class, |
| 332 int interface_subclass, int interface_protocol, |
| 333 std::vector<linked_ptr<EndpointDescriptor> >* endpoints) { |
| 318 InterfaceDescriptor descriptor; | 334 InterfaceDescriptor descriptor; |
| 319 descriptor.interface_number = interface_number; | 335 descriptor.interface_number = interface_number; |
| 320 descriptor.alternate_setting = alternate_setting; | 336 descriptor.alternate_setting = alternate_setting; |
| 321 descriptor.interface_class = interface_class; | 337 descriptor.interface_class = interface_class; |
| 322 descriptor.interface_subclass = interface_subclass; | 338 descriptor.interface_subclass = interface_subclass; |
| 323 descriptor.interface_protocol = interface_subclass; | 339 descriptor.interface_protocol = interface_subclass; |
| 324 descriptor.endpoints = *endpoints; | 340 descriptor.endpoints = *endpoints; |
| 325 return descriptor.ToValue().release(); | 341 return descriptor.ToValue().release(); |
| 326 } | 342 } |
| 327 | 343 |
| 328 } // namespace | 344 } // namespace |
| 329 | 345 |
| 330 namespace extensions { | 346 namespace extensions { |
| 331 | 347 |
| 332 UsbAsyncApiFunction::UsbAsyncApiFunction() | 348 UsbAsyncApiFunction::UsbAsyncApiFunction() : manager_(NULL) {} |
| 333 : manager_(NULL) { | |
| 334 } | |
| 335 | 349 |
| 336 UsbAsyncApiFunction::~UsbAsyncApiFunction() { | 350 UsbAsyncApiFunction::~UsbAsyncApiFunction() {} |
| 337 } | |
| 338 | 351 |
| 339 bool UsbAsyncApiFunction::PrePrepare() { | 352 bool UsbAsyncApiFunction::PrePrepare() { |
| 340 manager_ = ExtensionSystem::Get(profile())->usb_device_resource_manager(); | 353 manager_ = ExtensionSystem::Get(profile())->usb_device_resource_manager(); |
| 341 return manager_ != NULL; | 354 return manager_ != NULL; |
| 342 } | 355 } |
| 343 | 356 |
| 344 bool UsbAsyncApiFunction::Respond() { | 357 bool UsbAsyncApiFunction::Respond() { return error_.empty(); } |
| 345 return error_.empty(); | |
| 346 } | |
| 347 | 358 |
| 348 UsbDeviceResource* UsbAsyncApiFunction::GetUsbDeviceResource( | 359 UsbDeviceResource* UsbAsyncApiFunction::GetUsbDeviceResource( |
| 349 int api_resource_id) { | 360 int api_resource_id) { |
| 350 return manager_->Get(extension_->id(), api_resource_id); | 361 UsbDeviceResource* resource = |
| 362 manager_->Get(extension_->id(), api_resource_id); |
| 363 |
| 364 if (resource == NULL) return NULL; |
| 365 |
| 366 if (device_for_test_) { |
| 367 return resource; |
| 368 } |
| 369 |
| 370 return resource; |
| 351 } | 371 } |
| 352 | 372 |
| 353 void UsbAsyncApiFunction::RemoveUsbDeviceResource(int api_resource_id) { | 373 void UsbAsyncApiFunction::RemoveUsbDeviceResource(int api_resource_id) { |
| 354 manager_->Remove(extension_->id(), api_resource_id); | 374 manager_->Remove(extension_->id(), api_resource_id); |
| 355 } | 375 } |
| 356 | 376 |
| 357 void UsbAsyncApiFunction::CompleteWithError(const std::string& error) { | 377 void UsbAsyncApiFunction::CompleteWithError(const std::string& error) { |
| 358 SetError(error); | 378 SetError(error); |
| 359 AsyncWorkCompleted(); | 379 AsyncWorkCompleted(); |
| 360 } | 380 } |
| 361 | 381 |
| 362 UsbAsyncApiTransferFunction::UsbAsyncApiTransferFunction() {} | 382 UsbAsyncApiTransferFunction::UsbAsyncApiTransferFunction() {} |
| 363 | 383 |
| 364 UsbAsyncApiTransferFunction::~UsbAsyncApiTransferFunction() {} | 384 UsbAsyncApiTransferFunction::~UsbAsyncApiTransferFunction() {} |
| 365 | 385 |
| 366 void UsbAsyncApiTransferFunction::OnCompleted(UsbTransferStatus status, | 386 void UsbAsyncApiTransferFunction::OnCompleted(UsbTransferStatus status, |
| 367 scoped_refptr<net::IOBuffer> data, | 387 scoped_refptr<net::IOBuffer> data, |
| 368 size_t length) { | 388 size_t length) { |
| 369 if (status != USB_TRANSFER_COMPLETED) | 389 if (status != USB_TRANSFER_COMPLETED) |
| 370 SetError(ConvertTransferStatusToErrorString(status)); | 390 SetError(ConvertTransferStatusToErrorString(status)); |
| 371 | 391 |
| 372 SetResult(CreateTransferInfo(status, data, length)); | 392 SetResult(CreateTransferInfo(status, data, length)); |
| 373 AsyncWorkCompleted(); | 393 AsyncWorkCompleted(); |
| 374 } | 394 } |
| 375 | 395 |
| 376 bool UsbAsyncApiTransferFunction::ConvertDirectionSafely( | 396 bool UsbAsyncApiTransferFunction::ConvertDirectionSafely( |
| 377 const Direction& input, UsbEndpointDirection* output) { | 397 const Direction& input, UsbEndpointDirection* output) { |
| 378 const bool converted = ConvertDirection(input, output); | 398 const bool converted = ConvertDirection(input, output); |
| 379 if (!converted) | 399 if (!converted) SetError(kErrorConvertDirection); |
| 380 SetError(kErrorConvertDirection); | |
| 381 return converted; | 400 return converted; |
| 382 } | 401 } |
| 383 | 402 |
| 384 bool UsbAsyncApiTransferFunction::ConvertRequestTypeSafely( | 403 bool UsbAsyncApiTransferFunction::ConvertRequestTypeSafely( |
| 385 const RequestType& input, UsbDevice::TransferRequestType* output) { | 404 const RequestType& input, UsbDeviceHandle::TransferRequestType* output) { |
| 386 const bool converted = ConvertRequestType(input, output); | 405 const bool converted = ConvertRequestType(input, output); |
| 387 if (!converted) | 406 if (!converted) SetError(kErrorConvertRequestType); |
| 388 SetError(kErrorConvertRequestType); | |
| 389 return converted; | 407 return converted; |
| 390 } | 408 } |
| 391 | 409 |
| 392 bool UsbAsyncApiTransferFunction::ConvertRecipientSafely( | 410 bool UsbAsyncApiTransferFunction::ConvertRecipientSafely( |
| 393 const Recipient& input, UsbDevice::TransferRecipient* output) { | 411 const Recipient& input, UsbDeviceHandle::TransferRecipient* output) { |
| 394 const bool converted = ConvertRecipient(input, output); | 412 const bool converted = ConvertRecipient(input, output); |
| 395 if (!converted) | 413 if (!converted) SetError(kErrorConvertRecipient); |
| 396 SetError(kErrorConvertRecipient); | |
| 397 return converted; | 414 return converted; |
| 398 } | 415 } |
| 399 | 416 |
| 400 UsbFindDevicesFunction::UsbFindDevicesFunction() {} | 417 UsbGetDevicesFunction::UsbGetDevicesFunction() |
| 418 : vendor_id_(0), |
| 419 product_id_(0), |
| 420 interface_id_(UsbDevicePermissionData::ANY_INTERFACE), |
| 421 service_(NULL) {} |
| 401 | 422 |
| 402 UsbFindDevicesFunction::~UsbFindDevicesFunction() {} | 423 UsbGetDevicesFunction::~UsbGetDevicesFunction() {} |
| 403 | 424 |
| 404 void UsbFindDevicesFunction::SetDeviceForTest(UsbDevice* device) { | 425 void UsbGetDevicesFunction::SetDeviceForTest(UsbDeviceHandle* device) { |
| 405 device_for_test_ = device; | 426 device_for_test_ = device; |
| 406 } | 427 } |
| 407 | 428 |
| 408 bool UsbFindDevicesFunction::Prepare() { | 429 bool UsbGetDevicesFunction::PrePrepare() { |
| 409 parameters_ = FindDevices::Params::Create(*args_); | 430 if (device_for_test_) return UsbAsyncApiFunction::PrePrepare(); |
| 410 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 431 service_ = UsbServiceFactory::GetInstance()->GetForProfile(profile()); |
| 432 if (service_ == NULL) { |
| 433 LOG(WARNING) << "Could not get UsbService for active profile."; |
| 434 SetError(kErrorNoDevice); |
| 435 return false; |
| 436 } |
| 437 return UsbAsyncApiFunction::PrePrepare(); |
| 438 } |
| 439 |
| 440 bool UsbGetDevicesFunction::Prepare() { |
| 441 scoped_ptr<GetDevices::Params> parameters = |
| 442 GetDevices::Params::Create(*args_); |
| 443 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 444 vendor_id_ = parameters->options.vendor_id; |
| 445 product_id_ = parameters->options.product_id; |
| 446 if (parameters->options.interface_id.get()) |
| 447 interface_id_ = *parameters->options.interface_id; |
| 411 return true; | 448 return true; |
| 412 } | 449 } |
| 413 | 450 |
| 414 void UsbFindDevicesFunction::AsyncWorkStart() { | 451 void UsbGetDevicesFunction::AsyncWorkStart() { |
| 415 result_.reset(new base::ListValue()); | 452 result_.reset(new base::ListValue()); |
| 416 | 453 |
| 417 if (device_for_test_) { | 454 if (device_for_test_) { |
| 418 UsbDeviceResource* const resource = new UsbDeviceResource( | 455 result_->Append(PopulateDevice(device_for_test_->device(), 0, 0)); |
| 419 extension_->id(), | |
| 420 device_for_test_); | |
| 421 | |
| 422 Device device; | |
| 423 result_->Append(PopulateDevice(manager_->Add(resource), 0, 0)); | |
| 424 SetResult(result_.release()); | 456 SetResult(result_.release()); |
| 425 AsyncWorkCompleted(); | 457 AsyncWorkCompleted(); |
| 426 return; | 458 return; |
| 427 } | 459 } |
| 428 | 460 |
| 429 const uint16_t vendor_id = parameters_->options.vendor_id; | 461 UsbDevicePermission::CheckParam param(vendor_id_, product_id_, interface_id_); |
| 430 const uint16_t product_id = parameters_->options.product_id; | |
| 431 int interface_id = parameters_->options.interface_id.get() ? | |
| 432 *parameters_->options.interface_id.get() : | |
| 433 UsbDevicePermissionData::ANY_INTERFACE; | |
| 434 UsbDevicePermission::CheckParam param(vendor_id, product_id, interface_id); | |
| 435 if (!PermissionsData::CheckAPIPermissionWithParam( | 462 if (!PermissionsData::CheckAPIPermissionWithParam( |
| 436 GetExtension(), APIPermission::kUsbDevice, ¶m)) { | 463 GetExtension(), APIPermission::kUsbDevice, ¶m)) { |
| 437 LOG(WARNING) << "Insufficient permissions to access device."; | 464 LOG(WARNING) << "Insufficient permissions to access device."; |
| 438 CompleteWithError(kErrorPermissionDenied); | 465 CompleteWithError(kErrorPermissionDenied); |
| 439 return; | 466 return; |
| 440 } | 467 } |
| 441 | 468 |
| 442 UsbService* const service = UsbServiceFactory::GetInstance()->GetForProfile( | 469 BrowserThread::PostTask( |
| 443 profile()); | 470 BrowserThread::FILE, |
| 444 if (!service) { | 471 FROM_HERE, |
| 445 LOG(WARNING) << "Could not get UsbService for active profile."; | 472 base::Bind(&UsbService::FindDevices, base::Unretained(service_), |
| 446 CompleteWithError(kErrorNoDevice); | 473 vendor_id_, product_id_, interface_id_, &devices_, |
| 447 return; | 474 base::Bind(&UsbGetDevicesFunction::OnDevicesFound, this))); |
| 448 } | |
| 449 | |
| 450 service->FindDevices(vendor_id, product_id, interface_id, &devices_, | |
| 451 base::Bind(&UsbFindDevicesFunction::OnCompleted, this)); | |
| 452 } | 475 } |
| 453 | 476 |
| 454 void UsbFindDevicesFunction::OnCompleted() { | 477 void UsbGetDevicesFunction::OnDevicesFound() { |
| 478 // Redirect this to virtual method. |
| 479 OnCompleted(); |
| 480 } |
| 481 |
| 482 void UsbGetDevicesFunction::OnCompleted() { |
| 455 for (size_t i = 0; i < devices_.size(); ++i) { | 483 for (size_t i = 0; i < devices_.size(); ++i) { |
| 456 UsbDevice* const device = devices_[i].get(); | 484 result_->Append(PopulateDevice(devices_[i], vendor_id_, product_id_)); |
| 457 UsbDeviceResource* const resource = | |
| 458 new UsbDeviceResource(extension_->id(), device); | |
| 459 | |
| 460 Device js_device; | |
| 461 result_->Append(PopulateDevice(manager_->Add(resource), | |
| 462 parameters_->options.vendor_id, | |
| 463 parameters_->options.product_id)); | |
| 464 } | 485 } |
| 465 | 486 |
| 466 SetResult(result_.release()); | 487 SetResult(result_.release()); |
| 467 AsyncWorkCompleted(); | 488 AsyncWorkCompleted(); |
| 468 } | 489 } |
| 469 | 490 |
| 491 UsbFindDevicesFunction::UsbFindDevicesFunction() : UsbGetDevicesFunction() {} |
| 492 |
| 493 UsbFindDevicesFunction::~UsbFindDevicesFunction() {} |
| 494 |
| 495 bool UsbFindDevicesFunction::Prepare() { |
| 496 scoped_ptr<FindDevices::Params> parameters = |
| 497 FindDevices::Params::Create(*args_); |
| 498 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 499 vendor_id_ = parameters->options.vendor_id; |
| 500 product_id_ = parameters->options.product_id; |
| 501 if (parameters->options.interface_id.get()) |
| 502 interface_id_ = *parameters->options.interface_id; |
| 503 return true; |
| 504 } |
| 505 |
| 506 void UsbFindDevicesFunction::OnCompleted() { |
| 507 for (size_t i = 0; i < devices_.size(); ++i) { |
| 508 scoped_refptr<UsbDeviceHandle> handle = service_->OpenDevice(devices_[i]); |
| 509 if (handle.get()) handles_.push_back(handle); |
| 510 } |
| 511 BrowserThread::PostTask( |
| 512 BrowserThread::IO, |
| 513 FROM_HERE, |
| 514 base::Bind(&UsbFindDevicesFunction::OpenDevices, this)); |
| 515 } |
| 516 |
| 517 void UsbFindDevicesFunction::OpenDevices() { |
| 518 for (size_t i = 0; i < handles_.size(); ++i) { |
| 519 UsbDeviceResource* const resource = |
| 520 new UsbDeviceResource(extension_->id(), handles_[i]); |
| 521 result_->Append( |
| 522 PopulateDeviceHandle(manager_->Add(resource), handles_[i]->vendor_id(), |
| 523 handles_[i]->product_id())); |
| 524 } |
| 525 SetResult(result_.release()); |
| 526 AsyncWorkCompleted(); |
| 527 } |
| 528 |
| 529 UsbOpenDeviceFunction::UsbOpenDeviceFunction() : service_(NULL) {} |
| 530 |
| 531 UsbOpenDeviceFunction::~UsbOpenDeviceFunction() {} |
| 532 |
| 533 bool UsbOpenDeviceFunction::PrePrepare() { |
| 534 if (device_for_test_) return UsbAsyncApiFunction::PrePrepare(); |
| 535 service_ = UsbServiceFactory::GetInstance()->GetForProfile(profile()); |
| 536 if (service_ == NULL) { |
| 537 LOG(WARNING) << "Could not get UsbService for active profile."; |
| 538 SetError(kErrorNoDevice); |
| 539 return false; |
| 540 } |
| 541 return UsbAsyncApiFunction::PrePrepare(); |
| 542 } |
| 543 |
| 544 bool UsbOpenDeviceFunction::Prepare() { |
| 545 parameters_ = OpenDevice::Params::Create(*args_); |
| 546 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 547 return true; |
| 548 } |
| 549 |
| 550 void UsbOpenDeviceFunction::AsyncWorkStart() { |
| 551 if (device_for_test_) { |
| 552 UsbDeviceResource* const resource = |
| 553 new UsbDeviceResource(extension_->id(), device_for_test_); |
| 554 SetResult(PopulateDeviceHandle(manager_->Add(resource), |
| 555 device_for_test_->vendor_id(), |
| 556 device_for_test_->product_id())); |
| 557 AsyncWorkCompleted(); |
| 558 return; |
| 559 } |
| 560 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 561 base::Bind(&UsbOpenDeviceFunction::OpenDevice, this)); |
| 562 } |
| 563 |
| 564 void UsbOpenDeviceFunction::OpenDevice() { |
| 565 scoped_refptr<UsbDeviceHandle> handle = |
| 566 service_->OpenDevice(parameters_->device.device); |
| 567 if (!handle.get()) { |
| 568 CompleteWithError(kErrorDisconnect); |
| 569 return; |
| 570 } |
| 571 // Pass to IO thread to use api resource manager. |
| 572 BrowserThread::PostTask( |
| 573 BrowserThread::IO, |
| 574 FROM_HERE, |
| 575 base::Bind(&UsbOpenDeviceFunction::OnCompleted, this, handle)); |
| 576 } |
| 577 |
| 578 void UsbOpenDeviceFunction::OnCompleted(scoped_refptr<UsbDeviceHandle> handle) { |
| 579 UsbDeviceResource* const resource = |
| 580 new UsbDeviceResource(extension_->id(), handle); |
| 581 SetResult(PopulateDeviceHandle(manager_->Add(resource), handle->vendor_id(), |
| 582 handle->product_id())); |
| 583 AsyncWorkCompleted(); |
| 584 return; |
| 585 } |
| 586 |
| 470 UsbListInterfacesFunction::UsbListInterfacesFunction() {} | 587 UsbListInterfacesFunction::UsbListInterfacesFunction() {} |
| 471 | 588 |
| 472 UsbListInterfacesFunction::~UsbListInterfacesFunction() {} | 589 UsbListInterfacesFunction::~UsbListInterfacesFunction() {} |
| 473 | 590 |
| 474 bool UsbListInterfacesFunction::Prepare() { | 591 bool UsbListInterfacesFunction::Prepare() { |
| 475 parameters_ = ListInterfaces::Params::Create(*args_); | 592 parameters_ = ListInterfaces::Params::Create(*args_); |
| 476 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 593 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 477 return true; | 594 return true; |
| 478 } | 595 } |
| 479 | 596 |
| 480 void UsbListInterfacesFunction::AsyncWorkStart() { | 597 void UsbListInterfacesFunction::AsyncWorkStart() { |
| 481 UsbDeviceResource* const resource = GetUsbDeviceResource( | 598 UsbDeviceResource* const resource = |
| 482 parameters_->device.handle); | 599 GetUsbDeviceResource(parameters_->handle.handle); |
| 483 if (!resource) { | 600 if (!resource) { |
| 484 CompleteWithError(kErrorNoDevice); | 601 CompleteWithError(kErrorNoDevice); |
| 485 return; | 602 return; |
| 486 } | 603 } |
| 487 | 604 |
| 488 config_ = new UsbConfigDescriptor(); | 605 config_ = new UsbConfigDescriptor(); |
| 489 resource->device()->ListInterfaces( | 606 resource->ListInterfaces( |
| 490 config_.get(), base::Bind(&UsbListInterfacesFunction::OnCompleted, this)); | 607 config_.get(), base::Bind(&UsbListInterfacesFunction::OnCompleted, this)); |
| 491 } | 608 } |
| 492 | 609 |
| 493 void UsbListInterfacesFunction::OnCompleted(bool success) { | 610 void UsbListInterfacesFunction::OnCompleted(bool success) { |
| 494 if (!success) { | 611 if (!success) { |
| 495 SetError(kErrorCannotListInterfaces); | 612 SetError(kErrorCannotListInterfaces); |
| 496 AsyncWorkCompleted(); | 613 AsyncWorkCompleted(); |
| 497 return; | 614 return; |
| 498 } | 615 } |
| 499 | 616 |
| 500 result_.reset(new base::ListValue()); | 617 result_.reset(new base::ListValue()); |
| 501 | 618 |
| 502 for (size_t i = 0, numInterfaces = config_->GetNumInterfaces(); | 619 for (size_t i = 0, numInterfaces = config_->GetNumInterfaces(); |
| 503 i < numInterfaces; ++i) { | 620 i < numInterfaces; ++i) { |
| 504 scoped_refptr<const UsbInterface> usbInterface(config_->GetInterface(i)); | 621 scoped_refptr<const UsbInterface> usbInterface(config_->GetInterface(i)); |
| 505 for (size_t j = 0, numDescriptors = usbInterface->GetNumAltSettings(); | 622 for (size_t j = 0, numDescriptors = usbInterface->GetNumAltSettings(); |
| 506 j < numDescriptors; ++j) { | 623 j < numDescriptors; ++j) { |
| 507 scoped_refptr<const UsbInterfaceDescriptor> descriptor | 624 scoped_refptr<const UsbInterfaceDescriptor> descriptor = |
| 508 = usbInterface->GetAltSetting(j); | 625 usbInterface->GetAltSetting(j); |
| 509 std::vector<linked_ptr<EndpointDescriptor> > endpoints; | 626 std::vector<linked_ptr<EndpointDescriptor> > endpoints; |
| 510 for (size_t k = 0, numEndpoints = descriptor->GetNumEndpoints(); | 627 for (size_t k = 0, numEndpoints = descriptor->GetNumEndpoints(); |
| 511 k < numEndpoints; k++) { | 628 k < numEndpoints; ++k) { |
| 512 scoped_refptr<const UsbEndpointDescriptor> endpoint | 629 scoped_refptr<const UsbEndpointDescriptor> endpoint = |
| 513 = descriptor->GetEndpoint(k); | 630 descriptor->GetEndpoint(k); |
| 514 linked_ptr<EndpointDescriptor> endpoint_desc(new EndpointDescriptor()); | 631 linked_ptr<EndpointDescriptor> endpoint_desc(new EndpointDescriptor()); |
| 515 | 632 |
| 516 TransferType type; | 633 TransferType type; |
| 517 Direction direction; | 634 Direction direction; |
| 518 SynchronizationType synchronization; | 635 SynchronizationType synchronization; |
| 519 UsageType usage; | 636 UsageType usage; |
| 520 | 637 |
| 521 if (!ConvertTransferTypeSafely(endpoint->GetTransferType(), &type) || | 638 if (!ConvertTransferTypeSafely(endpoint->GetTransferType(), &type) || |
| 522 !ConvertDirectionSafely(endpoint->GetDirection(), &direction) || | 639 !ConvertDirectionSafely(endpoint->GetDirection(), &direction) || |
| 523 !ConvertSynchronizationTypeSafely( | 640 !ConvertSynchronizationTypeSafely( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 | 713 |
| 597 UsbCloseDeviceFunction::~UsbCloseDeviceFunction() {} | 714 UsbCloseDeviceFunction::~UsbCloseDeviceFunction() {} |
| 598 | 715 |
| 599 bool UsbCloseDeviceFunction::Prepare() { | 716 bool UsbCloseDeviceFunction::Prepare() { |
| 600 parameters_ = CloseDevice::Params::Create(*args_); | 717 parameters_ = CloseDevice::Params::Create(*args_); |
| 601 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 718 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 602 return true; | 719 return true; |
| 603 } | 720 } |
| 604 | 721 |
| 605 void UsbCloseDeviceFunction::AsyncWorkStart() { | 722 void UsbCloseDeviceFunction::AsyncWorkStart() { |
| 606 UsbDeviceResource* const resource = GetUsbDeviceResource( | 723 UsbDeviceResource* const resource = |
| 607 parameters_->device.handle); | 724 GetUsbDeviceResource(parameters_->handle.handle); |
| 608 if (!resource) { | 725 if (!resource) { |
| 609 CompleteWithError(kErrorNoDevice); | 726 CompleteWithError(kErrorNoDevice); |
| 610 return; | 727 return; |
| 611 } | 728 } |
| 612 | 729 |
| 613 resource->device()->Close(base::Bind(&UsbCloseDeviceFunction::OnCompleted, | 730 resource->Close(base::Bind(&UsbCloseDeviceFunction::OnCompleted, this)); |
| 614 this)); | 731 RemoveUsbDeviceResource(parameters_->handle.handle); |
| 615 RemoveUsbDeviceResource(parameters_->device.handle); | |
| 616 } | 732 } |
| 617 | 733 |
| 618 void UsbCloseDeviceFunction::OnCompleted() { | 734 void UsbCloseDeviceFunction::OnCompleted() { AsyncWorkCompleted(); } |
| 619 AsyncWorkCompleted(); | |
| 620 } | |
| 621 | 735 |
| 622 UsbClaimInterfaceFunction::UsbClaimInterfaceFunction() {} | 736 UsbClaimInterfaceFunction::UsbClaimInterfaceFunction() {} |
| 623 | 737 |
| 624 UsbClaimInterfaceFunction::~UsbClaimInterfaceFunction() {} | 738 UsbClaimInterfaceFunction::~UsbClaimInterfaceFunction() {} |
| 625 | 739 |
| 626 bool UsbClaimInterfaceFunction::Prepare() { | 740 bool UsbClaimInterfaceFunction::Prepare() { |
| 627 parameters_ = ClaimInterface::Params::Create(*args_); | 741 parameters_ = ClaimInterface::Params::Create(*args_); |
| 628 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 742 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 629 return true; | 743 return true; |
| 630 } | 744 } |
| 631 | 745 |
| 632 void UsbClaimInterfaceFunction::AsyncWorkStart() { | 746 void UsbClaimInterfaceFunction::AsyncWorkStart() { |
| 633 UsbDeviceResource* resource = | 747 UsbDeviceResource* resource = |
| 634 GetUsbDeviceResource(parameters_->device.handle); | 748 GetUsbDeviceResource(parameters_->handle.handle); |
| 635 if (!resource) { | 749 if (!resource) { |
| 636 CompleteWithError(kErrorNoDevice); | 750 CompleteWithError(kErrorNoDevice); |
| 637 return; | 751 return; |
| 638 } | 752 } |
| 639 | 753 |
| 640 resource->device()->ClaimInterface(parameters_->interface_number, | 754 resource->ClaimInterface( |
| 755 parameters_->interface_number, |
| 641 base::Bind(&UsbClaimInterfaceFunction::OnCompleted, this)); | 756 base::Bind(&UsbClaimInterfaceFunction::OnCompleted, this)); |
| 642 } | 757 } |
| 643 | 758 |
| 644 void UsbClaimInterfaceFunction::OnCompleted(bool success) { | 759 void UsbClaimInterfaceFunction::OnCompleted(bool success) { |
| 645 if (!success) | 760 if (!success) |
| 646 SetError(kErrorCannotClaimInterface); | 761 SetError(kErrorCannotClaimInterface); |
| 647 AsyncWorkCompleted(); | 762 AsyncWorkCompleted(); |
| 648 } | 763 } |
| 649 | 764 |
| 650 UsbReleaseInterfaceFunction::UsbReleaseInterfaceFunction() {} | 765 UsbReleaseInterfaceFunction::UsbReleaseInterfaceFunction() {} |
| 651 | 766 |
| 652 UsbReleaseInterfaceFunction::~UsbReleaseInterfaceFunction() {} | 767 UsbReleaseInterfaceFunction::~UsbReleaseInterfaceFunction() {} |
| 653 | 768 |
| 654 bool UsbReleaseInterfaceFunction::Prepare() { | 769 bool UsbReleaseInterfaceFunction::Prepare() { |
| 655 parameters_ = ReleaseInterface::Params::Create(*args_); | 770 parameters_ = ReleaseInterface::Params::Create(*args_); |
| 656 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 771 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 657 return true; | 772 return true; |
| 658 } | 773 } |
| 659 | 774 |
| 660 void UsbReleaseInterfaceFunction::AsyncWorkStart() { | 775 void UsbReleaseInterfaceFunction::AsyncWorkStart() { |
| 661 UsbDeviceResource* resource = | 776 UsbDeviceResource* resource = |
| 662 GetUsbDeviceResource(parameters_->device.handle); | 777 GetUsbDeviceResource(parameters_->handle.handle); |
| 663 if (!resource) { | 778 if (!resource) { |
| 664 CompleteWithError(kErrorNoDevice); | 779 CompleteWithError(kErrorNoDevice); |
| 665 return; | 780 return; |
| 666 } | 781 } |
| 667 | 782 |
| 668 resource->device()->ReleaseInterface(parameters_->interface_number, | 783 resource->ReleaseInterface( |
| 784 parameters_->interface_number, |
| 669 base::Bind(&UsbReleaseInterfaceFunction::OnCompleted, this)); | 785 base::Bind(&UsbReleaseInterfaceFunction::OnCompleted, this)); |
| 670 } | 786 } |
| 671 | 787 |
| 672 void UsbReleaseInterfaceFunction::OnCompleted(bool success) { | 788 void UsbReleaseInterfaceFunction::OnCompleted(bool success) { |
| 673 if (!success) | 789 if (!success) |
| 674 SetError(kErrorCannotReleaseInterface); | 790 SetError(kErrorCannotReleaseInterface); |
| 675 AsyncWorkCompleted(); | 791 AsyncWorkCompleted(); |
| 676 } | 792 } |
| 677 | 793 |
| 678 UsbSetInterfaceAlternateSettingFunction:: | 794 UsbSetInterfaceAlternateSettingFunction:: |
| 679 UsbSetInterfaceAlternateSettingFunction() {} | 795 UsbSetInterfaceAlternateSettingFunction() {} |
| 680 | 796 |
| 681 UsbSetInterfaceAlternateSettingFunction:: | 797 UsbSetInterfaceAlternateSettingFunction:: |
| 682 ~UsbSetInterfaceAlternateSettingFunction() {} | 798 ~UsbSetInterfaceAlternateSettingFunction() {} |
| 683 | 799 |
| 684 bool UsbSetInterfaceAlternateSettingFunction::Prepare() { | 800 bool UsbSetInterfaceAlternateSettingFunction::Prepare() { |
| 685 parameters_ = SetInterfaceAlternateSetting::Params::Create(*args_); | 801 parameters_ = SetInterfaceAlternateSetting::Params::Create(*args_); |
| 686 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 802 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 687 return true; | 803 return true; |
| 688 } | 804 } |
| 689 | 805 |
| 690 void UsbSetInterfaceAlternateSettingFunction::AsyncWorkStart() { | 806 void UsbSetInterfaceAlternateSettingFunction::AsyncWorkStart() { |
| 691 UsbDeviceResource* resource = | 807 UsbDeviceResource* resource = |
| 692 GetUsbDeviceResource(parameters_->device.handle); | 808 GetUsbDeviceResource(parameters_->handle.handle); |
| 693 if (!resource) { | 809 if (!resource) { |
| 694 CompleteWithError(kErrorNoDevice); | 810 CompleteWithError(kErrorNoDevice); |
| 695 return; | 811 return; |
| 696 } | 812 } |
| 697 | 813 |
| 698 resource->device()->SetInterfaceAlternateSetting( | 814 resource->SetInterfaceAlternateSetting( |
| 699 parameters_->interface_number, | 815 parameters_->interface_number, parameters_->alternate_setting, |
| 700 parameters_->alternate_setting, | |
| 701 base::Bind(&UsbSetInterfaceAlternateSettingFunction::OnCompleted, this)); | 816 base::Bind(&UsbSetInterfaceAlternateSettingFunction::OnCompleted, this)); |
| 702 } | 817 } |
| 703 | 818 |
| 704 void UsbSetInterfaceAlternateSettingFunction::OnCompleted(bool success) { | 819 void UsbSetInterfaceAlternateSettingFunction::OnCompleted(bool success) { |
| 705 if (!success) | 820 if (!success) |
| 706 SetError(kErrorCannotSetInterfaceAlternateSetting); | 821 SetError(kErrorCannotSetInterfaceAlternateSetting); |
| 707 AsyncWorkCompleted(); | 822 AsyncWorkCompleted(); |
| 708 } | 823 } |
| 709 | 824 |
| 710 UsbControlTransferFunction::UsbControlTransferFunction() {} | 825 UsbControlTransferFunction::UsbControlTransferFunction() {} |
| 711 | 826 |
| 712 UsbControlTransferFunction::~UsbControlTransferFunction() {} | 827 UsbControlTransferFunction::~UsbControlTransferFunction() {} |
| 713 | 828 |
| 714 bool UsbControlTransferFunction::Prepare() { | 829 bool UsbControlTransferFunction::Prepare() { |
| 715 parameters_ = ControlTransfer::Params::Create(*args_); | 830 parameters_ = ControlTransfer::Params::Create(*args_); |
| 716 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 831 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 717 return true; | 832 return true; |
| 718 } | 833 } |
| 719 | 834 |
| 720 void UsbControlTransferFunction::AsyncWorkStart() { | 835 void UsbControlTransferFunction::AsyncWorkStart() { |
| 721 UsbDeviceResource* const resource = GetUsbDeviceResource( | 836 UsbDeviceResource* const resource = |
| 722 parameters_->device.handle); | 837 GetUsbDeviceResource(parameters_->handle.handle); |
| 723 if (!resource) { | 838 if (!resource) { |
| 724 CompleteWithError(kErrorNoDevice); | 839 CompleteWithError(kErrorNoDevice); |
| 725 return; | 840 return; |
| 726 } | 841 } |
| 727 | 842 |
| 728 const ControlTransferInfo& transfer = parameters_->transfer_info; | 843 const ControlTransferInfo& transfer = parameters_->transfer_info; |
| 729 | 844 |
| 730 UsbEndpointDirection direction; | 845 UsbEndpointDirection direction; |
| 731 UsbDevice::TransferRequestType request_type; | 846 UsbDeviceHandle::TransferRequestType request_type; |
| 732 UsbDevice::TransferRecipient recipient; | 847 UsbDeviceHandle::TransferRecipient recipient; |
| 733 size_t size = 0; | 848 size_t size = 0; |
| 734 | 849 |
| 735 if (!ConvertDirectionSafely(transfer.direction, &direction) || | 850 if (!ConvertDirectionSafely(transfer.direction, &direction) || |
| 736 !ConvertRequestTypeSafely(transfer.request_type, &request_type) || | 851 !ConvertRequestTypeSafely(transfer.request_type, &request_type) || |
| 737 !ConvertRecipientSafely(transfer.recipient, &recipient)) { | 852 !ConvertRecipientSafely(transfer.recipient, &recipient)) { |
| 738 AsyncWorkCompleted(); | 853 AsyncWorkCompleted(); |
| 739 return; | 854 return; |
| 740 } | 855 } |
| 741 | 856 |
| 742 if (!GetTransferSize(transfer, &size)) { | 857 if (!GetTransferSize(transfer, &size)) { |
| 743 CompleteWithError(kErrorInvalidTransferLength); | 858 CompleteWithError(kErrorInvalidTransferLength); |
| 744 return; | 859 return; |
| 745 } | 860 } |
| 746 | 861 |
| 747 scoped_refptr<net::IOBuffer> buffer = CreateBufferForTransfer( | 862 scoped_refptr<net::IOBuffer> buffer = |
| 748 transfer, direction, size); | 863 CreateBufferForTransfer(transfer, direction, size); |
| 749 if (!buffer.get()) { | 864 if (!buffer.get()) { |
| 750 CompleteWithError(kErrorMalformedParameters); | 865 CompleteWithError(kErrorMalformedParameters); |
| 751 return; | 866 return; |
| 752 } | 867 } |
| 753 | 868 |
| 754 resource->device()->ControlTransfer( | 869 resource->ControlTransfer( |
| 755 direction, | 870 direction, request_type, recipient, transfer.request, transfer.value, |
| 756 request_type, | 871 transfer.index, buffer.get(), size, 0, |
| 757 recipient, | |
| 758 transfer.request, | |
| 759 transfer.value, | |
| 760 transfer.index, | |
| 761 buffer.get(), | |
| 762 size, | |
| 763 0, | |
| 764 base::Bind(&UsbControlTransferFunction::OnCompleted, this)); | 872 base::Bind(&UsbControlTransferFunction::OnCompleted, this)); |
| 765 } | 873 } |
| 766 | 874 |
| 767 UsbBulkTransferFunction::UsbBulkTransferFunction() {} | 875 UsbBulkTransferFunction::UsbBulkTransferFunction() {} |
| 768 | 876 |
| 769 UsbBulkTransferFunction::~UsbBulkTransferFunction() {} | 877 UsbBulkTransferFunction::~UsbBulkTransferFunction() {} |
| 770 | 878 |
| 771 bool UsbBulkTransferFunction::Prepare() { | 879 bool UsbBulkTransferFunction::Prepare() { |
| 772 parameters_ = BulkTransfer::Params::Create(*args_); | 880 parameters_ = BulkTransfer::Params::Create(*args_); |
| 773 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 881 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 774 return true; | 882 return true; |
| 775 } | 883 } |
| 776 | 884 |
| 777 void UsbBulkTransferFunction::AsyncWorkStart() { | 885 void UsbBulkTransferFunction::AsyncWorkStart() { |
| 778 UsbDeviceResource* const resource = GetUsbDeviceResource( | 886 UsbDeviceResource* const resource = |
| 779 parameters_->device.handle); | 887 GetUsbDeviceResource(parameters_->handle.handle); |
| 780 if (!resource) { | 888 if (!resource) { |
| 781 CompleteWithError(kErrorNoDevice); | 889 CompleteWithError(kErrorNoDevice); |
| 782 return; | 890 return; |
| 783 } | 891 } |
| 784 | 892 |
| 785 const GenericTransferInfo& transfer = parameters_->transfer_info; | 893 const GenericTransferInfo& transfer = parameters_->transfer_info; |
| 786 | 894 |
| 787 UsbEndpointDirection direction; | 895 UsbEndpointDirection direction; |
| 788 size_t size = 0; | 896 size_t size = 0; |
| 789 | 897 |
| 790 if (!ConvertDirectionSafely(transfer.direction, &direction)) { | 898 if (!ConvertDirectionSafely(transfer.direction, &direction)) { |
| 791 AsyncWorkCompleted(); | 899 AsyncWorkCompleted(); |
| 792 return; | 900 return; |
| 793 } | 901 } |
| 794 | 902 |
| 795 if (!GetTransferSize(transfer, &size)) { | 903 if (!GetTransferSize(transfer, &size)) { |
| 796 CompleteWithError(kErrorInvalidTransferLength); | 904 CompleteWithError(kErrorInvalidTransferLength); |
| 797 return; | 905 return; |
| 798 } | 906 } |
| 799 | 907 |
| 800 scoped_refptr<net::IOBuffer> buffer = CreateBufferForTransfer( | 908 scoped_refptr<net::IOBuffer> buffer = |
| 801 transfer, direction, size); | 909 CreateBufferForTransfer(transfer, direction, size); |
| 802 if (!buffer.get()) { | 910 if (!buffer.get()) { |
| 803 CompleteWithError(kErrorMalformedParameters); | 911 CompleteWithError(kErrorMalformedParameters); |
| 804 return; | 912 return; |
| 805 } | 913 } |
| 806 | 914 |
| 807 resource->device() | 915 resource->BulkTransfer( |
| 808 ->BulkTransfer(direction, | 916 direction, transfer.endpoint, buffer.get(), size, 0, |
| 809 transfer.endpoint, | 917 base::Bind(&UsbBulkTransferFunction::OnCompleted, this)); |
| 810 buffer.get(), | |
| 811 size, | |
| 812 0, | |
| 813 base::Bind(&UsbBulkTransferFunction::OnCompleted, this)); | |
| 814 } | 918 } |
| 815 | 919 |
| 816 UsbInterruptTransferFunction::UsbInterruptTransferFunction() {} | 920 UsbInterruptTransferFunction::UsbInterruptTransferFunction() {} |
| 817 | 921 |
| 818 UsbInterruptTransferFunction::~UsbInterruptTransferFunction() {} | 922 UsbInterruptTransferFunction::~UsbInterruptTransferFunction() {} |
| 819 | 923 |
| 820 bool UsbInterruptTransferFunction::Prepare() { | 924 bool UsbInterruptTransferFunction::Prepare() { |
| 821 parameters_ = InterruptTransfer::Params::Create(*args_); | 925 parameters_ = InterruptTransfer::Params::Create(*args_); |
| 822 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 926 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 823 return true; | 927 return true; |
| 824 } | 928 } |
| 825 | 929 |
| 826 void UsbInterruptTransferFunction::AsyncWorkStart() { | 930 void UsbInterruptTransferFunction::AsyncWorkStart() { |
| 827 UsbDeviceResource* const resource = GetUsbDeviceResource( | 931 UsbDeviceResource* const resource = |
| 828 parameters_->device.handle); | 932 GetUsbDeviceResource(parameters_->handle.handle); |
| 829 if (!resource) { | 933 if (!resource) { |
| 830 CompleteWithError(kErrorNoDevice); | 934 CompleteWithError(kErrorNoDevice); |
| 831 return; | 935 return; |
| 832 } | 936 } |
| 833 | 937 |
| 834 const GenericTransferInfo& transfer = parameters_->transfer_info; | 938 const GenericTransferInfo& transfer = parameters_->transfer_info; |
| 835 | 939 |
| 836 UsbEndpointDirection direction; | 940 UsbEndpointDirection direction; |
| 837 size_t size = 0; | 941 size_t size = 0; |
| 838 | 942 |
| 839 if (!ConvertDirectionSafely(transfer.direction, &direction)) { | 943 if (!ConvertDirectionSafely(transfer.direction, &direction)) { |
| 840 AsyncWorkCompleted(); | 944 AsyncWorkCompleted(); |
| 841 return; | 945 return; |
| 842 } | 946 } |
| 843 | 947 |
| 844 if (!GetTransferSize(transfer, &size)) { | 948 if (!GetTransferSize(transfer, &size)) { |
| 845 CompleteWithError(kErrorInvalidTransferLength); | 949 CompleteWithError(kErrorInvalidTransferLength); |
| 846 return; | 950 return; |
| 847 } | 951 } |
| 848 | 952 |
| 849 scoped_refptr<net::IOBuffer> buffer = CreateBufferForTransfer( | 953 scoped_refptr<net::IOBuffer> buffer = |
| 850 transfer, direction, size); | 954 CreateBufferForTransfer(transfer, direction, size); |
| 851 if (!buffer.get()) { | 955 if (!buffer.get()) { |
| 852 CompleteWithError(kErrorMalformedParameters); | 956 CompleteWithError(kErrorMalformedParameters); |
| 853 return; | 957 return; |
| 854 } | 958 } |
| 855 | 959 |
| 856 resource->device()->InterruptTransfer( | 960 resource->InterruptTransfer( |
| 857 direction, | 961 direction, |
| 858 transfer.endpoint, | 962 transfer.endpoint, |
| 859 buffer.get(), | 963 buffer.get(), |
| 860 size, | 964 size, |
| 861 0, | 965 0, |
| 862 base::Bind(&UsbInterruptTransferFunction::OnCompleted, this)); | 966 base::Bind(&UsbInterruptTransferFunction::OnCompleted, this)); |
| 863 } | 967 } |
| 864 | 968 |
| 865 UsbIsochronousTransferFunction::UsbIsochronousTransferFunction() {} | 969 UsbIsochronousTransferFunction::UsbIsochronousTransferFunction() {} |
| 866 | 970 |
| 867 UsbIsochronousTransferFunction::~UsbIsochronousTransferFunction() {} | 971 UsbIsochronousTransferFunction::~UsbIsochronousTransferFunction() {} |
| 868 | 972 |
| 869 bool UsbIsochronousTransferFunction::Prepare() { | 973 bool UsbIsochronousTransferFunction::Prepare() { |
| 870 parameters_ = IsochronousTransfer::Params::Create(*args_); | 974 parameters_ = IsochronousTransfer::Params::Create(*args_); |
| 871 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 975 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 872 return true; | 976 return true; |
| 873 } | 977 } |
| 874 | 978 |
| 875 void UsbIsochronousTransferFunction::AsyncWorkStart() { | 979 void UsbIsochronousTransferFunction::AsyncWorkStart() { |
| 876 UsbDeviceResource* const resource = GetUsbDeviceResource( | 980 UsbDeviceResource* const resource = |
| 877 parameters_->device.handle); | 981 GetUsbDeviceResource(parameters_->handle.handle); |
| 878 if (!resource) { | 982 if (!resource) { |
| 879 CompleteWithError(kErrorNoDevice); | 983 CompleteWithError(kErrorNoDevice); |
| 880 return; | 984 return; |
| 881 } | 985 } |
| 882 | 986 |
| 883 const IsochronousTransferInfo& transfer = parameters_->transfer_info; | 987 const IsochronousTransferInfo& transfer = parameters_->transfer_info; |
| 884 const GenericTransferInfo& generic_transfer = transfer.transfer_info; | 988 const GenericTransferInfo& generic_transfer = transfer.transfer_info; |
| 885 | 989 |
| 886 size_t size = 0; | 990 size_t size = 0; |
| 887 UsbEndpointDirection direction; | 991 UsbEndpointDirection direction; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 904 CompleteWithError(kErrorInvalidPacketLength); | 1008 CompleteWithError(kErrorInvalidPacketLength); |
| 905 return; | 1009 return; |
| 906 } | 1010 } |
| 907 unsigned int packet_length = transfer.packet_length; | 1011 unsigned int packet_length = transfer.packet_length; |
| 908 const uint64 total_length = packets * packet_length; | 1012 const uint64 total_length = packets * packet_length; |
| 909 if (packets > size || total_length > size) { | 1013 if (packets > size || total_length > size) { |
| 910 CompleteWithError(kErrorTransferLength); | 1014 CompleteWithError(kErrorTransferLength); |
| 911 return; | 1015 return; |
| 912 } | 1016 } |
| 913 | 1017 |
| 914 scoped_refptr<net::IOBuffer> buffer = CreateBufferForTransfer( | 1018 scoped_refptr<net::IOBuffer> buffer = |
| 915 generic_transfer, direction, size); | 1019 CreateBufferForTransfer(generic_transfer, direction, size); |
| 916 if (!buffer.get()) { | 1020 if (!buffer.get()) { |
| 917 CompleteWithError(kErrorMalformedParameters); | 1021 CompleteWithError(kErrorMalformedParameters); |
| 918 return; | 1022 return; |
| 919 } | 1023 } |
| 920 | 1024 |
| 921 resource->device()->IsochronousTransfer( | 1025 resource->IsochronousTransfer( |
| 922 direction, | 1026 direction, |
| 923 generic_transfer.endpoint, | 1027 generic_transfer.endpoint, |
| 924 buffer.get(), | 1028 buffer.get(), |
| 925 size, | 1029 size, |
| 926 packets, | 1030 packets, |
| 927 packet_length, | 1031 packet_length, |
| 928 0, | 1032 0, |
| 929 base::Bind(&UsbIsochronousTransferFunction::OnCompleted, this)); | 1033 base::Bind(&UsbIsochronousTransferFunction::OnCompleted, this)); |
| 930 } | 1034 } |
| 931 | 1035 |
| 932 UsbResetDeviceFunction::UsbResetDeviceFunction() {} | 1036 UsbResetDeviceFunction::UsbResetDeviceFunction() {} |
| 933 | 1037 |
| 934 UsbResetDeviceFunction::~UsbResetDeviceFunction() {} | 1038 UsbResetDeviceFunction::~UsbResetDeviceFunction() {} |
| 935 | 1039 |
| 936 bool UsbResetDeviceFunction::Prepare() { | 1040 bool UsbResetDeviceFunction::Prepare() { |
| 937 parameters_ = ResetDevice::Params::Create(*args_); | 1041 parameters_ = ResetDevice::Params::Create(*args_); |
| 938 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 1042 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 939 return true; | 1043 return true; |
| 940 } | 1044 } |
| 941 | 1045 |
| 942 void UsbResetDeviceFunction::AsyncWorkStart() { | 1046 void UsbResetDeviceFunction::AsyncWorkStart() { |
| 943 UsbDeviceResource* const resource = GetUsbDeviceResource( | 1047 UsbDeviceResource* const resource = |
| 944 parameters_->device.handle); | 1048 GetUsbDeviceResource(parameters_->handle.handle); |
| 945 if (!resource) { | 1049 if (!resource) { |
| 946 CompleteWithError(kErrorNoDevice); | 1050 CompleteWithError(kErrorNoDevice); |
| 947 return; | 1051 return; |
| 948 } | 1052 } |
| 949 | 1053 |
| 950 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 1054 BrowserThread::PostTask( |
| 951 base::Bind(&UsbResetDeviceFunction::OnStartResest, | 1055 BrowserThread::FILE, FROM_HERE, |
| 952 this, resource)); | 1056 base::Bind(&UsbResetDeviceFunction::OnStartResest, this, resource)); |
| 953 } | 1057 } |
| 954 | 1058 |
| 955 void UsbResetDeviceFunction::OnStartResest(UsbDeviceResource* resource) { | 1059 void UsbResetDeviceFunction::OnStartResest(UsbDeviceResource* resource) { |
| 956 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1060 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 957 resource->device()->ResetDevice( | 1061 resource->ResetDevice( |
| 958 base::Bind(&UsbResetDeviceFunction::OnCompletedFileThread, this)); | 1062 base::Bind(&UsbResetDeviceFunction::OnCompletedFileThread, this)); |
| 959 } | 1063 } |
| 960 | 1064 |
| 961 void UsbResetDeviceFunction::OnCompletedFileThread(bool success) { | 1065 void UsbResetDeviceFunction::OnCompletedFileThread(bool success) { |
| 962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1066 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 963 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 1067 BrowserThread::PostTask( |
| 964 base::Bind(&UsbResetDeviceFunction::OnCompleted, | 1068 BrowserThread::IO, FROM_HERE, |
| 965 this, success)); | 1069 base::Bind(&UsbResetDeviceFunction::OnCompleted, this, success)); |
| 966 return; | 1070 return; |
| 967 } | 1071 } |
| 968 | 1072 |
| 969 void UsbResetDeviceFunction::OnCompleted(bool success) { | 1073 void UsbResetDeviceFunction::OnCompleted(bool success) { |
| 970 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1074 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 971 if (!success) { | 1075 if (!success) { |
| 972 UsbDeviceResource* const resource = GetUsbDeviceResource( | 1076 UsbDeviceResource* const resource = |
| 973 parameters_->device.handle); | 1077 GetUsbDeviceResource(parameters_->handle.handle); |
| 974 if (!resource) { | 1078 if (!resource) { |
| 975 CompleteWithError(kErrorNoDevice); | 1079 CompleteWithError(kErrorNoDevice); |
| 976 return; | 1080 return; |
| 977 } | 1081 } |
| 978 // Close the device now because the handle is invalid after an | 1082 // Close the device now because the handle is invalid after an |
| 979 // unsuccessful reset. | 1083 // unsuccessful reset. |
| 980 resource->device()->Close( | 1084 resource->Close(base::Bind(&UsbResetDeviceFunction::OnError, this)); |
| 981 base::Bind(&UsbResetDeviceFunction::OnError, this)); | 1085 RemoveUsbDeviceResource(parameters_->handle.handle); |
| 982 return; | 1086 return; |
| 983 } | 1087 } |
| 984 SetResult(Value::CreateBooleanValue(true)); | 1088 SetResult(Value::CreateBooleanValue(true)); |
| 985 AsyncWorkCompleted(); | 1089 AsyncWorkCompleted(); |
| 986 } | 1090 } |
| 987 | 1091 |
| 988 void UsbResetDeviceFunction::OnError() { | 1092 void UsbResetDeviceFunction::OnError() { |
| 989 RemoveUsbDeviceResource(parameters_->device.handle); | |
| 990 SetError(kErrorResetDevice); | 1093 SetError(kErrorResetDevice); |
| 991 SetResult(Value::CreateBooleanValue(false)); | 1094 SetResult(Value::CreateBooleanValue(false)); |
| 992 AsyncWorkCompleted(); | 1095 AsyncWorkCompleted(); |
| 993 } | 1096 } |
| 994 | 1097 |
| 995 } // namespace extensions | 1098 } // namespace extensions |
| OLD | NEW |