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

Side by Side Diff: device/usb/usb_device.h

Issue 1034333002: Check USB device path access when prompting users to select a device. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Have MockPermissionBrokerClient extend FakePermissionBrokerClient to avoid adding mocks for unrelat… Created 5 years, 8 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 DEVICE_USB_USB_DEVICE_H_ 5 #ifndef DEVICE_USB_USB_DEVICE_H_
6 #define DEVICE_USB_USB_DEVICE_H_ 6 #define DEVICE_USB_USB_DEVICE_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 12
13 namespace device { 13 namespace device {
14 14
15 class UsbDeviceHandle; 15 class UsbDeviceHandle;
16 struct UsbConfigDescriptor; 16 struct UsbConfigDescriptor;
17 17
18 // A UsbDevice object represents a detected USB device, providing basic 18 // A UsbDevice object represents a detected USB device, providing basic
19 // information about it. For further manipulation of the device, a 19 // information about it. For further manipulation of the device, a
20 // UsbDeviceHandle must be created from Open() method. 20 // UsbDeviceHandle must be created from Open() method.
21 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { 21 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
22 public: 22 public:
23 typedef base::Callback<void(bool success)> ResultCallback;
24
23 // Accessors to basic information. 25 // Accessors to basic information.
24 uint16 vendor_id() const { return vendor_id_; } 26 uint16 vendor_id() const { return vendor_id_; }
25 uint16 product_id() const { return product_id_; } 27 uint16 product_id() const { return product_id_; }
26 uint32 unique_id() const { return unique_id_; } 28 uint32 unique_id() const { return unique_id_; }
27 29
28 #if defined(OS_CHROMEOS) 30 // On ChromeOS the permission_broker service is used to change the ownership
29 // On ChromeOS, if an interface of a claimed device is not claimed, the 31 // of USB device nodes so that Chrome can open them. On other platforms these
30 // permission broker can change the owner of the device so that the unclaimed 32 // functions are no-ops and always return true.
31 // interfaces can be used. If this argument is missing, permission broker will 33 virtual void CheckUsbAccess(const ResultCallback& callback);
32 // not be used and this method fails if the device is claimed. 34
33 virtual void RequestUsbAccess( 35 // Like CheckUsbAccess but actually changes the ownership of the device node.
34 int interface_id, 36 virtual void RequestUsbAccess(int interface_id,
35 const base::Callback<void(bool success)>& callback) = 0; 37 const ResultCallback& callback);
36 #endif // OS_CHROMEOS
37 38
38 // Creates a UsbDeviceHandle for further manipulation. 39 // Creates a UsbDeviceHandle for further manipulation.
39 // Blocking method. Must be called on FILE thread. 40 // Blocking method. Must be called on FILE thread.
40 virtual scoped_refptr<UsbDeviceHandle> Open() = 0; 41 virtual scoped_refptr<UsbDeviceHandle> Open() = 0;
41 42
42 // Explicitly closes a device handle. This method will be automatically called 43 // Explicitly closes a device handle. This method will be automatically called
43 // by the destructor of a UsbDeviceHandle as well. 44 // by the destructor of a UsbDeviceHandle as well.
44 // Closing a closed handle is a safe 45 // Closing a closed handle is a safe
45 // Blocking method. Must be called on FILE thread. 46 // Blocking method. Must be called on FILE thread.
46 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0; 47 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0;
(...skipping 12 matching lines...) Expand all
59 // string. This is a blocking method and must be called on FILE thread. 60 // string. This is a blocking method and must be called on FILE thread.
60 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985 61 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
61 virtual bool GetProduct(base::string16* product) = 0; 62 virtual bool GetProduct(base::string16* product) = 0;
62 63
63 // Gets the serial number string of the device, or returns false and an empty 64 // Gets the serial number string of the device, or returns false and an empty
64 // string. This is a blocking method and must be called on FILE thread. 65 // string. This is a blocking method and must be called on FILE thread.
65 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985 66 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
66 virtual bool GetSerialNumber(base::string16* serial) = 0; 67 virtual bool GetSerialNumber(base::string16* serial) = 0;
67 68
68 protected: 69 protected:
69 UsbDevice(uint16 vendor_id, uint16 product_id, uint32 unique_id) 70 UsbDevice(uint16 vendor_id, uint16 product_id, uint32 unique_id);
70 : vendor_id_(vendor_id), product_id_(product_id), unique_id_(unique_id) {} 71 virtual ~UsbDevice();
71 virtual ~UsbDevice() {}
72 72
73 private: 73 private:
74 friend class base::RefCountedThreadSafe<UsbDevice>; 74 friend class base::RefCountedThreadSafe<UsbDevice>;
75 75
76 const uint16 vendor_id_; 76 const uint16 vendor_id_;
77 const uint16 product_id_; 77 const uint16 product_id_;
78 const uint32 unique_id_; 78 const uint32 unique_id_;
79 79
80 DISALLOW_COPY_AND_ASSIGN(UsbDevice); 80 DISALLOW_COPY_AND_ASSIGN(UsbDevice);
81 }; 81 };
82 82
83 } // namespace device 83 } // namespace device
84 84
85 #endif // DEVICE_USB_USB_DEVICE_H_ 85 #endif // DEVICE_USB_USB_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698