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

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: Fix merge conflicts 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 #include "url/origin.h"
15
16 namespace device {
17 class BluetoothUUID;
18 }
19
20 namespace content {
21
22 struct BluetoothScanFilter;
23
24 // Keeps track of which origins are allowed to access which devices and
25 // their services.
26 //
27 // |AddDevice| generates device ids, which are random strings that are unique
28 // for each (origin, device address) pair.
29 class CONTENT_EXPORT BluetoothAllowedDevicesMap final {
30 public:
31 BluetoothAllowedDevicesMap();
32 ~BluetoothAllowedDevicesMap();
33
34 // Adds the Bluetooth Device with |device_address| to the map of allowed
35 // devices for that origin. Generates and returns a device id for the
36 // (|origin|, |device_address|) pair.
37 const std::string& AddDevice(
38 const url::Origin& origin,
39 const std::string& device_address,
40 const std::vector<BluetoothScanFilter>& filters,
41 const std::vector<device::BluetoothUUID>& optional_services);
42
43 // Removes the Bluetooth Device with |device_address| from the map of allowed
44 // devices for |origin|.
45 void RemoveDevice(const url::Origin& origin,
46 const std::string& device_address);
47
48 // TODO(ortuno): Add function to check if origin is allowed to access
49 // a device's service and add tests for that function.
50 // https://crbug.com/493460
51
52 // Returns the Bluetooth Device's id for |origin|. Returns an empty string
53 // if the origin is not allowed to access the device.
54 const std::string& GetDeviceId(const url::Origin& origin,
55 const std::string& device_address);
56
57 // For |device_id| in |origin|, returns the Bluetooth device's address. If
58 // there is no such |device_id| in |origin|, returns an empty string.
59 const std::string& GetDeviceAddress(const url::Origin& origin,
60 const std::string& device_id);
61
62 private:
63 typedef std::map<std::string, std::string> DeviceAddressToIdMap;
64 typedef std::map<std::string, std::string> DeviceIdToAddressMap;
65 typedef std::map<std::string, std::set<std::string>> DeviceIdToServicesMap;
66
67 // Returns an id guaranteed to be unique for the origin. The id is randomly
68 // generated so that an origin can't guess the id used in another origin.
69 std::string GenerateDeviceId(const url::Origin& origin);
70 std::set<std::string> UnionOfServices(
71 const std::vector<BluetoothScanFilter>& filters,
72 const std::vector<device::BluetoothUUID>& optional_services);
73
74 std::map<url::Origin, DeviceAddressToIdMap>
75 origin_to_device_address_to_id_map_;
76 std::map<url::Origin, DeviceIdToAddressMap>
77 origin_to_device_id_to_address_map_;
78 std::map<url::Origin, DeviceIdToServicesMap>
79 origin_to_device_id_to_services_map_;
80 };
81
82 } // namespace content
83
84 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_
OLDNEW
« no previous file with comments | « content/browser/bad_message.h ('k') | content/browser/bluetooth/bluetooth_allowed_devices_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698