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

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: Add comment for bad renderer check Created 4 years, 11 months 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 referring to
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
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,
palmer 2016/01/13 22:52:06 This should probably be a url::Origin, and not a s
ortuno 2016/01/14 02:44:58 Done.
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 // TODO(ortuno): Add function to check if origin is allowed to access
48 // a device's service and add tests for that function.
49 // https://crbug.com/493460
50
51 // Returns the Bluetooth Device's id for |origin|. Returns an empty string
52 // if the origin is not allowed to access the device.
53 const std::string& GetDeviceId(const std::string& origin,
54 const std::string& device_address);
55
56 // Returns the Bluetooth Device's address from |device_id_for_origin|. Returns
57 // an empty string if the origin is not allowed to access the device.
58 const std::string& GetDeviceAddress(const std::string& origin,
59 const std::string& device_id);
60
61 private:
62 typedef std::map<std::string, std::string> DeviceAddressToIdMap;
63 typedef std::map<std::string, std::string> DeviceIdToAddressMap;
64 typedef std::map<std::string, std::set<std::string>> DeviceIdToServicesMap;
65
66 // Returns an id guaranteed to be unique for the origin. The id is randomly
67 // generated so that an origin can't guess the ID used in another origin.
68 std::string GenerateDeviceId(const std::string& origin);
69 std::set<std::string> UnionOfServices(
70 const std::vector<BluetoothScanFilter>& filters,
71 const std::vector<device::BluetoothUUID>& optional_services);
72
73 std::map<std::string, DeviceAddressToIdMap>
74 origin_to_device_address_to_id_map_;
75 std::map<std::string, DeviceIdToAddressMap>
76 origin_to_device_id_to_address_map_;
77 std::map<std::string, DeviceIdToServicesMap>
78 origin_to_device_id_to_services_map_;
79 };
80
81 } // namespace content
82
83 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698