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