Chromium Code Reviews| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 // "Unique" Origins generate the same key in maps. The set of "unique" | 48 // "Unique" Origins generate the same key in maps. The set of "unique" |
| 49 // Origins that generate the same key does not intersect the set of | 49 // Origins that generate the same key does not intersect the set of |
| 50 // potentially trustworthy origins; since Bluetooth is only available for | 50 // potentially trustworthy origins; since Bluetooth is only available for |
| 51 // potntially trustworthy origins we should never receive a request from a | 51 // potntially trustworthy origins we should never receive a request from a |
| 52 // "unique" Origin. | 52 // "unique" Origin. |
| 53 // See url::Origin for what constitutes a "unique" Origin and the | 53 // See url::Origin for what constitutes a "unique" Origin and the |
| 54 // Secure Contexts spec for what constitutes a Trusworthy Origin: | 54 // Secure Contexts spec for what constitutes a Trusworthy Origin: |
| 55 // https://w3c.github.io/webappsec-secure-contexts/ | 55 // https://w3c.github.io/webappsec-secure-contexts/ |
| 56 CHECK(!origin.unique()); | 56 CHECK(!origin.unique()); |
| 57 | 57 |
| 58 if (ContainsKey(origin_to_device_address_to_id_map_[origin], | 58 auto device_address_to_id_map = origin_to_device_address_to_id_map_[origin]; |
| 59 device_address)) { | 59 auto id_iter = device_address_to_id_map.find(device_address); |
| 60 if (id_iter != device_address_to_id_map.end()) { | |
| 60 VLOG(1) << "Device already in map of allowed devices."; | 61 VLOG(1) << "Device already in map of allowed devices."; |
| 62 const auto& device_id = id_iter->second; | |
| 63 | |
| 64 // Update set of services. | |
| 65 auto new_services = UnionOfServices(filters, optional_services); | |
|
Jeffrey Yasskin
2016/02/03 23:18:18
We could optimize this by having UnionOfServices a
ortuno
2016/02/04 02:21:09
Done. Also replaced the UnionOfServices function s
Jeffrey Yasskin
2016/02/04 04:03:40
Yep, that's what I meant. Thanks!
| |
| 66 auto& old_services = | |
| 67 origin_to_device_id_to_services_map_[origin][device_id]; | |
| 68 old_services.insert(new_services.begin(), new_services.end()); | |
| 69 | |
| 61 return origin_to_device_address_to_id_map_[origin][device_address]; | 70 return origin_to_device_address_to_id_map_[origin][device_address]; |
| 62 } | 71 } |
| 63 const std::string device_id = GenerateDeviceId(); | 72 const std::string device_id = GenerateDeviceId(); |
| 64 VLOG(1) << "Id generated for device: " << device_id; | 73 VLOG(1) << "Id generated for device: " << device_id; |
| 65 | 74 |
| 66 origin_to_device_address_to_id_map_[origin][device_address] = device_id; | 75 origin_to_device_address_to_id_map_[origin][device_address] = device_id; |
| 67 origin_to_device_id_to_address_map_[origin][device_id] = device_address; | 76 origin_to_device_id_to_address_map_[origin][device_id] = device_address; |
| 68 origin_to_device_id_to_services_map_[origin][device_id] = | 77 origin_to_device_id_to_services_map_[origin][device_id] = |
| 69 UnionOfServices(filters, optional_services); | 78 UnionOfServices(filters, optional_services); |
| 70 | 79 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 unionOfServices.insert(uuid.canonical_value()); | 173 unionOfServices.insert(uuid.canonical_value()); |
| 165 } | 174 } |
| 166 } | 175 } |
| 167 for (const BluetoothUUID& uuid : optional_services) { | 176 for (const BluetoothUUID& uuid : optional_services) { |
| 168 unionOfServices.insert(uuid.canonical_value()); | 177 unionOfServices.insert(uuid.canonical_value()); |
| 169 } | 178 } |
| 170 return unionOfServices; | 179 return unionOfServices; |
| 171 } | 180 } |
| 172 | 181 |
| 173 } // namespace content | 182 } // namespace content |
| OLD | NEW |