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

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

Issue 1922923002: bluetooth: Move requestDevice to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-request-device
Patch Set: Rebase Created 4 years, 7 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ 5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_
6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ 6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 #include <vector> 11 #include <vector>
12 12
13 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h"
14 #include "url/origin.h" 15 #include "url/origin.h"
15 16
16 namespace device { 17 namespace device {
17 class BluetoothUUID; 18 class BluetoothUUID;
18 } 19 }
19 20
20 namespace content { 21 namespace content {
21 22
22 struct BluetoothScanFilter; 23 struct BluetoothScanFilter;
23 24
24 // Keeps track of which origins are allowed to access which devices and 25 // Keeps track of which origins are allowed to access which devices and
25 // their services. 26 // their services.
26 // 27 //
27 // |AddDevice| generates device ids, which are random strings that are unique 28 // |AddDevice| generates device ids, which are random strings that are unique
28 // in the map. 29 // in the map.
29 class CONTENT_EXPORT BluetoothAllowedDevicesMap final { 30 class CONTENT_EXPORT BluetoothAllowedDevicesMap final {
30 public: 31 public:
31 BluetoothAllowedDevicesMap(); 32 BluetoothAllowedDevicesMap();
32 ~BluetoothAllowedDevicesMap(); 33 ~BluetoothAllowedDevicesMap();
33 34
34 // Adds the Bluetooth Device with |device_address| to the map of allowed 35 // Adds the Bluetooth Device with |device_address| to the map of allowed
35 // devices for that origin. Generates and returns a device id. 36 // devices for that origin. Generates and returns a device id. Because
37 // unique origins generate the same hash, unique origins are not supported.
38 // Calling this function with a unique origin will CHECK-fail.
36 const std::string& AddDevice( 39 const std::string& AddDevice(
37 const url::Origin& origin, 40 const url::Origin& origin,
38 const std::string& device_address, 41 const std::string& device_address,
39 const std::vector<BluetoothScanFilter>& filters, 42 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options);
40 const std::vector<device::BluetoothUUID>& optional_services);
41 43
42 // Removes the Bluetooth Device with |device_address| from the map of allowed 44 // Removes the Bluetooth Device with |device_address| from the map of allowed
43 // devices for |origin|. 45 // devices for |origin|.
44 void RemoveDevice(const url::Origin& origin, 46 void RemoveDevice(const url::Origin& origin,
45 const std::string& device_address); 47 const std::string& device_address);
46 48
47 // Returns the Bluetooth Device's id for |origin|. Returns an empty string 49 // Returns the Bluetooth Device's id for |origin|. Returns an empty string
48 // if |origin| is not allowed to access the device. 50 // if |origin| is not allowed to access the device.
49 const std::string& GetDeviceId(const url::Origin& origin, 51 const std::string& GetDeviceId(const url::Origin& origin,
50 const std::string& device_address); 52 const std::string& device_address);
(...skipping 11 matching lines...) Expand all
62 64
63 private: 65 private:
64 typedef std::map<std::string, std::string> DeviceAddressToIdMap; 66 typedef std::map<std::string, std::string> DeviceAddressToIdMap;
65 typedef std::map<std::string, std::string> DeviceIdToAddressMap; 67 typedef std::map<std::string, std::string> DeviceIdToAddressMap;
66 typedef std::map<std::string, std::set<std::string>> DeviceIdToServicesMap; 68 typedef std::map<std::string, std::set<std::string>> DeviceIdToServicesMap;
67 69
68 // Returns an id guaranteed to be unique for the map. The id is randomly 70 // Returns an id guaranteed to be unique for the map. The id is randomly
69 // generated so that an origin can't guess the id used in another origin. 71 // generated so that an origin can't guess the id used in another origin.
70 std::string GenerateDeviceId(); 72 std::string GenerateDeviceId();
71 void AddUnionOfServicesTo( 73 void AddUnionOfServicesTo(
72 const std::vector<BluetoothScanFilter>& filters, 74 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options,
73 const std::vector<device::BluetoothUUID>& optional_services,
74 std::set<std::string>* unionOfServices); 75 std::set<std::string>* unionOfServices);
75 76
77 // TODO(ortuno): Now that there is only one instance of this class per frame
78 // and that this map gets destroyed when navigating consider removing the
79 // origin mapping.
80 // http://crbug.com/610343
76 std::map<url::Origin, DeviceAddressToIdMap> 81 std::map<url::Origin, DeviceAddressToIdMap>
77 origin_to_device_address_to_id_map_; 82 origin_to_device_address_to_id_map_;
78 std::map<url::Origin, DeviceIdToAddressMap> 83 std::map<url::Origin, DeviceIdToAddressMap>
79 origin_to_device_id_to_address_map_; 84 origin_to_device_id_to_address_map_;
80 std::map<url::Origin, DeviceIdToServicesMap> 85 std::map<url::Origin, DeviceIdToServicesMap>
81 origin_to_device_id_to_services_map_; 86 origin_to_device_id_to_services_map_;
82 87
83 // Keep track of all device_ids in the map. 88 // Keep track of all device_ids in the map.
84 std::set<std::string> device_id_set_; 89 std::set<std::string> device_id_set_;
85 }; 90 };
86 91
87 } // namespace content 92 } // namespace content
88 93
89 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ 94 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698