| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/usb/usb_api.h" | 5 #include "extensions/browser/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" |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 scoped_refptr<UsbDeviceHandle> | 457 scoped_refptr<UsbDeviceHandle> |
| 458 UsbAsyncApiFunction::GetDeviceHandleOrCompleteWithError( | 458 UsbAsyncApiFunction::GetDeviceHandleOrCompleteWithError( |
| 459 const ConnectionHandle& input_device_handle) { | 459 const ConnectionHandle& input_device_handle) { |
| 460 UsbDeviceResource* resource = | 460 UsbDeviceResource* resource = |
| 461 manager_->Get(extension_->id(), input_device_handle.handle); | 461 manager_->Get(extension_->id(), input_device_handle.handle); |
| 462 if (!resource) { | 462 if (!resource) { |
| 463 CompleteWithError(kErrorNoDevice); | 463 CompleteWithError(kErrorNoDevice); |
| 464 return NULL; | 464 return NULL; |
| 465 } | 465 } |
| 466 | 466 |
| 467 if (!resource->device() || !resource->device()->device()) { | 467 if (!resource->device() || !resource->device()->GetDevice()) { |
| 468 CompleteWithError(kErrorDisconnect); | 468 CompleteWithError(kErrorDisconnect); |
| 469 manager_->Remove(extension_->id(), input_device_handle.handle); | 469 manager_->Remove(extension_->id(), input_device_handle.handle); |
| 470 return NULL; | 470 return NULL; |
| 471 } | 471 } |
| 472 | 472 |
| 473 if (resource->device()->device()->vendor_id() != | 473 if (resource->device()->GetDevice()->vendor_id() != |
| 474 input_device_handle.vendor_id || | 474 input_device_handle.vendor_id || |
| 475 resource->device()->device()->product_id() != | 475 resource->device()->GetDevice()->product_id() != |
| 476 input_device_handle.product_id) { | 476 input_device_handle.product_id) { |
| 477 CompleteWithError(kErrorNoDevice); | 477 CompleteWithError(kErrorNoDevice); |
| 478 return NULL; | 478 return NULL; |
| 479 } | 479 } |
| 480 | 480 |
| 481 return resource->device(); | 481 return resource->device(); |
| 482 } | 482 } |
| 483 | 483 |
| 484 void UsbAsyncApiFunction::RemoveUsbDeviceResource(int api_resource_id) { | 484 void UsbAsyncApiFunction::RemoveUsbDeviceResource(int api_resource_id) { |
| 485 manager_->Remove(extension_->id(), api_resource_id); | 485 manager_->Remove(extension_->id(), api_resource_id); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 | 714 |
| 715 handle_ = device->Open(); | 715 handle_ = device->Open(); |
| 716 if (!handle_) { | 716 if (!handle_) { |
| 717 SetError(kErrorOpen); | 717 SetError(kErrorOpen); |
| 718 AsyncWorkCompleted(); | 718 AsyncWorkCompleted(); |
| 719 return; | 719 return; |
| 720 } | 720 } |
| 721 | 721 |
| 722 SetResult(PopulateConnectionHandle( | 722 SetResult(PopulateConnectionHandle( |
| 723 manager_->Add(new UsbDeviceResource(extension_->id(), handle_)), | 723 manager_->Add(new UsbDeviceResource(extension_->id(), handle_)), |
| 724 handle_->device()->vendor_id(), | 724 handle_->GetDevice()->vendor_id(), |
| 725 handle_->device()->product_id())); | 725 handle_->GetDevice()->product_id())); |
| 726 AsyncWorkCompleted(); | 726 AsyncWorkCompleted(); |
| 727 } | 727 } |
| 728 | 728 |
| 729 UsbListInterfacesFunction::UsbListInterfacesFunction() { | 729 UsbListInterfacesFunction::UsbListInterfacesFunction() { |
| 730 } | 730 } |
| 731 | 731 |
| 732 UsbListInterfacesFunction::~UsbListInterfacesFunction() { | 732 UsbListInterfacesFunction::~UsbListInterfacesFunction() { |
| 733 } | 733 } |
| 734 | 734 |
| 735 bool UsbListInterfacesFunction::Prepare() { | 735 bool UsbListInterfacesFunction::Prepare() { |
| 736 parameters_ = ListInterfaces::Params::Create(*args_); | 736 parameters_ = ListInterfaces::Params::Create(*args_); |
| 737 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 737 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 738 return true; | 738 return true; |
| 739 } | 739 } |
| 740 | 740 |
| 741 void UsbListInterfacesFunction::AsyncWorkStart() { | 741 void UsbListInterfacesFunction::AsyncWorkStart() { |
| 742 scoped_refptr<UsbDeviceHandle> device_handle = | 742 scoped_refptr<UsbDeviceHandle> device_handle = |
| 743 GetDeviceHandleOrCompleteWithError(parameters_->handle); | 743 GetDeviceHandleOrCompleteWithError(parameters_->handle); |
| 744 if (!device_handle) | 744 if (!device_handle) |
| 745 return; | 745 return; |
| 746 | 746 |
| 747 scoped_refptr<UsbConfigDescriptor> config = | 747 scoped_refptr<UsbConfigDescriptor> config = |
| 748 device_handle->device()->ListInterfaces(); | 748 device_handle->GetDevice()->ListInterfaces(); |
| 749 | 749 |
| 750 if (!config) { | 750 if (!config) { |
| 751 SetError(kErrorCannotListInterfaces); | 751 SetError(kErrorCannotListInterfaces); |
| 752 AsyncWorkCompleted(); | 752 AsyncWorkCompleted(); |
| 753 return; | 753 return; |
| 754 } | 754 } |
| 755 | 755 |
| 756 result_.reset(new base::ListValue()); | 756 result_.reset(new base::ListValue()); |
| 757 | 757 |
| 758 for (size_t i = 0, num_interfaces = config->GetNumInterfaces(); | 758 for (size_t i = 0, num_interfaces = config->GetNumInterfaces(); |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 SetResult(new base::FundamentalValue(false)); | 1199 SetResult(new base::FundamentalValue(false)); |
| 1200 CompleteWithError(kErrorResetDevice); | 1200 CompleteWithError(kErrorResetDevice); |
| 1201 return; | 1201 return; |
| 1202 } | 1202 } |
| 1203 | 1203 |
| 1204 SetResult(new base::FundamentalValue(true)); | 1204 SetResult(new base::FundamentalValue(true)); |
| 1205 AsyncWorkCompleted(); | 1205 AsyncWorkCompleted(); |
| 1206 } | 1206 } |
| 1207 | 1207 |
| 1208 } // namespace extensions | 1208 } // namespace extensions |
| OLD | NEW |