| 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, |
| 54 scoped_refptr<net::IOBuffer> data, | 52 scoped_refptr<net::IOBuffer> data, |
| 55 size_t length); | 53 size_t length); |
| 56 }; | 54 }; |
| 57 | 55 |
| 58 class UsbFindDevicesFunction : public UsbAsyncApiFunction { | 56 class UsbFindDevicesFunction : public UsbAsyncApiFunction { |
| 59 public: | 57 public: |
| 60 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES) | 58 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES) |
| 61 | 59 |
| 62 UsbFindDevicesFunction(); | 60 UsbFindDevicesFunction(); |
| 63 | 61 |
| 64 static void SetDeviceForTest(UsbDevice* device); | 62 static void SetDeviceForTest(UsbDeviceHandle* device); |
| 65 | 63 |
| 66 protected: | 64 protected: |
| 67 virtual ~UsbFindDevicesFunction(); | 65 virtual ~UsbFindDevicesFunction(); |
| 68 | 66 |
| 67 virtual bool PrePrepare() OVERRIDE; |
| 69 virtual bool Prepare() OVERRIDE; | 68 virtual bool Prepare() OVERRIDE; |
| 70 virtual void AsyncWorkStart() OVERRIDE; | 69 virtual void AsyncWorkStart() OVERRIDE; |
| 71 | 70 |
| 72 private: | 71 private: |
| 73 void OnCompleted(); | 72 void OnCompleted(); |
| 74 | 73 |
| 75 scoped_ptr<base::ListValue> result_; | 74 scoped_ptr<base::ListValue> result_; |
| 76 std::vector<scoped_refptr<UsbDevice> > devices_; | 75 std::vector<int> devices_; |
| 77 scoped_ptr<extensions::api::usb::FindDevices::Params> parameters_; | 76 scoped_ptr<extensions::api::usb::FindDevices::Params> parameters_; |
| 77 UsbService* service_; |
| 78 }; |
| 79 |
| 80 class UsbOpenDeviceFunction : public UsbAsyncApiFunction { |
| 81 public: |
| 82 DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE) |
| 83 |
| 84 UsbOpenDeviceFunction(); |
| 85 |
| 86 protected: |
| 87 virtual ~UsbOpenDeviceFunction(); |
| 88 |
| 89 virtual bool PrePrepare() OVERRIDE; |
| 90 virtual bool Prepare() OVERRIDE; |
| 91 virtual void AsyncWorkStart() OVERRIDE; |
| 92 |
| 93 private: |
| 94 void OnOpened(scoped_refptr<UsbDeviceHandle> handle); |
| 95 void OnCompleted(scoped_refptr<UsbDeviceHandle> handle); |
| 96 |
| 97 scoped_ptr<extensions::api::usb::OpenDevice::Params> parameters_; |
| 98 UsbService* service_; |
| 78 }; | 99 }; |
| 79 | 100 |
| 80 class UsbListInterfacesFunction : public UsbAsyncApiFunction { | 101 class UsbListInterfacesFunction : public UsbAsyncApiFunction { |
| 81 public: | 102 public: |
| 82 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) | 103 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) |
| 83 | 104 |
| 84 UsbListInterfacesFunction(); | 105 UsbListInterfacesFunction(); |
| 85 | 106 |
| 86 protected: | 107 protected: |
| 87 virtual ~UsbListInterfacesFunction(); | 108 virtual ~UsbListInterfacesFunction(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 112 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE) | 133 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE) |
| 113 | 134 |
| 114 UsbCloseDeviceFunction(); | 135 UsbCloseDeviceFunction(); |
| 115 | 136 |
| 116 protected: | 137 protected: |
| 117 virtual ~UsbCloseDeviceFunction(); | 138 virtual ~UsbCloseDeviceFunction(); |
| 118 | 139 |
| 119 virtual bool Prepare() OVERRIDE; | 140 virtual bool Prepare() OVERRIDE; |
| 120 virtual void AsyncWorkStart() OVERRIDE; | 141 virtual void AsyncWorkStart() OVERRIDE; |
| 121 | 142 |
| 143 private: |
| 122 void OnCompleted(); | 144 void OnCompleted(); |
| 123 | 145 |
| 124 private: | |
| 125 scoped_ptr<extensions::api::usb::CloseDevice::Params> parameters_; | 146 scoped_ptr<extensions::api::usb::CloseDevice::Params> parameters_; |
| 126 }; | 147 }; |
| 127 | 148 |
| 128 class UsbClaimInterfaceFunction : public UsbAsyncApiFunction { | 149 class UsbClaimInterfaceFunction : public UsbAsyncApiFunction { |
| 129 public: | 150 public: |
| 130 DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE) | 151 DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE) |
| 131 | 152 |
| 132 UsbClaimInterfaceFunction(); | 153 UsbClaimInterfaceFunction(); |
| 133 | 154 |
| 134 protected: | 155 protected: |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 285 |
| 265 // IO thread. | 286 // IO thread. |
| 266 void OnCompleted(bool success); | 287 void OnCompleted(bool success); |
| 267 void OnError(); | 288 void OnError(); |
| 268 | 289 |
| 269 scoped_ptr<extensions::api::usb::ResetDevice::Params> parameters_; | 290 scoped_ptr<extensions::api::usb::ResetDevice::Params> parameters_; |
| 270 }; | 291 }; |
| 271 } // namespace extensions | 292 } // namespace extensions |
| 272 | 293 |
| 273 #endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ | 294 #endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ |
| OLD | NEW |