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

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

Issue 2015463004: bluetooth: Use BluetoothUUID instead of string when sending uuids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-mojo-request-device
Patch Set: Include string Created 4 years, 6 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 <unordered_set>
11 #include <vector> 12 #include <vector>
12 13
13 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
14 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h" 15 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h"
15 #include "url/origin.h" 16 #include "url/origin.h"
16 17
17 namespace device { 18 namespace device {
18 class BluetoothUUID; 19 class BluetoothUUID;
19 } 20 }
20 21
(...skipping 30 matching lines...) Expand all
51 const std::string& GetDeviceId(const url::Origin& origin, 52 const std::string& GetDeviceId(const url::Origin& origin,
52 const std::string& device_address); 53 const std::string& device_address);
53 54
54 // For |device_id| in |origin|, returns the Bluetooth device's address. If 55 // For |device_id| in |origin|, returns the Bluetooth device's address. If
55 // there is no such |device_id| in |origin|, returns an empty string. 56 // there is no such |device_id| in |origin|, returns an empty string.
56 const std::string& GetDeviceAddress(const url::Origin& origin, 57 const std::string& GetDeviceAddress(const url::Origin& origin,
57 const std::string& device_id); 58 const std::string& device_id);
58 59
59 // Returns true if the origin has previously been granted access to 60 // Returns true if the origin has previously been granted access to
60 // the service. 61 // the service.
61 bool IsOriginAllowedToAccessService(const url::Origin& origin, 62 bool IsOriginAllowedToAccessService(
62 const std::string& device_id, 63 const url::Origin& origin,
63 const std::string& service_uuid) const; 64 const std::string& device_id,
65 const device::BluetoothUUID& service_uuid) const;
64 66
65 private: 67 private:
66 typedef std::map<std::string, std::string> DeviceAddressToIdMap; 68 typedef std::map<std::string, std::string> DeviceAddressToIdMap;
67 typedef std::map<std::string, std::string> DeviceIdToAddressMap; 69 typedef std::map<std::string, std::string> DeviceIdToAddressMap;
68 typedef std::map<std::string, std::set<std::string>> DeviceIdToServicesMap; 70 typedef std::map<std::string, std::unordered_set<device::BluetoothUUID>>
71 DeviceIdToServicesMap;
69 72
70 // Returns an id guaranteed to be unique for the map. The id is randomly 73 // Returns an id guaranteed to be unique for the map. The id is randomly
71 // generated so that an origin can't guess the id used in another origin. 74 // generated so that an origin can't guess the id used in another origin.
72 std::string GenerateDeviceId(); 75 std::string GenerateDeviceId();
73 void AddUnionOfServicesTo( 76 void AddUnionOfServicesTo(
74 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options, 77 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options,
75 std::set<std::string>* unionOfServices); 78 std::unordered_set<device::BluetoothUUID>* unionOfServices);
76 79
77 // TODO(ortuno): Now that there is only one instance of this class per frame 80 // 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 81 // and that this map gets destroyed when navigating consider removing the
79 // origin mapping. 82 // origin mapping.
80 // http://crbug.com/610343 83 // http://crbug.com/610343
81 std::map<url::Origin, DeviceAddressToIdMap> 84 std::map<url::Origin, DeviceAddressToIdMap>
82 origin_to_device_address_to_id_map_; 85 origin_to_device_address_to_id_map_;
83 std::map<url::Origin, DeviceIdToAddressMap> 86 std::map<url::Origin, DeviceIdToAddressMap>
84 origin_to_device_id_to_address_map_; 87 origin_to_device_id_to_address_map_;
85 std::map<url::Origin, DeviceIdToServicesMap> 88 std::map<url::Origin, DeviceIdToServicesMap>
86 origin_to_device_id_to_services_map_; 89 origin_to_device_id_to_services_map_;
87 90
88 // Keep track of all device_ids in the map. 91 // Keep track of all device_ids in the map.
89 std::set<std::string> device_id_set_; 92 std::set<std::string> device_id_set_;
90 }; 93 };
91 94
92 } // namespace content 95 } // namespace content
93 96
94 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_ 97 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698