Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: content/browser/bluetooth/bluetooth_allowed_devices_map.h

Issue 1502663003: bluetooth: Implement allowed devices map (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Forgot test file Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_
6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_
7
8 #include <map>
9 #include <set>
10 #include <vector>
11
12 #include "base/memory/scoped_ptr.h"
13 #include "content/common/content_export.h"
14
15 namespace device {
16 class BluetoothUUID;
17 }
18
19 namespace content {
20
21 struct BluetoothScanFilter;
22
23 // Keeps track of which origins are allowed to access which devices and
24 // their services.
25 //
26 // 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.
27 // the generated |device_id| for each origin for a given device.
28 class CONTENT_EXPORT BluetoothAllowedDevicesMap final {
29 public:
30 BluetoothAllowedDevicesMap();
31 ~BluetoothAllowedDevicesMap();
32
33 // 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.
34 // devices for that origin. Returns the generated |device_id| for |origin|
35 // for the device with |device_address|.
36 const std::string& AddDevice(
37 const std::string& origin,
38 const std::string& device_address,
39 const std::vector<BluetoothScanFilter>& filters,
40 const std::vector<device::BluetoothUUID>& optional_services);
41
42 // Removes the Bluetooth Device with |device_address| from the map of allowed
43 // devices for |origin|.
44 void RemoveDevice(const std::string& origin,
45 const std::string& device_address);
46
47 // Returns true if |origin| is allowed to access the Bluetooth Device
48 // with id |device_id|.
49 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.
50 const std::string& device_id);
51 // Returns true if |origin| is allowed to access the Bluetooth Device
52 // with MAC address |device_address|.
53 bool HasDevicePermissionFromDeviceAddress(const std::string& origin,
54 const std::string& device_address);
55
56 // TODO(ortuno): Add function to check if origin is allowed to access
57 // a device's service and add tests for that function.
58 // https://crbug.com/493460
59
60 // Returns the Bluetooth Device's id for |origin|.
61 // 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.
62 // is allowed to interact with the device.
63 const std::string& GetDeviceId(const std::string& origin,
64 const std::string& device_address);
65
66 // Returns the Bluetooth Device's address from |device_id_for_origin|.
67 // This function should never be called before checking if the origin
68 // is allowed to interact with the device.
69 const std::string& GetDeviceAddress(const std::string& origin,
70 const std::string& device_id);
71
72 private:
73 typedef std::map<std::string, std::string> DeviceAddressToIdMap;
74 typedef std::map<std::string, std::string> DeviceIdToAddressMap;
75 typedef std::map<std::string, std::set<std::string>> DeviceIdToServicesMap;
76
77 // 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.
78 const std::string GenerateDeviceId(const std::string& origin);
79 const std::set<std::string> UnionOfServices(
80 const std::vector<BluetoothScanFilter>& filters,
81 const std::vector<device::BluetoothUUID>& optional_services);
82
83 std::map<std::string, DeviceAddressToIdMap>
84 origin_to_device_address_to_id_map_;
85 std::map<std::string, DeviceIdToAddressMap>
86 origin_to_device_id_to_address_map_;
87 std::map<std::string, DeviceIdToServicesMap>
88 origin_to_device_id_to_services_map_;
89 };
90
91 } // namespace content
92
93 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698