Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / device / usb / usb_device_impl.h
blob71edf1f046a9334a64500bc30117904294d41f52
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
3 // found in the LICENSE file.
5 #ifndef DEVICE_USB_USB_DEVICE_IMPL_H_
6 #define DEVICE_USB_USB_DEVICE_IMPL_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/threading/thread_checker.h"
13 #include "device/usb/usb_descriptors.h"
14 #include "device/usb/usb_device.h"
16 struct libusb_device;
17 struct libusb_config_descriptor;
18 struct libusb_device_handle;
20 namespace base {
21 class SequencedTaskRunner;
24 namespace device {
26 class UsbDeviceHandleImpl;
27 class UsbContext;
29 typedef struct libusb_device* PlatformUsbDevice;
30 typedef struct libusb_config_descriptor* PlatformUsbConfigDescriptor;
31 typedef struct libusb_device_handle* PlatformUsbDeviceHandle;
33 class UsbDeviceImpl : public UsbDevice {
34 public:
35 // UsbDevice implementation:
36 #if defined(OS_CHROMEOS)
37 // Only overridden on Chrome OS.
38 void CheckUsbAccess(const ResultCallback& callback) override;
39 void RequestUsbAccess(int interface_id,
40 const ResultCallback& callback) override;
41 #endif // OS_CHROMEOS
42 void Open(const OpenCallback& callback) override;
43 bool Close(scoped_refptr<UsbDeviceHandle> handle) override;
44 const UsbConfigDescriptor* GetConfiguration() override;
46 protected:
47 friend class UsbServiceImpl;
48 friend class UsbDeviceHandleImpl;
50 // Called by UsbServiceImpl only;
51 UsbDeviceImpl(scoped_refptr<UsbContext> context,
52 PlatformUsbDevice platform_device,
53 uint16 vendor_id,
54 uint16 product_id,
55 uint32 unique_id,
56 const base::string16& manufacturer_string,
57 const base::string16& product_string,
58 const base::string16& serial_number,
59 const std::string& device_node,
60 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
62 ~UsbDeviceImpl() override;
64 // Called only by UsbServiceImpl.
65 PlatformUsbDevice platform_device() const { return platform_device_; }
66 void set_visited(bool visited) { visited_ = visited; }
67 bool was_visited() const { return visited_; }
68 void OnDisconnect();
70 // Called by UsbDeviceHandleImpl.
71 void RefreshConfiguration();
73 private:
74 void OpenOnBlockingThread(const OpenCallback& callback);
75 void Opened(PlatformUsbDeviceHandle platform_handle,
76 const OpenCallback& callback);
78 base::ThreadChecker thread_checker_;
79 PlatformUsbDevice platform_device_;
80 bool visited_ = false;
82 #if defined(OS_CHROMEOS)
83 // On Chrome OS save the devnode string for requesting path access from
84 // permission broker.
85 std::string devnode_;
86 #endif
88 // The current device configuration descriptor. May be null if the device is
89 // in an unconfigured state.
90 scoped_ptr<UsbConfigDescriptor> configuration_;
92 // Retain the context so that it will not be released before UsbDevice.
93 scoped_refptr<UsbContext> context_;
95 // Opened handles.
96 typedef std::vector<scoped_refptr<UsbDeviceHandleImpl> > HandlesVector;
97 HandlesVector handles_;
99 scoped_refptr<base::SequencedTaskRunner> task_runner_;
100 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
102 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl);
105 } // namespace device
107 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_