OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ | |
6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <vector> | |
11 | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "content/common/content_export.h" | |
14 #include "url/origin.h" | |
15 | |
16 namespace device { | |
17 class BluetoothUUID; | |
18 } | |
19 | |
20 namespace content { | |
21 | |
22 struct BluetoothScanFilter; | |
23 | |
24 // Keeps track of which origins are allowed to access which devices and | |
25 // their services. | |
26 // | |
27 // When talking about |device_id|s we are referring to | |
28 // the generated |device_id| for each origin for a given device. | |
palmer
2016/01/15 01:13:59
Nit: I'd reword this comment, along these lines:
ortuno
2016/01/15 02:52:21
Done.
| |
29 class CONTENT_EXPORT BluetoothAllowedDevicesMap final { | |
30 public: | |
31 BluetoothAllowedDevicesMap(); | |
32 ~BluetoothAllowedDevicesMap(); | |
33 | |
34 // Adds the Bluetooth Device with |device_address| to the map of allowed | |
35 // devices for that origin. Returns the generated |device_id| for |origin| | |
palmer
2016/01/15 01:13:59
...then you can change the last sentence in this c
ortuno
2016/01/15 02:52:22
Done.
| |
36 // for the device with |device_address|. | |
37 const std::string& AddDevice( | |
38 const url::Origin& origin, | |
39 const std::string& device_address, | |
40 const std::vector<BluetoothScanFilter>& filters, | |
41 const std::vector<device::BluetoothUUID>& optional_services); | |
42 | |
43 // Removes the Bluetooth Device with |device_address| from the map of allowed | |
44 // devices for |origin|. | |
45 void RemoveDevice(const url::Origin& origin, | |
46 const std::string& device_address); | |
47 | |
48 // TODO(ortuno): Add function to check if origin is allowed to access | |
49 // a device's service and add tests for that function. | |
50 // https://crbug.com/493460 | |
51 | |
52 // Returns the Bluetooth Device's id for |origin|. Returns an empty string | |
53 // if the origin is not allowed to access the device. | |
54 const std::string& GetDeviceId(const url::Origin& origin, | |
55 const std::string& device_address); | |
56 | |
57 // Returns the Bluetooth Device's address from |device_id_for_origin|. Returns | |
palmer
2016/01/15 01:13:59
Minor Nit: Maybe word this in such a way that the
ortuno
2016/01/15 02:52:21
Done.
| |
58 // an empty string if the origin is not allowed to access the device. | |
59 const std::string& GetDeviceAddress(const url::Origin& origin, | |
60 const std::string& device_id); | |
61 | |
62 private: | |
63 typedef std::map<std::string, std::string> DeviceAddressToIdMap; | |
64 typedef std::map<std::string, std::string> DeviceIdToAddressMap; | |
65 typedef std::map<std::string, std::set<std::string>> DeviceIdToServicesMap; | |
66 | |
67 // Returns an id guaranteed to be unique for the origin. The id is randomly | |
68 // generated so that an origin can't guess the ID used in another origin. | |
69 std::string GenerateDeviceId(const url::Origin& origin); | |
70 std::set<std::string> UnionOfServices( | |
71 const std::vector<BluetoothScanFilter>& filters, | |
72 const std::vector<device::BluetoothUUID>& optional_services); | |
73 | |
74 std::map<url::Origin, DeviceAddressToIdMap> | |
palmer
2016/01/15 01:13:59
This 3-way mapping system seems complex. I wonder
ortuno
2016/01/15 02:52:22
Interesting. This class implements the spec so I o
| |
75 origin_to_device_address_to_id_map_; | |
76 std::map<url::Origin, DeviceIdToAddressMap> | |
77 origin_to_device_id_to_address_map_; | |
78 std::map<url::Origin, DeviceIdToServicesMap> | |
79 origin_to_device_id_to_services_map_; | |
80 }; | |
81 | |
82 } // namespace content | |
83 | |
84 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ | |
OLD | NEW |