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 "device/usb/usb_device.h" | 13 #include "device/usb/usb_device.h" |
14 #include "device/usb/usb_device_filter.h" | 14 #include "device/usb/usb_device_filter.h" |
15 #include "device/usb/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/browser/api/device_permissions_prompt.h" | |
18 #include "extensions/common/api/usb.h" | 19 #include "extensions/common/api/usb.h" |
19 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
20 | 21 |
21 namespace extensions { | 22 namespace extensions { |
22 | 23 |
24 class DevicePermissions; | |
23 class UsbDeviceResource; | 25 class UsbDeviceResource; |
24 | 26 |
25 class UsbAsyncApiFunction : public AsyncApiFunction { | 27 class UsbAsyncApiFunction : public AsyncApiFunction { |
26 public: | 28 public: |
27 UsbAsyncApiFunction(); | 29 UsbAsyncApiFunction(); |
28 | 30 |
29 protected: | 31 protected: |
30 virtual ~UsbAsyncApiFunction(); | 32 virtual ~UsbAsyncApiFunction(); |
31 | 33 |
32 virtual bool PrePrepare() override; | 34 virtual bool PrePrepare() override; |
33 virtual bool Respond() override; | 35 virtual bool Respond() override; |
34 | 36 |
35 static void CreateDeviceFilter( | |
36 const extensions::core_api::usb::DeviceFilter& input, | |
37 device::UsbDeviceFilter* output); | |
38 | |
39 bool HasDevicePermission(scoped_refptr<device::UsbDevice> device); | 37 bool HasDevicePermission(scoped_refptr<device::UsbDevice> device); |
40 | |
41 scoped_refptr<device::UsbDevice> GetDeviceOrCompleteWithError( | 38 scoped_refptr<device::UsbDevice> GetDeviceOrCompleteWithError( |
42 const extensions::core_api::usb::Device& input_device); | 39 const extensions::core_api::usb::Device& input_device); |
43 | |
44 scoped_refptr<device::UsbDeviceHandle> GetDeviceHandleOrCompleteWithError( | 40 scoped_refptr<device::UsbDeviceHandle> GetDeviceHandleOrCompleteWithError( |
45 const extensions::core_api::usb::ConnectionHandle& input_device_handle); | 41 const extensions::core_api::usb::ConnectionHandle& input_device_handle); |
46 | 42 |
47 void RemoveUsbDeviceResource(int api_resource_id); | 43 void RemoveUsbDeviceResource(int api_resource_id); |
48 | 44 |
49 void CompleteWithError(const std::string& error); | 45 void CompleteWithError(const std::string& error); |
50 | 46 |
51 ApiResourceManager<UsbDeviceResource>* manager_; | 47 ApiResourceManager<UsbDeviceResource>* manager_; |
48 scoped_ptr<DevicePermissions> device_permissions_; | |
52 }; | 49 }; |
53 | 50 |
54 class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction { | 51 class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction { |
55 protected: | 52 protected: |
56 UsbAsyncApiTransferFunction(); | 53 UsbAsyncApiTransferFunction(); |
57 virtual ~UsbAsyncApiTransferFunction(); | 54 virtual ~UsbAsyncApiTransferFunction(); |
58 | 55 |
59 bool ConvertDirectionSafely(const extensions::core_api::usb::Direction& input, | 56 bool ConvertDirectionSafely(const extensions::core_api::usb::Direction& input, |
60 device::UsbEndpointDirection* output); | 57 device::UsbEndpointDirection* output); |
61 bool ConvertRequestTypeSafely( | 58 bool ConvertRequestTypeSafely( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 93 |
97 UsbGetDevicesFunction(); | 94 UsbGetDevicesFunction(); |
98 | 95 |
99 virtual bool Prepare() override; | 96 virtual bool Prepare() override; |
100 virtual void AsyncWorkStart() override; | 97 virtual void AsyncWorkStart() override; |
101 | 98 |
102 protected: | 99 protected: |
103 virtual ~UsbGetDevicesFunction(); | 100 virtual ~UsbGetDevicesFunction(); |
104 | 101 |
105 private: | 102 private: |
106 void EnumerationCompletedFileThread( | 103 scoped_ptr<extensions::core_api::usb::GetDevices::Params> parameters_; |
107 scoped_ptr<std::vector<scoped_refptr<device::UsbDevice> > > devices); | 104 }; |
108 | 105 |
109 scoped_ptr<extensions::core_api::usb::GetDevices::Params> parameters_; | 106 class UsbGetUserSelectedDevicesFunction |
107 : public UIThreadExtensionFunction, | |
108 public DevicePermissionsPrompt::Delegate { | |
109 public: | |
110 DECLARE_EXTENSION_FUNCTION("usb.getUserSelectedDevices", | |
111 USB_GETUSERSELECTEDDEVICES) | |
112 | |
113 UsbGetUserSelectedDevicesFunction(); | |
114 | |
115 protected: | |
116 virtual ~UsbGetUserSelectedDevicesFunction(); | |
117 virtual ResponseAction Run() override; | |
118 | |
119 private: | |
120 virtual void UsbDevicesChosen( | |
Ken Rockot(use gerrit already)
2014/10/16 19:15:23
optional nit: I kind of wish this interface were n
| |
121 const std::vector<scoped_refptr<device::UsbDevice>>& devices) override; | |
122 | |
123 scoped_ptr<DevicePermissionsPrompt> prompt_; | |
124 std::vector<uint32> device_ids_; | |
125 std::vector<scoped_refptr<device::UsbDevice>> devices_; | |
126 std::vector<base::string16> serial_numbers_; | |
110 }; | 127 }; |
111 | 128 |
112 class UsbRequestAccessFunction : public UsbAsyncApiFunction { | 129 class UsbRequestAccessFunction : public UsbAsyncApiFunction { |
113 public: | 130 public: |
114 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) | 131 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) |
115 | 132 |
116 UsbRequestAccessFunction(); | 133 UsbRequestAccessFunction(); |
117 | 134 |
118 virtual bool Prepare() override; | 135 virtual bool Prepare() override; |
119 virtual void AsyncWorkStart() override; | 136 virtual void AsyncWorkStart() override; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 | 334 |
318 virtual bool Prepare() override; | 335 virtual bool Prepare() override; |
319 virtual void AsyncWorkStart() override; | 336 virtual void AsyncWorkStart() override; |
320 | 337 |
321 private: | 338 private: |
322 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_; | 339 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_; |
323 }; | 340 }; |
324 } // namespace extensions | 341 } // namespace extensions |
325 | 342 |
326 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_ | 343 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_ |
OLD | NEW |