| 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 #ifndef EXTENSIONS_BROWSER_API_USB_USB_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_USB_USB_API_H_ |
| 6 #define EXTENSIONS_BROWSER_API_USB_USB_API_H_ | 6 #define EXTENSIONS_BROWSER_API_USB_USB_API_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "components/usb_service/usb_device.h" | 13 #include "device/usb/usb_device.h" |
| 14 #include "components/usb_service/usb_device_handle.h" | 14 #include "device/usb/usb_device_handle.h" |
| 15 #include "extensions/browser/api/api_resource_manager.h" | 15 #include "extensions/browser/api/api_resource_manager.h" |
| 16 #include "extensions/browser/api/async_api_function.h" | 16 #include "extensions/browser/api/async_api_function.h" |
| 17 #include "extensions/common/api/usb.h" | 17 #include "extensions/common/api/usb.h" |
| 18 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 class UsbDeviceResource; | 22 class UsbDeviceResource; |
| 23 | 23 |
| 24 class UsbAsyncApiFunction : public AsyncApiFunction { | 24 class UsbAsyncApiFunction : public AsyncApiFunction { |
| 25 public: | 25 public: |
| 26 UsbAsyncApiFunction(); | 26 UsbAsyncApiFunction(); |
| 27 | 27 |
| 28 protected: | 28 protected: |
| 29 virtual ~UsbAsyncApiFunction(); | 29 virtual ~UsbAsyncApiFunction(); |
| 30 | 30 |
| 31 virtual bool PrePrepare() OVERRIDE; | 31 virtual bool PrePrepare() OVERRIDE; |
| 32 virtual bool Respond() OVERRIDE; | 32 virtual bool Respond() OVERRIDE; |
| 33 | 33 |
| 34 scoped_refptr<usb_service::UsbDevice> GetDeviceOrOrCompleteWithError( | 34 scoped_refptr<device::UsbDevice> GetDeviceOrOrCompleteWithError( |
| 35 const extensions::core_api::usb::Device& input_device); | 35 const extensions::core_api::usb::Device& input_device); |
| 36 | 36 |
| 37 scoped_refptr<usb_service::UsbDeviceHandle> | 37 scoped_refptr<device::UsbDeviceHandle> GetDeviceHandleOrCompleteWithError( |
| 38 GetDeviceHandleOrCompleteWithError( | 38 const extensions::core_api::usb::ConnectionHandle& input_device_handle); |
| 39 const extensions::core_api::usb::ConnectionHandle& | |
| 40 input_device_handle); | |
| 41 | 39 |
| 42 void RemoveUsbDeviceResource(int api_resource_id); | 40 void RemoveUsbDeviceResource(int api_resource_id); |
| 43 | 41 |
| 44 void CompleteWithError(const std::string& error); | 42 void CompleteWithError(const std::string& error); |
| 45 | 43 |
| 46 ApiResourceManager<UsbDeviceResource>* manager_; | 44 ApiResourceManager<UsbDeviceResource>* manager_; |
| 47 }; | 45 }; |
| 48 | 46 |
| 49 class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction { | 47 class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction { |
| 50 protected: | 48 protected: |
| 51 UsbAsyncApiTransferFunction(); | 49 UsbAsyncApiTransferFunction(); |
| 52 virtual ~UsbAsyncApiTransferFunction(); | 50 virtual ~UsbAsyncApiTransferFunction(); |
| 53 | 51 |
| 54 bool ConvertDirectionSafely(const extensions::core_api::usb::Direction& input, | 52 bool ConvertDirectionSafely(const extensions::core_api::usb::Direction& input, |
| 55 usb_service::UsbEndpointDirection* output); | 53 device::UsbEndpointDirection* output); |
| 56 bool ConvertRequestTypeSafely( | 54 bool ConvertRequestTypeSafely( |
| 57 const extensions::core_api::usb::RequestType& input, | 55 const extensions::core_api::usb::RequestType& input, |
| 58 usb_service::UsbDeviceHandle::TransferRequestType* output); | 56 device::UsbDeviceHandle::TransferRequestType* output); |
| 59 bool ConvertRecipientSafely( | 57 bool ConvertRecipientSafely( |
| 60 const extensions::core_api::usb::Recipient& input, | 58 const extensions::core_api::usb::Recipient& input, |
| 61 usb_service::UsbDeviceHandle::TransferRecipient* output); | 59 device::UsbDeviceHandle::TransferRecipient* output); |
| 62 | 60 |
| 63 void OnCompleted(usb_service::UsbTransferStatus status, | 61 void OnCompleted(device::UsbTransferStatus status, |
| 64 scoped_refptr<net::IOBuffer> data, | 62 scoped_refptr<net::IOBuffer> data, |
| 65 size_t length); | 63 size_t length); |
| 66 }; | 64 }; |
| 67 | 65 |
| 68 class UsbFindDevicesFunction : public UsbAsyncApiFunction { | 66 class UsbFindDevicesFunction : public UsbAsyncApiFunction { |
| 69 public: | 67 public: |
| 70 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES) | 68 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES) |
| 71 | 69 |
| 72 UsbFindDevicesFunction(); | 70 UsbFindDevicesFunction(); |
| 73 | 71 |
| 74 protected: | 72 protected: |
| 75 virtual ~UsbFindDevicesFunction(); | 73 virtual ~UsbFindDevicesFunction(); |
| 76 | 74 |
| 77 virtual bool Prepare() OVERRIDE; | 75 virtual bool Prepare() OVERRIDE; |
| 78 virtual void AsyncWorkStart() OVERRIDE; | 76 virtual void AsyncWorkStart() OVERRIDE; |
| 79 | 77 |
| 80 private: | 78 private: |
| 81 void OpenDevices( | 79 void OpenDevices( |
| 82 scoped_ptr<std::vector<scoped_refptr<usb_service::UsbDevice> > > devices); | 80 scoped_ptr<std::vector<scoped_refptr<device::UsbDevice> > > devices); |
| 83 | 81 |
| 84 std::vector<scoped_refptr<usb_service::UsbDeviceHandle> > device_handles_; | 82 std::vector<scoped_refptr<device::UsbDeviceHandle> > device_handles_; |
| 85 scoped_ptr<extensions::core_api::usb::FindDevices::Params> parameters_; | 83 scoped_ptr<extensions::core_api::usb::FindDevices::Params> parameters_; |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 class UsbGetDevicesFunction : public UsbAsyncApiFunction { | 86 class UsbGetDevicesFunction : public UsbAsyncApiFunction { |
| 89 public: | 87 public: |
| 90 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES) | 88 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES) |
| 91 | 89 |
| 92 UsbGetDevicesFunction(); | 90 UsbGetDevicesFunction(); |
| 93 | 91 |
| 94 virtual bool Prepare() OVERRIDE; | 92 virtual bool Prepare() OVERRIDE; |
| 95 virtual void AsyncWorkStart() OVERRIDE; | 93 virtual void AsyncWorkStart() OVERRIDE; |
| 96 | 94 |
| 97 protected: | 95 protected: |
| 98 virtual ~UsbGetDevicesFunction(); | 96 virtual ~UsbGetDevicesFunction(); |
| 99 | 97 |
| 100 private: | 98 private: |
| 101 void EnumerationCompletedFileThread( | 99 void EnumerationCompletedFileThread( |
| 102 scoped_ptr<std::vector<scoped_refptr<usb_service::UsbDevice> > > devices); | 100 scoped_ptr<std::vector<scoped_refptr<device::UsbDevice> > > devices); |
| 103 | 101 |
| 104 scoped_ptr<extensions::core_api::usb::GetDevices::Params> parameters_; | 102 scoped_ptr<extensions::core_api::usb::GetDevices::Params> parameters_; |
| 105 }; | 103 }; |
| 106 | 104 |
| 107 class UsbRequestAccessFunction : public UsbAsyncApiFunction { | 105 class UsbRequestAccessFunction : public UsbAsyncApiFunction { |
| 108 public: | 106 public: |
| 109 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) | 107 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) |
| 110 | 108 |
| 111 UsbRequestAccessFunction(); | 109 UsbRequestAccessFunction(); |
| 112 | 110 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 128 | 126 |
| 129 UsbOpenDeviceFunction(); | 127 UsbOpenDeviceFunction(); |
| 130 | 128 |
| 131 virtual bool Prepare() OVERRIDE; | 129 virtual bool Prepare() OVERRIDE; |
| 132 virtual void AsyncWorkStart() OVERRIDE; | 130 virtual void AsyncWorkStart() OVERRIDE; |
| 133 | 131 |
| 134 protected: | 132 protected: |
| 135 virtual ~UsbOpenDeviceFunction(); | 133 virtual ~UsbOpenDeviceFunction(); |
| 136 | 134 |
| 137 private: | 135 private: |
| 138 scoped_refptr<usb_service::UsbDeviceHandle> handle_; | 136 scoped_refptr<device::UsbDeviceHandle> handle_; |
| 139 scoped_ptr<extensions::core_api::usb::OpenDevice::Params> parameters_; | 137 scoped_ptr<extensions::core_api::usb::OpenDevice::Params> parameters_; |
| 140 }; | 138 }; |
| 141 | 139 |
| 142 class UsbListInterfacesFunction : public UsbAsyncApiFunction { | 140 class UsbListInterfacesFunction : public UsbAsyncApiFunction { |
| 143 public: | 141 public: |
| 144 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) | 142 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) |
| 145 | 143 |
| 146 UsbListInterfacesFunction(); | 144 UsbListInterfacesFunction(); |
| 147 | 145 |
| 148 protected: | 146 protected: |
| 149 virtual ~UsbListInterfacesFunction(); | 147 virtual ~UsbListInterfacesFunction(); |
| 150 | 148 |
| 151 virtual bool Prepare() OVERRIDE; | 149 virtual bool Prepare() OVERRIDE; |
| 152 virtual void AsyncWorkStart() OVERRIDE; | 150 virtual void AsyncWorkStart() OVERRIDE; |
| 153 | 151 |
| 154 private: | 152 private: |
| 155 bool ConvertDirectionSafely(const usb_service::UsbEndpointDirection& input, | 153 bool ConvertDirectionSafely(const device::UsbEndpointDirection& input, |
| 156 extensions::core_api::usb::Direction* output); | 154 extensions::core_api::usb::Direction* output); |
| 157 bool ConvertSynchronizationTypeSafely( | 155 bool ConvertSynchronizationTypeSafely( |
| 158 const usb_service::UsbSynchronizationType& input, | 156 const device::UsbSynchronizationType& input, |
| 159 extensions::core_api::usb::SynchronizationType* output); | 157 extensions::core_api::usb::SynchronizationType* output); |
| 160 bool ConvertTransferTypeSafely( | 158 bool ConvertTransferTypeSafely( |
| 161 const usb_service::UsbTransferType& input, | 159 const device::UsbTransferType& input, |
| 162 extensions::core_api::usb::TransferType* output); | 160 extensions::core_api::usb::TransferType* output); |
| 163 bool ConvertUsageTypeSafely(const usb_service::UsbUsageType& input, | 161 bool ConvertUsageTypeSafely(const device::UsbUsageType& input, |
| 164 extensions::core_api::usb::UsageType* output); | 162 extensions::core_api::usb::UsageType* output); |
| 165 | 163 |
| 166 scoped_ptr<base::ListValue> result_; | 164 scoped_ptr<base::ListValue> result_; |
| 167 scoped_ptr<extensions::core_api::usb::ListInterfaces::Params> parameters_; | 165 scoped_ptr<extensions::core_api::usb::ListInterfaces::Params> parameters_; |
| 168 }; | 166 }; |
| 169 | 167 |
| 170 class UsbCloseDeviceFunction : public UsbAsyncApiFunction { | 168 class UsbCloseDeviceFunction : public UsbAsyncApiFunction { |
| 171 public: | 169 public: |
| 172 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE) | 170 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE) |
| 173 | 171 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 306 |
| 309 virtual bool Prepare() OVERRIDE; | 307 virtual bool Prepare() OVERRIDE; |
| 310 virtual void AsyncWorkStart() OVERRIDE; | 308 virtual void AsyncWorkStart() OVERRIDE; |
| 311 | 309 |
| 312 private: | 310 private: |
| 313 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_; | 311 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_; |
| 314 }; | 312 }; |
| 315 } // namespace extensions | 313 } // namespace extensions |
| 316 | 314 |
| 317 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_ | 315 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_ |
| OLD | NEW |