| 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 #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 "chrome/browser/extensions/api/api_function.h" | 13 #include "chrome/browser/extensions/api/api_function.h" |
| 13 #include "chrome/browser/extensions/api/api_resource_manager.h" | 14 #include "chrome/browser/extensions/api/api_resource_manager.h" |
| 14 #include "chrome/browser/usb/usb_device.h" | 15 #include "chrome/browser/usb/usb_device.h" |
| 15 #include "chrome/browser/usb/usb_device_handle.h" | 16 #include "chrome/browser/usb/usb_device_handle.h" |
| 16 #include "chrome/common/extensions/api/usb.h" | 17 #include "chrome/common/extensions/api/usb.h" |
| 17 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| 18 | 19 |
| 20 class UsbDevice; |
| 19 class UsbDeviceHandle; | 21 class UsbDeviceHandle; |
| 20 class UsbService; | 22 class UsbService; |
| 21 | 23 |
| 22 namespace extensions { | 24 namespace extensions { |
| 23 | 25 |
| 24 class UsbDeviceResource; | 26 class UsbDeviceResource; |
| 25 | 27 |
| 26 class UsbAsyncApiFunction : public AsyncApiFunction { | 28 class UsbAsyncApiFunction : public AsyncApiFunction { |
| 27 public: | 29 public: |
| 28 UsbAsyncApiFunction(); | 30 UsbAsyncApiFunction(); |
| 29 | 31 |
| 30 protected: | 32 protected: |
| 31 virtual ~UsbAsyncApiFunction(); | 33 virtual ~UsbAsyncApiFunction(); |
| 32 | 34 |
| 33 virtual bool PrePrepare() OVERRIDE; | 35 virtual bool PrePrepare() OVERRIDE; |
| 34 virtual bool Respond() OVERRIDE; | 36 virtual bool Respond() OVERRIDE; |
| 35 | 37 |
| 36 UsbDeviceResource* GetUsbDeviceResource(int api_resource_id); | 38 scoped_refptr<UsbDevice> GetDeviceOrOrCompleteWithError( |
| 39 const extensions::api::usb::Device& input_device); |
| 40 |
| 41 scoped_refptr<UsbDeviceHandle> GetDeviceHandleOrCompleteWithError( |
| 42 const extensions::api::usb::ConnectionHandle& input_device_handle); |
| 43 |
| 37 void RemoveUsbDeviceResource(int api_resource_id); | 44 void RemoveUsbDeviceResource(int api_resource_id); |
| 38 | 45 |
| 39 void CompleteWithError(const std::string& error); | 46 void CompleteWithError(const std::string& error); |
| 40 | 47 |
| 41 ApiResourceManager<UsbDeviceResource>* manager_; | 48 ApiResourceManager<UsbDeviceResource>* manager_; |
| 42 }; | 49 }; |
| 43 | 50 |
| 44 class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction { | 51 class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction { |
| 45 protected: | 52 protected: |
| 46 UsbAsyncApiTransferFunction(); | 53 UsbAsyncApiTransferFunction(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 57 scoped_refptr<net::IOBuffer> data, | 64 scoped_refptr<net::IOBuffer> data, |
| 58 size_t length); | 65 size_t length); |
| 59 }; | 66 }; |
| 60 | 67 |
| 61 class UsbFindDevicesFunction : public UsbAsyncApiFunction { | 68 class UsbFindDevicesFunction : public UsbAsyncApiFunction { |
| 62 public: | 69 public: |
| 63 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES) | 70 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES) |
| 64 | 71 |
| 65 UsbFindDevicesFunction(); | 72 UsbFindDevicesFunction(); |
| 66 | 73 |
| 67 static void SetDeviceForTest(UsbDevice* device); | |
| 68 | |
| 69 protected: | 74 protected: |
| 70 virtual ~UsbFindDevicesFunction(); | 75 virtual ~UsbFindDevicesFunction(); |
| 71 | 76 |
| 72 virtual bool Prepare() OVERRIDE; | 77 virtual bool Prepare() OVERRIDE; |
| 73 virtual void AsyncWorkStart() OVERRIDE; | 78 virtual void AsyncWorkStart() OVERRIDE; |
| 74 | 79 |
| 75 private: | 80 private: |
| 81 void OpenDevices(scoped_ptr<std::vector<scoped_refptr<UsbDevice> > > devices); |
| 82 |
| 83 scoped_ptr<base::ListValue> result_; |
| 84 std::vector<scoped_refptr<UsbDeviceHandle> > device_handles_; |
| 85 scoped_ptr<extensions::api::usb::FindDevices::Params> parameters_; |
| 86 }; |
| 87 |
| 88 class UsbGetDevicesFunction : public UsbAsyncApiFunction { |
| 89 public: |
| 90 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES) |
| 91 |
| 92 UsbGetDevicesFunction(); |
| 93 |
| 94 static void SetDeviceForTest(UsbDevice* device); |
| 95 |
| 96 virtual bool Prepare() OVERRIDE; |
| 97 virtual void AsyncWorkStart() OVERRIDE; |
| 98 |
| 99 protected: |
| 100 virtual ~UsbGetDevicesFunction(); |
| 101 |
| 102 private: |
| 76 void EnumerationCompletedFileThread( | 103 void EnumerationCompletedFileThread( |
| 77 scoped_ptr<std::vector<scoped_refptr<UsbDevice> > > devices); | 104 scoped_ptr<std::vector<scoped_refptr<UsbDevice> > > devices); |
| 78 | 105 |
| 79 scoped_ptr<base::ListValue> result_; | 106 scoped_ptr<base::ListValue> result_; |
| 80 std::vector<scoped_refptr<UsbDeviceHandle> > device_handles_; | 107 scoped_ptr<extensions::api::usb::GetDevices::Params> parameters_; |
| 81 scoped_ptr<extensions::api::usb::FindDevices::Params> parameters_; | 108 }; |
| 109 |
| 110 class UsbRequestAccessFunction : public UsbAsyncApiFunction { |
| 111 public: |
| 112 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) |
| 113 |
| 114 UsbRequestAccessFunction(); |
| 115 |
| 116 virtual bool Prepare() OVERRIDE; |
| 117 virtual void AsyncWorkStart() OVERRIDE; |
| 118 |
| 119 protected: |
| 120 virtual ~UsbRequestAccessFunction(); |
| 121 |
| 122 void OnCompleted(bool success); |
| 123 |
| 124 private: |
| 125 scoped_ptr<extensions::api::usb::RequestAccess::Params> parameters_; |
| 126 }; |
| 127 |
| 128 class UsbOpenDeviceFunction : public UsbAsyncApiFunction { |
| 129 public: |
| 130 DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE) |
| 131 |
| 132 UsbOpenDeviceFunction(); |
| 133 |
| 134 virtual bool Prepare() OVERRIDE; |
| 135 virtual void AsyncWorkStart() OVERRIDE; |
| 136 |
| 137 protected: |
| 138 virtual ~UsbOpenDeviceFunction(); |
| 139 |
| 140 private: |
| 141 scoped_refptr<UsbDeviceHandle> handle_; |
| 142 scoped_ptr<extensions::api::usb::OpenDevice::Params> parameters_; |
| 82 }; | 143 }; |
| 83 | 144 |
| 84 class UsbListInterfacesFunction : public UsbAsyncApiFunction { | 145 class UsbListInterfacesFunction : public UsbAsyncApiFunction { |
| 85 public: | 146 public: |
| 86 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) | 147 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) |
| 87 | 148 |
| 88 UsbListInterfacesFunction(); | 149 UsbListInterfacesFunction(); |
| 89 | 150 |
| 90 protected: | 151 protected: |
| 91 virtual ~UsbListInterfacesFunction(); | 152 virtual ~UsbListInterfacesFunction(); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 310 |
| 250 virtual bool Prepare() OVERRIDE; | 311 virtual bool Prepare() OVERRIDE; |
| 251 virtual void AsyncWorkStart() OVERRIDE; | 312 virtual void AsyncWorkStart() OVERRIDE; |
| 252 | 313 |
| 253 private: | 314 private: |
| 254 scoped_ptr<extensions::api::usb::ResetDevice::Params> parameters_; | 315 scoped_ptr<extensions::api::usb::ResetDevice::Params> parameters_; |
| 255 }; | 316 }; |
| 256 } // namespace extensions | 317 } // namespace extensions |
| 257 | 318 |
| 258 #endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ | 319 #endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ |
| OLD | NEW |