OLD | NEW |
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 #ifndef EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ | 4 #ifndef EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ |
5 #define EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ | 5 #define EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ |
6 | 6 |
7 #include <stdint.h> | |
8 | |
9 #include <string> | 7 #include <string> |
10 | 8 |
| 9 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
12 #include "extensions/common/permissions/api_permission.h" | 11 #include "extensions/common/permissions/api_permission.h" |
13 | 12 |
14 namespace base { | 13 namespace base { |
15 | 14 |
16 class Value; | 15 class Value; |
17 | 16 |
18 } // namespace base | 17 } // namespace base |
19 | 18 |
20 namespace extensions { | 19 namespace extensions { |
21 | 20 |
22 // A pattern that can be used to match a USB device permission. | 21 // A pattern that can be used to match a USB device permission. |
23 // Should be of the format: vendorId:productId, where both vendorId and | 22 // Should be of the format: vendorId:productId, where both vendorId and |
24 // productId are decimal strings representing uint16_t values. | 23 // productId are decimal strings representing uint16 values. |
25 class UsbDevicePermissionData { | 24 class UsbDevicePermissionData { |
26 public: | 25 public: |
27 enum SpecialInterfaces { | 26 enum SpecialInterfaces { |
28 // A special interface id for stating permissions for an entire USB device, | 27 // A special interface id for stating permissions for an entire USB device, |
29 // no specific interface. This value must match value of Rule::ANY_INTERFACE | 28 // no specific interface. This value must match value of Rule::ANY_INTERFACE |
30 // from ChromeOS permission_broker project. | 29 // from ChromeOS permission_broker project. |
31 ANY_INTERFACE = -1, | 30 ANY_INTERFACE = -1, |
32 | 31 |
33 // A special interface id for |Check| to indicate that interface field is | 32 // A special interface id for |Check| to indicate that interface field is |
34 // not to be checked. Not used in manifest file. | 33 // not to be checked. Not used in manifest file. |
35 UNSPECIFIED_INTERFACE = -2 | 34 UNSPECIFIED_INTERFACE = -2 |
36 }; | 35 }; |
37 | 36 |
38 UsbDevicePermissionData(); | 37 UsbDevicePermissionData(); |
39 UsbDevicePermissionData(uint16_t vendor_id, | 38 UsbDevicePermissionData(uint16 vendor_id, |
40 uint16_t product_id, | 39 uint16 product_id, |
41 int interface_id); | 40 int interface_id); |
42 | 41 |
43 // Check if |param| (which must be a UsbDevicePermissionData::CheckParam) | 42 // Check if |param| (which must be a UsbDevicePermissionData::CheckParam) |
44 // matches the vendor and product IDs associated with |this|. | 43 // matches the vendor and product IDs associated with |this|. |
45 bool Check(const APIPermission::CheckParam* param) const; | 44 bool Check(const APIPermission::CheckParam* param) const; |
46 | 45 |
47 // Convert |this| into a base::Value. | 46 // Convert |this| into a base::Value. |
48 scoped_ptr<base::Value> ToValue() const; | 47 scoped_ptr<base::Value> ToValue() const; |
49 | 48 |
50 // Populate |this| from a base::Value. | 49 // Populate |this| from a base::Value. |
51 bool FromValue(const base::Value* value); | 50 bool FromValue(const base::Value* value); |
52 | 51 |
53 bool operator<(const UsbDevicePermissionData& rhs) const; | 52 bool operator<(const UsbDevicePermissionData& rhs) const; |
54 bool operator==(const UsbDevicePermissionData& rhs) const; | 53 bool operator==(const UsbDevicePermissionData& rhs) const; |
55 | 54 |
56 const uint16_t& vendor_id() const { return vendor_id_; } | 55 const uint16& vendor_id() const { return vendor_id_; } |
57 const uint16_t& product_id() const { return product_id_; } | 56 const uint16& product_id() const { return product_id_; } |
58 | 57 |
59 // These accessors are provided for IPC_STRUCT_TRAITS_MEMBER. Please | 58 // These accessors are provided for IPC_STRUCT_TRAITS_MEMBER. Please |
60 // think twice before using them for anything else. | 59 // think twice before using them for anything else. |
61 uint16_t& vendor_id() { return vendor_id_; } | 60 uint16& vendor_id() { return vendor_id_; } |
62 uint16_t& product_id() { return product_id_; } | 61 uint16& product_id() { return product_id_; } |
63 | 62 |
64 private: | 63 private: |
65 uint16_t vendor_id_; | 64 uint16 vendor_id_; |
66 uint16_t product_id_; | 65 uint16 product_id_; |
67 int interface_id_; | 66 int interface_id_; |
68 }; | 67 }; |
69 | 68 |
70 } // namespace extensions | 69 } // namespace extensions |
71 | 70 |
72 #endif // EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ | 71 #endif // EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ |
OLD | NEW |