Do not clear ephemeral device permissions when an app is suspended.
[chromium-blink-merge.git] / device / usb / usb_device_impl.h
blob76ede3378bb80f27943ac23cbaaf578034c1dba4
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 const base::string16& manufacturer_string,
56 const base::string16& product_string,
57 const base::string16& serial_number,
58 const std::string& device_node,
59 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
61 ~UsbDeviceImpl() override;
63 // Called only by UsbServiceImpl.
64 PlatformUsbDevice platform_device() const { return platform_device_; }
65 void set_visited(bool visited) { visited_ = visited; }
66 bool was_visited() const { return visited_; }
67 void OnDisconnect();
69 // Called by UsbDeviceHandleImpl.
70 void RefreshConfiguration();
72 private:
73 void OpenOnBlockingThread(const OpenCallback& callback);
74 void Opened(PlatformUsbDeviceHandle platform_handle,
75 const OpenCallback& callback);
77 base::ThreadChecker thread_checker_;
78 PlatformUsbDevice platform_device_;
79 bool visited_ = false;
81 #if defined(OS_CHROMEOS)
82 // On Chrome OS save the devnode string for requesting path access from
83 // permission broker.
84 std::string devnode_;
85 #endif
87 // The current device configuration descriptor. May be null if the device is
88 // in an unconfigured state.
89 scoped_ptr<UsbConfigDescriptor> configuration_;
91 // Retain the context so that it will not be released before UsbDevice.
92 scoped_refptr<UsbContext> context_;
94 // Opened handles.
95 typedef std::vector<scoped_refptr<UsbDeviceHandleImpl> > HandlesVector;
96 HandlesVector handles_;
98 scoped_refptr<base::SequencedTaskRunner> task_runner_;
99 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
101 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl);
104 } // namespace device
106 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_