OLD | NEW |
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 #include "content/browser/bluetooth/bluetooth_allowed_devices_map.h" | 5 #include "content/browser/bluetooth/bluetooth_allowed_devices_map.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/optional.h" | 11 #include "base/optional.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "content/browser/bluetooth/bluetooth_blocklist.h" | 14 #include "content/browser/bluetooth/bluetooth_blocklist.h" |
15 #include "content/common/bluetooth/web_bluetooth_device_id.h" | 15 #include "content/common/bluetooth/web_bluetooth_device_id.h" |
16 | 16 |
17 using device::BluetoothUUID; | 17 using device::BluetoothUUID; |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 BluetoothAllowedDevicesMap::BluetoothAllowedDevicesMap() {} | 21 BluetoothAllowedDevicesMap::BluetoothAllowedDevicesMap() {} |
22 BluetoothAllowedDevicesMap::~BluetoothAllowedDevicesMap() {} | 22 BluetoothAllowedDevicesMap::~BluetoothAllowedDevicesMap() {} |
23 | 23 |
24 const WebBluetoothDeviceId& BluetoothAllowedDevicesMap::AddDevice( | 24 const WebBluetoothDeviceId& BluetoothAllowedDevicesMap::AddDevice( |
25 const url::Origin& origin, | 25 const url::Origin& origin, |
26 const std::string& device_address, | 26 const std::string& device_address, |
27 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) { | 27 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) { |
28 VLOG(1) << "Adding a device to Map of Allowed Devices."; | 28 DVLOG(1) << "Adding a device to Map of Allowed Devices."; |
29 | 29 |
30 // "Unique" Origins generate the same key in maps, therefore are not | 30 // "Unique" Origins generate the same key in maps, therefore are not |
31 // supported. | 31 // supported. |
32 CHECK(!origin.unique()); | 32 CHECK(!origin.unique()); |
33 | 33 |
34 auto device_address_to_id_map = origin_to_device_address_to_id_map_[origin]; | 34 auto device_address_to_id_map = origin_to_device_address_to_id_map_[origin]; |
35 auto id_iter = device_address_to_id_map.find(device_address); | 35 auto id_iter = device_address_to_id_map.find(device_address); |
36 if (id_iter != device_address_to_id_map.end()) { | 36 if (id_iter != device_address_to_id_map.end()) { |
37 VLOG(1) << "Device already in map of allowed devices."; | 37 DVLOG(1) << "Device already in map of allowed devices."; |
38 const auto& device_id = id_iter->second; | 38 const auto& device_id = id_iter->second; |
39 | 39 |
40 AddUnionOfServicesTo( | 40 AddUnionOfServicesTo( |
41 options, &origin_to_device_id_to_services_map_[origin][device_id]); | 41 options, &origin_to_device_id_to_services_map_[origin][device_id]); |
42 | 42 |
43 return origin_to_device_address_to_id_map_[origin][device_address]; | 43 return origin_to_device_address_to_id_map_[origin][device_address]; |
44 } | 44 } |
45 const WebBluetoothDeviceId device_id = GenerateUniqueDeviceId(); | 45 const WebBluetoothDeviceId device_id = GenerateUniqueDeviceId(); |
46 VLOG(1) << "Id generated for device: " << device_id; | 46 DVLOG(1) << "Id generated for device: " << device_id; |
47 | 47 |
48 origin_to_device_address_to_id_map_[origin][device_address] = device_id; | 48 origin_to_device_address_to_id_map_[origin][device_address] = device_id; |
49 origin_to_device_id_to_address_map_[origin][device_id] = device_address; | 49 origin_to_device_id_to_address_map_[origin][device_id] = device_address; |
50 AddUnionOfServicesTo( | 50 AddUnionOfServicesTo( |
51 options, &origin_to_device_id_to_services_map_[origin][device_id]); | 51 options, &origin_to_device_id_to_services_map_[origin][device_id]); |
52 | 52 |
53 CHECK(device_id_set_.insert(device_id).second); | 53 CHECK(device_id_set_.insert(device_id).second); |
54 | 54 |
55 return origin_to_device_address_to_id_map_[origin][device_address]; | 55 return origin_to_device_address_to_id_map_[origin][device_address]; |
56 } | 56 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 177 } |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 for (const BluetoothUUID& uuid : options->optional_services) { | 181 for (const BluetoothUUID& uuid : options->optional_services) { |
182 unionOfServices->insert(uuid); | 182 unionOfServices->insert(uuid); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 } // namespace content | 186 } // namespace content |
OLD | NEW |