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 std::vector<scoped_refptr<UsbDeviceHandle> > device_handles_; |
| 84 scoped_ptr<extensions::api::usb::FindDevices::Params> parameters_; |
| 85 }; |
| 86 |
| 87 class UsbGetDevicesFunction : public UsbAsyncApiFunction { |
| 88 public: |
| 89 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES) |
| 90 |
| 91 UsbGetDevicesFunction(); |
| 92 |
| 93 static void SetDeviceForTest(UsbDevice* device); |
| 94 |
| 95 virtual bool Prepare() OVERRIDE; |
| 96 virtual void AsyncWorkStart() OVERRIDE; |
| 97 |
| 98 protected: |
| 99 virtual ~UsbGetDevicesFunction(); |
| 100 |
| 101 private: |
76 void EnumerationCompletedFileThread( | 102 void EnumerationCompletedFileThread( |
77 scoped_ptr<std::vector<scoped_refptr<UsbDevice> > > devices); | 103 scoped_ptr<std::vector<scoped_refptr<UsbDevice> > > devices); |
78 | 104 |
79 scoped_ptr<base::ListValue> result_; | 105 scoped_ptr<extensions::api::usb::GetDevices::Params> parameters_; |
80 std::vector<scoped_refptr<UsbDeviceHandle> > device_handles_; | 106 }; |
81 scoped_ptr<extensions::api::usb::FindDevices::Params> parameters_; | 107 |
| 108 class UsbRequestAccessFunction : public UsbAsyncApiFunction { |
| 109 public: |
| 110 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) |
| 111 |
| 112 UsbRequestAccessFunction(); |
| 113 |
| 114 virtual bool Prepare() OVERRIDE; |
| 115 virtual void AsyncWorkStart() OVERRIDE; |
| 116 |
| 117 protected: |
| 118 virtual ~UsbRequestAccessFunction(); |
| 119 |
| 120 void OnCompleted(bool success); |
| 121 |
| 122 private: |
| 123 scoped_ptr<extensions::api::usb::RequestAccess::Params> parameters_; |
| 124 }; |
| 125 |
| 126 class UsbOpenDeviceFunction : public UsbAsyncApiFunction { |
| 127 public: |
| 128 DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE) |
| 129 |
| 130 UsbOpenDeviceFunction(); |
| 131 |
| 132 virtual bool Prepare() OVERRIDE; |
| 133 virtual void AsyncWorkStart() OVERRIDE; |
| 134 |
| 135 protected: |
| 136 virtual ~UsbOpenDeviceFunction(); |
| 137 |
| 138 private: |
| 139 scoped_refptr<UsbDeviceHandle> handle_; |
| 140 scoped_ptr<extensions::api::usb::OpenDevice::Params> parameters_; |
82 }; | 141 }; |
83 | 142 |
84 class UsbListInterfacesFunction : public UsbAsyncApiFunction { | 143 class UsbListInterfacesFunction : public UsbAsyncApiFunction { |
85 public: | 144 public: |
86 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) | 145 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) |
87 | 146 |
88 UsbListInterfacesFunction(); | 147 UsbListInterfacesFunction(); |
89 | 148 |
90 protected: | 149 protected: |
91 virtual ~UsbListInterfacesFunction(); | 150 virtual ~UsbListInterfacesFunction(); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 308 |
250 virtual bool Prepare() OVERRIDE; | 309 virtual bool Prepare() OVERRIDE; |
251 virtual void AsyncWorkStart() OVERRIDE; | 310 virtual void AsyncWorkStart() OVERRIDE; |
252 | 311 |
253 private: | 312 private: |
254 scoped_ptr<extensions::api::usb::ResetDevice::Params> parameters_; | 313 scoped_ptr<extensions::api::usb::ResetDevice::Params> parameters_; |
255 }; | 314 }; |
256 } // namespace extensions | 315 } // namespace extensions |
257 | 316 |
258 #endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ | 317 #endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_ |
OLD | NEW |