Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2339)

Side by Side Diff: extensions/browser/api/usb/usb_api.h

Issue 599303004: Add getUserSelectedDevices to the USB extensions API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(
121 const std::vector<scoped_refptr<device::UsbDevice>>& devices) override;
Finnur 2014/10/15 09:33:08 style: s/>>/> >/
Reilly Grant (use Gerrit) 2014/10/15 19:12:43 clang-format has been updated to prefer the no-spa
122
123 std::vector<uint32> device_ids_;
124 std::vector<scoped_refptr<device::UsbDevice>> devices_;
Finnur 2014/10/15 09:33:08 style: s/>>/> >/
125 std::vector<base::string16> serial_numbers_;
110 }; 126 };
111 127
112 class UsbRequestAccessFunction : public UsbAsyncApiFunction { 128 class UsbRequestAccessFunction : public UsbAsyncApiFunction {
113 public: 129 public:
114 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) 130 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS)
115 131
116 UsbRequestAccessFunction(); 132 UsbRequestAccessFunction();
117 133
118 virtual bool Prepare() override; 134 virtual bool Prepare() override;
119 virtual void AsyncWorkStart() override; 135 virtual void AsyncWorkStart() override;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 333
318 virtual bool Prepare() override; 334 virtual bool Prepare() override;
319 virtual void AsyncWorkStart() override; 335 virtual void AsyncWorkStart() override;
320 336
321 private: 337 private:
322 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_; 338 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_;
323 }; 339 };
324 } // namespace extensions 340 } // namespace extensions
325 341
326 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_ 342 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/api/usb/usb_api.cc » ('j') | extensions/browser/api/usb/usb_api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698