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

Side by Side Diff: chrome/browser/usb/usb_device.h

Issue 22914023: Introducing chrome.usb.getDevices/openDevice API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-interface
Patch Set: Adding chrome.usb.requestAccess Created 7 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 5
6 #ifndef CHROME_BROWSER_USB_USB_DEVICE_H_ 6 #ifndef CHROME_BROWSER_USB_USB_DEVICE_H_
7 #define CHROME_BROWSER_USB_USB_DEVICE_H_ 7 #define CHROME_BROWSER_USB_USB_DEVICE_H_
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
14 #include "chrome/browser/usb/usb_interface.h" 15 #include "chrome/browser/usb/usb_interface.h"
15 16
16 struct libusb_device; 17 struct libusb_device;
17 class UsbDeviceHandle; 18 class UsbDeviceHandle;
18 class UsbContext; 19 class UsbContext;
19 20
20 typedef libusb_device* PlatformUsbDevice; 21 typedef libusb_device* PlatformUsbDevice;
21 22
22 // A UsbDevice object represents a detected USB device, providing basic 23 // A UsbDevice object represents a detected USB device, providing basic
23 // information about it. For further manipulation of the device, a 24 // information about it. For further manipulation of the device, a
24 // UsbDeviceHandle must be created from Open() method. 25 // UsbDeviceHandle must be created from Open() method.
25 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { 26 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
26 public: 27 public:
27 // Accessors to basic information. 28 // Accessors to basic information.
28 PlatformUsbDevice platform_device() const { return platform_device_; } 29 PlatformUsbDevice platform_device() const { return platform_device_; }
29 uint16 vendor_id() const { return vendor_id_; } 30 uint16 vendor_id() const { return vendor_id_; }
30 uint16 product_id() const { return product_id_; } 31 uint16 product_id() const { return product_id_; }
32 uint32 unique_id() const { return unique_id_; }
33
34 #if defined(OS_CHROMEOS)
35 // On ChromeOS, if an interface of a claimed device is not claimed, the
36 // permission broker can change the owner of the device so that the unclaimed
37 // interfaces can be used. If this argument is missing, permission broker will
38 // not be used and this method fails if the device is claimed.
39 virtual void RequestUsbAcess(
40 int interface_id, const base::Callback<void(bool success)>& callback);
41 #endif // OS_CHROMEOS
31 42
32 // Creates a UsbDeviceHandle for further manipulation. 43 // Creates a UsbDeviceHandle for further manipulation.
33 // Blocking method. Must be called on FILE thread. 44 // Blocking method. Must be called on FILE thread.
34 virtual scoped_refptr<UsbDeviceHandle> Open(); 45 virtual scoped_refptr<UsbDeviceHandle> Open();
35 46
36 // Explicitly closes a device handle. This method will be automatically called 47 // Explicitly closes a device handle. This method will be automatically called
37 // by the destructor of a UsbDeviceHandle as well. 48 // by the destructor of a UsbDeviceHandle as well.
38 // Closing a closed handle is a safe 49 // Closing a closed handle is a safe
39 // Blocking method. Must be called on FILE thread. 50 // Blocking method. Must be called on FILE thread.
40 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle); 51 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle);
41 52
42 // Lists the interfaces provided by the device and fills the given 53 // Lists the interfaces provided by the device and fills the given
43 // UsbConfigDescriptor. 54 // UsbConfigDescriptor.
44 // Blocking method. Must be called on FILE thread. 55 // Blocking method. Must be called on FILE thread.
45 virtual scoped_refptr<UsbConfigDescriptor> ListInterfaces(); 56 virtual scoped_refptr<UsbConfigDescriptor> ListInterfaces();
46 57
47 protected: 58 protected:
48 friend class UsbService; 59 friend class UsbService;
49 friend class base::RefCountedThreadSafe<UsbDevice>; 60 friend class base::RefCountedThreadSafe<UsbDevice>;
50 61
51 // Called by UsbService only; 62 // Called by UsbService only;
52 UsbDevice(scoped_refptr<UsbContext> context, 63 UsbDevice(scoped_refptr<UsbContext> context,
53 PlatformUsbDevice platform_device, 64 PlatformUsbDevice platform_device,
54 uint16 vendor_id, 65 uint16 vendor_id,
55 uint16 product_id); 66 uint16 product_id,
67 uint32 unique_id);
56 68
57 // Constructor called in test only. 69 // Constructor called in test only.
58 UsbDevice(); 70 UsbDevice();
59 virtual ~UsbDevice(); 71 virtual ~UsbDevice();
60 72
61 // Called only be UsbService. 73 // Called only be UsbService.
62 virtual void OnDisconnect(); 74 virtual void OnDisconnect();
63 75
76 #if defined(OS_CHROMEOS)
77 // This method is called when permission broker replied our request.
78 // We will simply relay it to FILE thread.
79 // |callback| comes first because it will be base::Bind'ed.
80 void OnRequestUsbAccessReplied(
81 const base::Callback<void(bool success)>& callback,
82 bool success);
83 #endif // OS_CHROMEOS
84
64 private: 85 private:
65 PlatformUsbDevice platform_device_; 86 PlatformUsbDevice platform_device_;
66 uint16 vendor_id_; 87 uint16 vendor_id_;
67 uint16 product_id_; 88 uint16 product_id_;
89 uint32 unique_id_;
68 90
69 // Retain the context so that it will not be released before UsbDevice. 91 // Retain the context so that it will not be released before UsbDevice.
70 scoped_refptr<UsbContext> context_; 92 scoped_refptr<UsbContext> context_;
71 93
72 // Opened handles. 94 // Opened handles.
73 typedef std::vector<scoped_refptr<UsbDeviceHandle> > HandlesVector; 95 typedef std::vector<scoped_refptr<UsbDeviceHandle> > HandlesVector;
74 HandlesVector handles_; 96 HandlesVector handles_;
75 97
76 base::ThreadChecker thread_checker_; 98 base::ThreadChecker thread_checker_;
77 99
78 DISALLOW_COPY_AND_ASSIGN(UsbDevice); 100 DISALLOW_COPY_AND_ASSIGN(UsbDevice);
79 }; 101 };
80 102
81 #endif // CHROME_BROWSER_USB_USB_DEVICE_H_ 103 #endif // CHROME_BROWSER_USB_USB_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698