| 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> |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 const std::string& GetDeviceId(const url::Origin& origin, | 51 const std::string& GetDeviceId(const url::Origin& origin, |
| 52 const std::string& device_address); | 52 const std::string& device_address); |
| 53 | 53 |
| 54 // For |device_id| in |origin|, returns the Bluetooth device's address. If | 54 // For |device_id| in |origin|, returns the Bluetooth device's address. If |
| 55 // there is no such |device_id| in |origin|, returns an empty string. | 55 // there is no such |device_id| in |origin|, returns an empty string. |
| 56 const std::string& GetDeviceAddress(const url::Origin& origin, | 56 const std::string& GetDeviceAddress(const url::Origin& origin, |
| 57 const std::string& device_id); | 57 const std::string& device_id); |
| 58 | 58 |
| 59 // Returns true if the origin has previously been granted access to | 59 // Returns true if the origin has previously been granted access to |
| 60 // the service. | 60 // the service. |
| 61 bool IsOriginAllowedToAccessService(const url::Origin& origin, | 61 bool IsOriginAllowedToAccessService( |
| 62 const std::string& device_id, | 62 const url::Origin& origin, |
| 63 const std::string& service_uuid) const; | 63 const std::string& device_id, |
| 64 const device::BluetoothUUID& service_uuid) const; |
| 64 | 65 |
| 65 private: | 66 private: |
| 66 typedef std::map<std::string, std::string> DeviceAddressToIdMap; | 67 typedef std::map<std::string, std::string> DeviceAddressToIdMap; |
| 67 typedef std::map<std::string, std::string> DeviceIdToAddressMap; | 68 typedef std::map<std::string, std::string> DeviceIdToAddressMap; |
| 68 typedef std::map<std::string, std::set<std::string>> DeviceIdToServicesMap; | 69 typedef std::map<std::string, std::set<device::BluetoothUUID>> |
| 70 DeviceIdToServicesMap; |
| 69 | 71 |
| 70 // Returns an id guaranteed to be unique for the map. The id is randomly | 72 // Returns an id guaranteed to be unique for the map. The id is randomly |
| 71 // generated so that an origin can't guess the id used in another origin. | 73 // generated so that an origin can't guess the id used in another origin. |
| 72 std::string GenerateDeviceId(); | 74 std::string GenerateDeviceId(); |
| 73 void AddUnionOfServicesTo( | 75 void AddUnionOfServicesTo( |
| 74 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options, | 76 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options, |
| 75 std::set<std::string>* unionOfServices); | 77 std::set<device::BluetoothUUID>* unionOfServices); |
| 76 | 78 |
| 77 // TODO(ortuno): Now that there is only one instance of this class per frame | 79 // TODO(ortuno): Now that there is only one instance of this class per frame |
| 78 // and that this map gets destroyed when navigating consider removing the | 80 // and that this map gets destroyed when navigating consider removing the |
| 79 // origin mapping. | 81 // origin mapping. |
| 80 // http://crbug.com/610343 | 82 // http://crbug.com/610343 |
| 81 std::map<url::Origin, DeviceAddressToIdMap> | 83 std::map<url::Origin, DeviceAddressToIdMap> |
| 82 origin_to_device_address_to_id_map_; | 84 origin_to_device_address_to_id_map_; |
| 83 std::map<url::Origin, DeviceIdToAddressMap> | 85 std::map<url::Origin, DeviceIdToAddressMap> |
| 84 origin_to_device_id_to_address_map_; | 86 origin_to_device_id_to_address_map_; |
| 85 std::map<url::Origin, DeviceIdToServicesMap> | 87 std::map<url::Origin, DeviceIdToServicesMap> |
| 86 origin_to_device_id_to_services_map_; | 88 origin_to_device_id_to_services_map_; |
| 87 | 89 |
| 88 // Keep track of all device_ids in the map. | 90 // Keep track of all device_ids in the map. |
| 89 std::set<std::string> device_id_set_; | 91 std::set<std::string> device_id_set_; |
| 90 }; | 92 }; |
| 91 | 93 |
| 92 } // namespace content | 94 } // namespace content |
| 93 | 95 |
| 94 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ | 96 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ |
| OLD | NEW |