OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ | 5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ |
6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ | 6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h" | |
14 #include "url/origin.h" | 15 #include "url/origin.h" |
15 | 16 |
16 namespace device { | 17 namespace device { |
17 class BluetoothUUID; | 18 class BluetoothUUID; |
18 } | 19 } |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 struct BluetoothScanFilter; | 23 struct BluetoothScanFilter; |
23 | 24 |
24 // Keeps track of which origins are allowed to access which devices and | 25 // Keeps track of which origins are allowed to access which devices and |
25 // their services. | 26 // their services. |
26 // | 27 // |
27 // |AddDevice| generates device ids, which are random strings that are unique | 28 // |AddDevice| generates device ids, which are random strings that are unique |
28 // in the map. | 29 // in the map. |
29 class CONTENT_EXPORT BluetoothAllowedDevicesMap final { | 30 class CONTENT_EXPORT BluetoothAllowedDevicesMap final { |
30 public: | 31 public: |
31 BluetoothAllowedDevicesMap(); | 32 BluetoothAllowedDevicesMap(); |
32 ~BluetoothAllowedDevicesMap(); | 33 ~BluetoothAllowedDevicesMap(); |
33 | 34 |
34 // Adds the Bluetooth Device with |device_address| to the map of allowed | 35 // Adds the Bluetooth Device with |device_address| to the map of allowed |
35 // devices for that origin. Generates and returns a device id. | 36 // devices for that origin. Generates and returns a device id. Because |
37 // unique origins generate the same hash, unique origins are not supported. | |
Jeffrey Yasskin
2016/05/13 04:41:58
Does "not supported" mean they'll CHECK-fail, retu
ortuno
2016/05/13 20:11:17
Added comment.
| |
36 const std::string& AddDevice( | 38 const std::string& AddDevice( |
37 const url::Origin& origin, | 39 const url::Origin& origin, |
38 const std::string& device_address, | 40 const std::string& device_address, |
39 const std::vector<BluetoothScanFilter>& filters, | 41 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options); |
40 const std::vector<device::BluetoothUUID>& optional_services); | |
41 | 42 |
42 // Removes the Bluetooth Device with |device_address| from the map of allowed | 43 // Removes the Bluetooth Device with |device_address| from the map of allowed |
43 // devices for |origin|. | 44 // devices for |origin|. |
44 void RemoveDevice(const url::Origin& origin, | 45 void RemoveDevice(const url::Origin& origin, |
45 const std::string& device_address); | 46 const std::string& device_address); |
46 | 47 |
47 // Returns the Bluetooth Device's id for |origin|. Returns an empty string | 48 // Returns the Bluetooth Device's id for |origin|. Returns an empty string |
48 // if |origin| is not allowed to access the device. | 49 // if |origin| is not allowed to access the device. |
49 const std::string& GetDeviceId(const url::Origin& origin, | 50 const std::string& GetDeviceId(const url::Origin& origin, |
50 const std::string& device_address); | 51 const std::string& device_address); |
(...skipping 11 matching lines...) Expand all Loading... | |
62 | 63 |
63 private: | 64 private: |
64 typedef std::map<std::string, std::string> DeviceAddressToIdMap; | 65 typedef std::map<std::string, std::string> DeviceAddressToIdMap; |
65 typedef std::map<std::string, std::string> DeviceIdToAddressMap; | 66 typedef std::map<std::string, std::string> DeviceIdToAddressMap; |
66 typedef std::map<std::string, std::set<std::string>> DeviceIdToServicesMap; | 67 typedef std::map<std::string, std::set<std::string>> DeviceIdToServicesMap; |
67 | 68 |
68 // Returns an id guaranteed to be unique for the map. The id is randomly | 69 // Returns an id guaranteed to be unique for the map. The id is randomly |
69 // generated so that an origin can't guess the id used in another origin. | 70 // generated so that an origin can't guess the id used in another origin. |
70 std::string GenerateDeviceId(); | 71 std::string GenerateDeviceId(); |
71 void AddUnionOfServicesTo( | 72 void AddUnionOfServicesTo( |
72 const std::vector<BluetoothScanFilter>& filters, | 73 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options, |
73 const std::vector<device::BluetoothUUID>& optional_services, | |
74 std::set<std::string>* unionOfServices); | 74 std::set<std::string>* unionOfServices); |
75 | 75 |
76 // TODO(ortuno): Now that there is only one instance of this class per frame | |
77 // and that this map gets destroyed when navigating consider removing the | |
78 // origin mapping. | |
79 // http://crbug.com/610343 | |
76 std::map<url::Origin, DeviceAddressToIdMap> | 80 std::map<url::Origin, DeviceAddressToIdMap> |
77 origin_to_device_address_to_id_map_; | 81 origin_to_device_address_to_id_map_; |
78 std::map<url::Origin, DeviceIdToAddressMap> | 82 std::map<url::Origin, DeviceIdToAddressMap> |
79 origin_to_device_id_to_address_map_; | 83 origin_to_device_id_to_address_map_; |
80 std::map<url::Origin, DeviceIdToServicesMap> | 84 std::map<url::Origin, DeviceIdToServicesMap> |
81 origin_to_device_id_to_services_map_; | 85 origin_to_device_id_to_services_map_; |
82 | 86 |
83 // Keep track of all device_ids in the map. | 87 // Keep track of all device_ids in the map. |
84 std::set<std::string> device_id_set_; | 88 std::set<std::string> device_id_set_; |
85 }; | 89 }; |
86 | 90 |
87 } // namespace content | 91 } // namespace content |
88 | 92 |
89 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ | 93 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ |
OLD | NEW |