Chromium Code Reviews| Index: content/browser/bluetooth/bluetooth_allowed_devices.h |
| diff --git a/content/browser/bluetooth/bluetooth_allowed_devices_map.h b/content/browser/bluetooth/bluetooth_allowed_devices.h |
| similarity index 46% |
| rename from content/browser/bluetooth/bluetooth_allowed_devices_map.h |
| rename to content/browser/bluetooth/bluetooth_allowed_devices.h |
| index 3dd20114456556d6e3f518fd2e8e1ae0333004f3..d3814adbe0509f9c49c9d61521facad2f21efa2e 100644 |
| --- a/content/browser/bluetooth/bluetooth_allowed_devices_map.h |
| +++ b/content/browser/bluetooth/bluetooth_allowed_devices.h |
| @@ -2,8 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_H_ |
| -#define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_H_ |
| +#ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_H_ |
| +#define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_H_ |
| #include <memory> |
| #include <string> |
| @@ -15,7 +15,6 @@ |
| #include "content/common/bluetooth/web_bluetooth_device_id.h" |
| #include "content/common/content_export.h" |
| #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.mojom.h" |
| -#include "url/origin.h" |
| namespace device { |
| class BluetoothUUID; |
| @@ -23,60 +22,49 @@ class BluetoothUUID; |
| namespace content { |
| -// Keeps track of which origins are allowed to access which devices and |
| -// their services. |
| +// Keeps track of which devices and their services are allowed to access. |
|
scheib
2017/01/26 04:27:36
Tracks the devices and their services that a site
juncai
2017/01/30 20:34:55
Done.
|
| // |
| // |AddDevice| generates device ids, which are random strings that are unique |
| // in the map. |
| -class CONTENT_EXPORT BluetoothAllowedDevicesMap final { |
| +class CONTENT_EXPORT BluetoothAllowedDevices final { |
| public: |
| - BluetoothAllowedDevicesMap(); |
| - ~BluetoothAllowedDevicesMap(); |
| + BluetoothAllowedDevices(); |
| + BluetoothAllowedDevices(const BluetoothAllowedDevices& other); |
| + ~BluetoothAllowedDevices(); |
| // Adds the Bluetooth Device with |device_address| to the map of allowed |
| - // devices for that origin. Generates and returns a device id. Because |
| - // unique origins generate the same hash, unique origins are not supported. |
| - // Calling this function with a unique origin will CHECK-fail. |
| + // devices. Generates and returns a device id. |
|
scheib
2017/01/26 04:27:36
a new random device ID so that devices IDs can not
juncai
2017/01/30 20:34:55
Done.
|
| const WebBluetoothDeviceId& AddDevice( |
| - const url::Origin& origin, |
| const std::string& device_address, |
| const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options); |
| // Removes the Bluetooth Device with |device_address| from the map of allowed |
| - // devices for |origin|. |
| - void RemoveDevice(const url::Origin& origin, |
| - const std::string& device_address); |
| - |
| - // Returns the Bluetooth Device's id for |origin| if |origin| is allowed to |
| - // access the device. |
| - const WebBluetoothDeviceId* GetDeviceId(const url::Origin& origin, |
| - const std::string& device_address); |
| - |
| - // For |device_id| in |origin|, returns the Bluetooth device's address. If |
| - // there is no such |device_id| in |origin|, returns an empty string. |
| - const std::string& GetDeviceAddress(const url::Origin& origin, |
| - const WebBluetoothDeviceId& device_id); |
| - |
| - // Returns true if the origin has previously been granted access to at least |
| - // one service. |
| - bool IsOriginAllowedToAccessAtLeastOneService( |
| - const url::Origin& origin, |
| + // devices. |
| + void RemoveDevice(const std::string& device_address); |
| + |
| + // Returns the Bluetooth Device's id if the device is allowed to access. |
|
scheib
2017/01/26 04:27:36
id if it has been added previously with |AddDevice
juncai
2017/01/30 20:34:55
Done.
|
| + const WebBluetoothDeviceId* GetDeviceId(const std::string& device_address); |
| + |
| + // For |device_id|, returns the Bluetooth device's address. If there is no |
| + // such |device_id|, returns an empty string. |
| + const std::string& GetDeviceAddress(const WebBluetoothDeviceId& device_id); |
| + |
| + // Returns true if access has previously been granted to at least one |
| + // service. |
| + bool IsAllowedToAccessAtLeastOneService( |
| const WebBluetoothDeviceId& device_id) const; |
| - // Returns true if the origin has previously been granted access to |
| - // the service. |
| - bool IsOriginAllowedToAccessService( |
| - const url::Origin& origin, |
| + // Returns true if access has previously been granted to the service. |
| + bool IsAllowedToAccessService( |
| const WebBluetoothDeviceId& device_id, |
| const device::BluetoothUUID& service_uuid) const; |
| private: |
| typedef std::unordered_map<std::string, WebBluetoothDeviceId> |
| DeviceAddressToIdMap; |
| - typedef std::unordered_map<WebBluetoothDeviceId, |
| - std::string, |
| - WebBluetoothDeviceIdHash> |
| - DeviceIdToAddressMap; |
| + typedef std:: |
| + unordered_map<WebBluetoothDeviceId, std::string, WebBluetoothDeviceIdHash> |
| + DeviceIdToAddressMap; |
| typedef std::unordered_map< |
| WebBluetoothDeviceId, |
| std::unordered_set<device::BluetoothUUID, device::BluetoothUUIDHash>, |
| @@ -91,16 +79,9 @@ class CONTENT_EXPORT BluetoothAllowedDevicesMap final { |
| std::unordered_set<device::BluetoothUUID, device::BluetoothUUIDHash>* |
| unionOfServices); |
| - // TODO(ortuno): Now that there is only one instance of this class per frame |
| - // and that this map gets destroyed when navigating consider removing the |
| - // origin mapping. |
| - // http://crbug.com/610343 |
| - std::map<url::Origin, DeviceAddressToIdMap> |
| - origin_to_device_address_to_id_map_; |
| - std::map<url::Origin, DeviceIdToAddressMap> |
| - origin_to_device_id_to_address_map_; |
| - std::map<url::Origin, DeviceIdToServicesMap> |
| - origin_to_device_id_to_services_map_; |
| + DeviceAddressToIdMap device_address_to_id_map_; |
| + DeviceIdToAddressMap device_id_to_address_map_; |
| + DeviceIdToServicesMap device_id_to_services_map_; |
| // Keep track of all device_ids in the map. |
| std::unordered_set<WebBluetoothDeviceId, WebBluetoothDeviceIdHash> |
| @@ -109,4 +90,4 @@ class CONTENT_EXPORT BluetoothAllowedDevicesMap final { |
| } // namespace content |
| -#endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_H_ |
| +#endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_H_ |