#ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_H_
#define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_H_
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "base/containers/flat_set.h"
#include "content/common/content_export.h"
#include "third_party/blink/public/common/bluetooth/web_bluetooth_device_id.h"
#include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom.h"
namespace device {
class BluetoothUUID;
}
namespace content {
class CONTENT_EXPORT BluetoothAllowedDevices final {
public:
BluetoothAllowedDevices();
BluetoothAllowedDevices(const BluetoothAllowedDevices& other);
~BluetoothAllowedDevices();
const blink::WebBluetoothDeviceId& AddDevice(
const std::string& device_address,
const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options);
const blink::WebBluetoothDeviceId& AddDevice(
const std::string& device_address);
void RemoveDevice(const std::string& device_address);
const blink::WebBluetoothDeviceId* GetDeviceId(
const std::string& device_address);
const std::string& GetDeviceAddress(
const blink::WebBluetoothDeviceId& device_id);
bool IsAllowedToAccessAtLeastOneService(
const blink::WebBluetoothDeviceId& device_id) const;
bool IsAllowedToAccessService(
const blink::WebBluetoothDeviceId& device_id,
const device::BluetoothUUID& service_uuid) const;
bool IsAllowedToAccessManufacturerData(
const blink::WebBluetoothDeviceId& device_id,
const uint16_t manufacturer_code) const;
bool IsAllowedToGATTConnect(
const blink::WebBluetoothDeviceId& device_id) const;
private:
typedef std::unordered_map<std::string, blink::WebBluetoothDeviceId>
DeviceAddressToIdMap;
typedef std::unordered_map<blink::WebBluetoothDeviceId,
std::string,
blink::WebBluetoothDeviceIdHash>
DeviceIdToAddressMap;
typedef std::unordered_map<
blink::WebBluetoothDeviceId,
std::unordered_set<device::BluetoothUUID, device::BluetoothUUIDHash>,
blink::WebBluetoothDeviceIdHash>
DeviceIdToServicesMap;
typedef std::unordered_map<blink::WebBluetoothDeviceId,
bool,
blink::WebBluetoothDeviceIdHash>
DeviceIdToConnectableMap;
using DeviceIdToManufacturerDataMap =
std::unordered_map<blink::WebBluetoothDeviceId,
base::flat_set<uint16_t>,
blink::WebBluetoothDeviceIdHash>;
blink::WebBluetoothDeviceId GenerateUniqueDeviceId();
void AddUnionOfServicesTo(
const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options,
std::unordered_set<device::BluetoothUUID, device::BluetoothUUIDHash>*
unionOfServices);
void AddManufacturerDataTo(
const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options,
base::flat_set<uint16_t>* manufacturer_codes);
DeviceAddressToIdMap device_address_to_id_map_;
DeviceIdToAddressMap device_id_to_address_map_;
DeviceIdToServicesMap device_id_to_services_map_;
DeviceIdToManufacturerDataMap device_id_to_manufacturers_map_;
DeviceIdToConnectableMap device_id_to_connectable_map_;
std::unordered_set<blink::WebBluetoothDeviceId,
blink::WebBluetoothDeviceIdHash>
device_id_set_;
};
}
#endif