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