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

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

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: Lint 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 #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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 auto id_iter = device_id_to_address_map.find(device_id); 123 auto id_iter = device_id_to_address_map.find(device_id);
124 124
125 return id_iter == device_id_to_address_map.end() ? base::EmptyString() 125 return id_iter == device_id_to_address_map.end() ? base::EmptyString()
126 : id_iter->second; 126 : id_iter->second;
127 } 127 }
128 128
129 bool BluetoothAllowedDevicesMap::IsOriginAllowedToAccessService( 129 bool BluetoothAllowedDevicesMap::IsOriginAllowedToAccessService(
130 const url::Origin& origin, 130 const url::Origin& origin,
131 const std::string& device_id, 131 const std::string& device_id,
132 const std::string& service_uuid) const { 132 const BluetoothUUID& service_uuid) const {
133 if (BluetoothBlacklist::Get().IsExcluded(BluetoothUUID(service_uuid))) { 133 if (BluetoothBlacklist::Get().IsExcluded(service_uuid)) {
134 return false; 134 return false;
135 } 135 }
136 136
137 auto id_map_iter = origin_to_device_id_to_services_map_.find(origin); 137 auto id_map_iter = origin_to_device_id_to_services_map_.find(origin);
138 if (id_map_iter == origin_to_device_id_to_services_map_.end()) { 138 if (id_map_iter == origin_to_device_id_to_services_map_.end()) {
139 return false; 139 return false;
140 } 140 }
141 141
142 const auto& device_id_to_services_map = id_map_iter->second; 142 const auto& device_id_to_services_map = id_map_iter->second;
143 143
144 auto id_iter = device_id_to_services_map.find(device_id); 144 auto id_iter = device_id_to_services_map.find(device_id);
145 145
146 return id_iter == device_id_to_services_map.end() 146 return id_iter == device_id_to_services_map.end()
147 ? false 147 ? false
148 : ContainsKey(id_iter->second, service_uuid); 148 : ContainsKey(id_iter->second, service_uuid);
149 } 149 }
150 150
151 std::string BluetoothAllowedDevicesMap::GenerateDeviceId() { 151 std::string BluetoothAllowedDevicesMap::GenerateDeviceId() {
152 std::string device_id = GetBase64Id(); 152 std::string device_id = GetBase64Id();
153 while (ContainsKey(device_id_set_, device_id)) { 153 while (ContainsKey(device_id_set_, device_id)) {
154 LOG(WARNING) << "Generated repeated id."; 154 LOG(WARNING) << "Generated repeated id.";
155 device_id = GetBase64Id(); 155 device_id = GetBase64Id();
156 } 156 }
157 return device_id; 157 return device_id;
158 } 158 }
159 159
160 void BluetoothAllowedDevicesMap::AddUnionOfServicesTo( 160 void BluetoothAllowedDevicesMap::AddUnionOfServicesTo(
161 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options, 161 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options,
162 std::set<std::string>* unionOfServices) { 162 std::set<BluetoothUUID>* unionOfServices) {
163 for (const auto& filter : options->filters) { 163 for (const auto& filter : options->filters) {
164 for (const std::string& uuid : filter->services) { 164 for (const std::unique_ptr<BluetoothUUID>& uuid : filter->services) {
Jeffrey Yasskin 2016/05/28 04:38:06 I'm definitely sad that there's no type-based way
ortuno 2016/05/31 17:30:47 I'm OK with waiting.
165 unionOfServices->insert(uuid); 165 unionOfServices->insert(*uuid);
166 } 166 }
167 } 167 }
168 for (const std::string& uuid : options->optional_services) { 168 for (const std::unique_ptr<BluetoothUUID>& uuid :
169 unionOfServices->insert(uuid); 169 options->optional_services) {
170 unionOfServices->insert(*uuid);
170 } 171 }
171 } 172 }
172 173
173 } // namespace content 174 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698