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