Index: content/browser/bluetooth/bluetooth_allowed_devices_map.h |
diff --git a/content/browser/bluetooth/bluetooth_allowed_devices_map.h b/content/browser/bluetooth/bluetooth_allowed_devices_map.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5e6b4a878aa5346c04458f82056811105e0d48d7 |
--- /dev/null |
+++ b/content/browser/bluetooth/bluetooth_allowed_devices_map.h |
@@ -0,0 +1,93 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// 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_ |
+#define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ |
+ |
+#include <map> |
+#include <set> |
+#include <vector> |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "content/common/content_export.h" |
+ |
+namespace device { |
+class BluetoothUUID; |
+} |
+ |
+namespace content { |
+ |
+struct BluetoothScanFilter; |
+ |
+// Keeps track of which origins are allowed to access which devices and |
+// their services. |
+// |
+// When talking about |device_id|s we are refer to |
Jeffrey Yasskin
2016/01/06 00:47:57
s/refer/referring/
ortuno
2016/01/13 01:41:43
Done.
|
+// the generated |device_id| for each origin for a given device. |
+class CONTENT_EXPORT BluetoothAllowedDevicesMap final { |
+ public: |
+ BluetoothAllowedDevicesMap(); |
+ ~BluetoothAllowedDevicesMap(); |
+ |
+ // Adds the Bluetooth Device with |device_address| to the map of allowed |
Jeffrey Yasskin
2016/01/06 00:47:57
Does this still work if the device is already in t
ortuno
2016/01/13 01:41:43
Implementing features that are not yet in the spec
Jeffrey Yasskin
2016/01/13 02:31:36
Fair enough.
|
+ // devices for that origin. Returns the generated |device_id| for |origin| |
+ // for the device with |device_address|. |
+ const std::string& AddDevice( |
+ const std::string& origin, |
+ const std::string& device_address, |
+ const std::vector<BluetoothScanFilter>& filters, |
+ const std::vector<device::BluetoothUUID>& optional_services); |
+ |
+ // Removes the Bluetooth Device with |device_address| from the map of allowed |
+ // devices for |origin|. |
+ void RemoveDevice(const std::string& origin, |
+ const std::string& device_address); |
+ |
+ // Returns true if |origin| is allowed to access the Bluetooth Device |
+ // with id |device_id|. |
+ bool HasDevicePermissionFromDeviceId(const std::string& origin, |
Jeffrey Yasskin
2016/01/06 00:47:57
I might name these HasPermissionToAccessDeviceId()
ortuno
2016/01/13 01:41:43
Done.
|
+ const std::string& device_id); |
+ // Returns true if |origin| is allowed to access the Bluetooth Device |
+ // with MAC address |device_address|. |
+ bool HasDevicePermissionFromDeviceAddress(const std::string& origin, |
+ const std::string& device_address); |
+ |
+ // TODO(ortuno): Add function to check if origin is allowed to access |
+ // a device's service and add tests for that function. |
+ // https://crbug.com/493460 |
+ |
+ // Returns the Bluetooth Device's id for |origin|. |
+ // This function should never be called before checking if the origin |
Jeffrey Yasskin
2016/01/06 00:47:57
It seems cheaper to unify the access check with th
ortuno
2016/01/13 01:41:43
Done.
|
+ // is allowed to interact with the device. |
+ const std::string& GetDeviceId(const std::string& origin, |
+ const std::string& device_address); |
+ |
+ // Returns the Bluetooth Device's address from |device_id_for_origin|. |
+ // This function should never be called before checking if the origin |
+ // is allowed to interact with the device. |
+ const std::string& GetDeviceAddress(const std::string& origin, |
+ const std::string& device_id); |
+ |
+ private: |
+ typedef std::map<std::string, std::string> DeviceAddressToIdMap; |
+ typedef std::map<std::string, std::string> DeviceIdToAddressMap; |
+ typedef std::map<std::string, std::set<std::string>> DeviceIdToServicesMap; |
+ |
+ // Returns an id guaranteed to be unique for the origin. |
Jeffrey Yasskin
2016/01/06 00:47:57
Could you mention that this is also random, so tha
ortuno
2016/01/13 01:41:43
Done.
|
+ const std::string GenerateDeviceId(const std::string& origin); |
+ const std::set<std::string> UnionOfServices( |
+ const std::vector<BluetoothScanFilter>& filters, |
+ const std::vector<device::BluetoothUUID>& optional_services); |
+ |
+ std::map<std::string, DeviceAddressToIdMap> |
+ origin_to_device_address_to_id_map_; |
+ std::map<std::string, DeviceIdToAddressMap> |
+ origin_to_device_id_to_address_map_; |
+ std::map<std::string, DeviceIdToServicesMap> |
+ origin_to_device_id_to_services_map_; |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ |