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_blacklist.h" | 14 #include "content/browser/bluetooth/bluetooth_blacklist.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 namespace { | |
22 | |
23 std::ostream& operator<<(std::ostream& out, | |
24 const WebBluetoothDeviceId& device_id) { | |
25 return out << device_id.str(); | |
26 } | |
27 | |
28 } // namespace | |
29 | |
21 BluetoothAllowedDevicesMap::BluetoothAllowedDevicesMap() {} | 30 BluetoothAllowedDevicesMap::BluetoothAllowedDevicesMap() {} |
22 BluetoothAllowedDevicesMap::~BluetoothAllowedDevicesMap() {} | 31 BluetoothAllowedDevicesMap::~BluetoothAllowedDevicesMap() {} |
23 | 32 |
24 const WebBluetoothDeviceId& BluetoothAllowedDevicesMap::AddDevice( | 33 const WebBluetoothDeviceId& BluetoothAllowedDevicesMap::AddDevice( |
25 const url::Origin& origin, | 34 const url::Origin& origin, |
26 const std::string& device_address, | 35 const std::string& device_address, |
27 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) { | 36 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) { |
28 VLOG(1) << "Adding a device to Map of Allowed Devices."; | 37 VLOG(1) << "Adding a device to Map of Allowed Devices."; |
29 | 38 |
30 // "Unique" Origins generate the same key in maps, therefore are not | 39 // "Unique" Origins generate the same key in maps, therefore are not |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 device_id = WebBluetoothDeviceId::Create(); | 169 device_id = WebBluetoothDeviceId::Create(); |
161 } | 170 } |
162 return device_id; | 171 return device_id; |
163 } | 172 } |
164 | 173 |
165 void BluetoothAllowedDevicesMap::AddUnionOfServicesTo( | 174 void BluetoothAllowedDevicesMap::AddUnionOfServicesTo( |
166 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options, | 175 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options, |
167 std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash>* | 176 std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash>* |
168 unionOfServices) { | 177 unionOfServices) { |
169 for (const auto& filter : options->filters) { | 178 for (const auto& filter : options->filters) { |
170 for (const base::Optional<BluetoothUUID>& uuid : filter->services) { | 179 if (filter->services) { |
ortuno
2016/11/21 04:42:31
All this nesting makes the code less readable. I w
juncai
2016/11/21 21:27:05
Added test for this.
Done.
| |
171 unionOfServices->insert(uuid.value()); | 180 for (const BluetoothUUID& uuid : filter->services.value()) { |
181 unionOfServices->insert(uuid); | |
182 } | |
172 } | 183 } |
173 } | 184 } |
174 for (const base::Optional<BluetoothUUID>& uuid : options->optional_services) { | 185 for (const BluetoothUUID& uuid : options->optional_services) { |
175 unionOfServices->insert(uuid.value()); | 186 unionOfServices->insert(uuid); |
176 } | 187 } |
177 } | 188 } |
178 | 189 |
179 } // namespace content | 190 } // namespace content |
OLD | NEW |