| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "chrome/browser/extensions/api/api_function.h" | 11 #include "chrome/browser/extensions/api/api_function.h" |
| 12 #include "chrome/browser/extensions/api/api_resource_manager.h" | 12 #include "chrome/browser/extensions/api/api_resource_manager.h" |
| 13 #include "chrome/browser/usb/usb_device.h" | 13 #include "chrome/browser/usb/usb_device_handle.h" |
| 14 #include "chrome/common/extensions/api/usb.h" | 14 #include "chrome/common/extensions/api/usb.h" |
| 15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 16 | 16 |
| 17 class UsbDevice; | |
| 18 | |
| 19 namespace extensions { | 17 namespace extensions { |
| 20 | 18 |
| 21 class UsbDeviceResource; | 19 class UsbDeviceResource; |
| 22 | 20 |
| 23 class UsbAsyncApiFunction : public AsyncApiFunction { | 21 class UsbAsyncApiFunction : public AsyncApiFunction { |
| 24 public: | 22 public: |
| 25 UsbAsyncApiFunction(); | 23 UsbAsyncApiFunction(); |
| 26 | 24 |
| 27 protected: | 25 protected: |
| 28 virtual ~UsbAsyncApiFunction(); | 26 virtual ~UsbAsyncApiFunction(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 39 }; | 37 }; |
| 40 | 38 |
| 41 class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction { | 39 class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction { |
| 42 protected: | 40 protected: |
| 43 UsbAsyncApiTransferFunction(); | 41 UsbAsyncApiTransferFunction(); |
| 44 virtual ~UsbAsyncApiTransferFunction(); | 42 virtual ~UsbAsyncApiTransferFunction(); |
| 45 | 43 |
| 46 bool ConvertDirectionSafely(const extensions::api::usb::Direction& input, | 44 bool ConvertDirectionSafely(const extensions::api::usb::Direction& input, |
| 47 UsbEndpointDirection* output); | 45 UsbEndpointDirection* output); |
| 48 bool ConvertRequestTypeSafely(const extensions::api::usb::RequestType& input, | 46 bool ConvertRequestTypeSafely(const extensions::api::usb::RequestType& input, |
| 49 UsbDevice::TransferRequestType* output); | 47 UsbDeviceHandle::TransferRequestType* output); |
| 50 bool ConvertRecipientSafely(const extensions::api::usb::Recipient& input, | 48 bool ConvertRecipientSafely(const extensions::api::usb::Recipient& input, |
| 51 UsbDevice::TransferRecipient* output); | 49 UsbDeviceHandle::TransferRecipient* output); |
| 52 | 50 |
| 53 void OnCompleted(UsbTransferStatus status, | 51 void OnCompleted(UsbTransferStatus status, scoped_refptr<net::IOBuffer> data, |
| 54 scoped_refptr<net::IOBuffer> data, | |
| 55 size_t length); | 52 size_t length); |
| 56 }; | 53 }; |
| 57 | 54 |
| 58 class UsbFindDevicesFunction : public UsbAsyncApiFunction { | 55 class UsbGetDevicesFunction : public UsbAsyncApiFunction { |
| 56 public: |
| 57 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES) |
| 58 |
| 59 UsbGetDevicesFunction(); |
| 60 |
| 61 static void SetDeviceForTest(UsbDeviceHandle* device); |
| 62 |
| 63 protected: |
| 64 virtual ~UsbGetDevicesFunction(); |
| 65 |
| 66 virtual bool PrePrepare() OVERRIDE; |
| 67 virtual bool Prepare() OVERRIDE; |
| 68 virtual void AsyncWorkStart() OVERRIDE; |
| 69 |
| 70 // Called on FILE thread. |
| 71 void OnDevicesFound(); |
| 72 virtual void OnCompleted(); |
| 73 |
| 74 scoped_ptr<base::ListValue> result_; |
| 75 std::vector<int> devices_; |
| 76 int vendor_id_; |
| 77 int product_id_; |
| 78 int interface_id_; |
| 79 UsbService* service_; |
| 80 }; |
| 81 |
| 82 class UsbFindDevicesFunction : public UsbGetDevicesFunction { |
| 59 public: | 83 public: |
| 60 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES) | 84 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES) |
| 61 | 85 |
| 62 UsbFindDevicesFunction(); | 86 UsbFindDevicesFunction(); |
| 63 | 87 |
| 64 static void SetDeviceForTest(UsbDevice* device); | |
| 65 | |
| 66 protected: | 88 protected: |
| 67 virtual ~UsbFindDevicesFunction(); | 89 virtual ~UsbFindDevicesFunction(); |
| 68 | 90 |
| 69 virtual bool Prepare() OVERRIDE; | 91 virtual bool Prepare() OVERRIDE; |
| 92 |
| 93 // Called on FILE thread. |
| 94 virtual void OnCompleted() OVERRIDE; |
| 95 |
| 96 // Called on IO thread. |
| 97 void OpenDevices(); |
| 98 |
| 99 std::vector<scoped_refptr<UsbDeviceHandle> > handles_; |
| 100 }; |
| 101 |
| 102 class UsbOpenDeviceFunction : public UsbAsyncApiFunction { |
| 103 public: |
| 104 DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE) |
| 105 |
| 106 UsbOpenDeviceFunction(); |
| 107 |
| 108 protected: |
| 109 virtual ~UsbOpenDeviceFunction(); |
| 110 |
| 111 virtual bool PrePrepare() OVERRIDE; |
| 112 virtual bool Prepare() OVERRIDE; |
| 70 virtual void AsyncWorkStart() OVERRIDE; | 113 virtual void AsyncWorkStart() OVERRIDE; |
| 71 | 114 |
| 72 private: | 115 private: |
| 73 void OnCompleted(); | 116 void OpenDevice(); |
| 117 void OnCompleted(scoped_refptr<UsbDeviceHandle> handle); |
| 74 | 118 |
| 75 scoped_ptr<base::ListValue> result_; | 119 scoped_ptr<extensions::api::usb::OpenDevice::Params> parameters_; |
| 76 std::vector<scoped_refptr<UsbDevice> > devices_; | 120 UsbService* service_; |
| 77 scoped_ptr<extensions::api::usb::FindDevices::Params> parameters_; | |
| 78 }; | 121 }; |
| 79 | 122 |
| 80 class UsbListInterfacesFunction : public UsbAsyncApiFunction { | 123 class UsbListInterfacesFunction : public UsbAsyncApiFunction { |
| 81 public: | 124 public: |
| 82 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) | 125 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) |
| 83 | 126 |
| 84 UsbListInterfacesFunction(); | 127 UsbListInterfacesFunction(); |
| 85 | 128 |
| 86 protected: | 129 protected: |
| 87 virtual ~UsbListInterfacesFunction(); | 130 virtual ~UsbListInterfacesFunction(); |
| 88 | 131 |
| 89 virtual bool Prepare() OVERRIDE; | 132 virtual bool Prepare() OVERRIDE; |
| 90 virtual void AsyncWorkStart() OVERRIDE; | 133 virtual void AsyncWorkStart() OVERRIDE; |
| 91 | 134 |
| 92 private: | 135 private: |
| 93 void OnCompleted(bool success); | 136 void OnCompleted(bool success); |
| 94 | 137 |
| 95 bool ConvertDirectionSafely(const UsbEndpointDirection& input, | 138 bool ConvertDirectionSafely(const UsbEndpointDirection& input, |
| 96 extensions::api::usb::Direction* output); | 139 extensions::api::usb::Direction* output); |
| 97 bool ConvertSynchronizationTypeSafely( | 140 bool ConvertSynchronizationTypeSafely( |
| 98 const UsbSynchronizationType& input, | 141 const UsbSynchronizationType& input, |
| 99 extensions::api::usb::SynchronizationType* output); | 142 extensions::api::usb::SynchronizationType* output); |
| 100 bool ConvertTransferTypeSafely(const UsbTransferType& input, | 143 bool ConvertTransferTypeSafely(const UsbTransferType& input, |
| 101 extensions::api::usb::TransferType* output); | 144 extensions::api::usb::TransferType* output); |
| 102 bool ConvertUsageTypeSafely(const UsbUsageType& input, | 145 bool ConvertUsageTypeSafely(const UsbUsageType& input, |
| 103 extensions::api::usb::UsageType* output); | 146 extensions::api::usb::UsageType* output); |
| 104 | 147 |
| 105 scoped_ptr<base::ListValue> result_; | 148 scoped_ptr<base::ListValue> result_; |
| 106 scoped_refptr<UsbConfigDescriptor> config_; | 149 scoped_refptr<UsbConfigDescriptor> config_; |
| 107 scoped_ptr<extensions::api::usb::ListInterfaces::Params> parameters_; | 150 scoped_ptr<extensions::api::usb::ListInterfaces::Params> parameters_; |
| 108 }; | 151 }; |
| 109 | 152 |
| 110 class UsbCloseDeviceFunction : public UsbAsyncApiFunction { | 153 class UsbCloseDeviceFunction : public UsbAsyncApiFunction { |
| 111 public: | 154 public: |
| 112 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE) | 155 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE) |
| 113 | 156 |
| 114 UsbCloseDeviceFunction(); | 157 UsbCloseDeviceFunction(); |
| 115 | 158 |
| 116 protected: | 159 protected: |
| 117 virtual ~UsbCloseDeviceFunction(); | 160 virtual ~UsbCloseDeviceFunction(); |
| 118 | 161 |
| 119 virtual bool Prepare() OVERRIDE; | 162 virtual bool Prepare() OVERRIDE; |
| 120 virtual void AsyncWorkStart() OVERRIDE; | 163 virtual void AsyncWorkStart() OVERRIDE; |
| 121 | 164 |
| 165 private: |
| 122 void OnCompleted(); | 166 void OnCompleted(); |
| 123 | 167 |
| 124 private: | |
| 125 scoped_ptr<extensions::api::usb::CloseDevice::Params> parameters_; | 168 scoped_ptr<extensions::api::usb::CloseDevice::Params> parameters_; |
| 126 }; | 169 }; |
| 127 | 170 |
| 128 class UsbClaimInterfaceFunction : public UsbAsyncApiFunction { | 171 class UsbClaimInterfaceFunction : public UsbAsyncApiFunction { |
| 129 public: | 172 public: |
| 130 DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE) | 173 DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE) |
| 131 | 174 |
| 132 UsbClaimInterfaceFunction(); | 175 UsbClaimInterfaceFunction(); |
| 133 | 176 |
| 134 protected: | 177 protected: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 245 |
| 203 UsbBulkTransferFunction(); | 246 UsbBulkTransferFunction(); |
| 204 | 247 |
| 205 protected: | 248 protected: |
| 206 virtual ~UsbBulkTransferFunction(); | 249 virtual ~UsbBulkTransferFunction(); |
| 207 | 250 |
| 208 virtual bool Prepare() OVERRIDE; | 251 virtual bool Prepare() OVERRIDE; |
| 209 virtual void AsyncWorkStart() OVERRIDE; | 252 virtual void AsyncWorkStart() OVERRIDE; |
| 210 | 253 |
| 211 private: | 254 private: |
| 212 scoped_ptr<extensions::api::usb::BulkTransfer::Params> | 255 scoped_ptr<extensions::api::usb::BulkTransfer::Params> parameters_; |
| 213 parameters_; | |
| 214 }; | 256 }; |
| 215 | 257 |
| 216 class UsbInterruptTransferFunction : public UsbAsyncApiTransferFunction { | 258 class UsbInterruptTransferFunction : public UsbAsyncApiTransferFunction { |
| 217 public: | 259 public: |
| 218 DECLARE_EXTENSION_FUNCTION("usb.interruptTransfer", USB_INTERRUPTTRANSFER) | 260 DECLARE_EXTENSION_FUNCTION("usb.interruptTransfer", USB_INTERRUPTTRANSFER) |
| 219 | 261 |
| 220 UsbInterruptTransferFunction(); | 262 UsbInterruptTransferFunction(); |
| 221 | 263 |
| 222 protected: | 264 protected: |
| 223 virtual ~UsbInterruptTransferFunction(); | 265 virtual ~UsbInterruptTransferFunction(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 306 |
| 265 // IO thread. | 307 // IO thread. |
| 266 void OnCompleted(bool success); | 308 void OnCompleted(bool success); |
| 267 void OnError(); | 309 void OnError(); |
| 268 | 310 |
| 269 scoped_ptr<extensions::api::usb::ResetDevice::Params> parameters_; | 311 scoped_ptr<extensions::api::usb::ResetDevice::Params> parameters_; |
| 270 }; | 312 }; |
| 271 } // namespace extensions | 313 } // namespace extensions |
| 272 | 314 |
| 273 #endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ | 315 #endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ |
| OLD | NEW |