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