OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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. | |
4 | |
5 #ifndef CHROME_BROWSER_USB_USB_BLOCKLIST_H_ | |
6 #define CHROME_BROWSER_USB_USB_BLOCKLIST_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <set> | |
11 | |
12 #include "base/lazy_instance.h" | |
13 #include "base/macros.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/strings/string_piece.h" | |
16 | |
17 namespace device { | |
18 class UsbDevice; | |
19 } | |
20 | |
21 class UsbBlocklist final { | |
22 public: | |
23 // An entry in the blocklist. Represents a specific version of a device that | |
24 // should be be accessible. These fields correspond to the idVendor, idProduct | |
scheib
2016/12/15 18:43:56
'be be' -> 'not be'
Reilly Grant (use Gerrit)
2016/12/15 23:21:03
Done.
| |
25 // and bcdDevice fields of the device's USB device descriptor. | |
26 struct Entry { | |
27 Entry(uint16_t vendor_id, uint16_t product_id, uint16_t version); | |
28 | |
29 uint16_t vendor_id; | |
30 uint16_t product_id; | |
31 uint16_t version; | |
32 }; | |
33 | |
34 ~UsbBlocklist(); | |
35 | |
36 // Returns a singleton instance of the blocklist. | |
37 static UsbBlocklist& Get(); | |
38 | |
39 // Adds a device to the blocklist to be excluded from access. | |
40 void Exclude(const Entry&); | |
41 | |
42 // Adds a device to the blocklist by parsing a blocklist string and calling | |
43 // Exclude(entry). | |
44 // | |
45 // The blocklist string must be a comma-separated list of | |
46 // idVendor:idProduct:bcdDevice triples, where each member of the triple is a | |
47 // 16-bit integer written as exactly 4 hexadecimal digits. The triples may | |
48 // be separated by whitespace. Triple components are colon-separated and must | |
49 // not have whitespace around the colon. | |
50 // | |
51 // Invalid entries in the comma-separated list will be ignored. | |
52 // | |
53 // Example: | |
54 // "1000:001C:0100, 1000:001D:0101, 123:ignored:0" | |
55 void Exclude(base::StringPiece blocklist_string); | |
56 | |
57 // Returns if a device is excluded from access. | |
58 bool IsExcluded(const Entry&); | |
59 bool IsExcluded(scoped_refptr<const device::UsbDevice>); | |
60 | |
61 // Size of the blocklist. | |
62 size_t size() { return blocklisted_devices_.size(); } | |
63 | |
64 // Reload the blocklist for testing purposes. | |
65 void ResetToDefaultValuesForTest(); | |
66 | |
67 private: | |
68 // friend LazyInstance to permit access to private constructor. | |
69 friend base::DefaultLazyInstanceTraits<UsbBlocklist>; | |
70 | |
71 UsbBlocklist(); | |
72 | |
73 void PopulateWithDefaultValues(); | |
74 | |
75 // Populates the blocklist with values obtained dynamically from a server, | |
76 // able to be updated without shipping new executable versions. | |
77 void PopulateWithServerProvidedValues(); | |
78 | |
79 // Set of blocklist entries. | |
80 std::set<Entry> blocklisted_devices_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(UsbBlocklist); | |
83 }; | |
84 | |
85 #endif // CHROME_BROWSER_USB_USB_BLOCKLIST_H_ | |
OLD | NEW |