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

Side by Side Diff: device/bluetooth/bluetooth_device_win.cc

Issue 2244693002: bluetooth: Refactor how we update based on Advertising Data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix arc Created 4 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "device/bluetooth/bluetooth_device_win.h" 5 #include "device/bluetooth/bluetooth_device_win.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/containers/scoped_ptr_hash_map.h" 10 #include "base/containers/scoped_ptr_hash_map.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 bool BluetoothDeviceWin::IsConnectable() const { 107 bool BluetoothDeviceWin::IsConnectable() const {
108 return false; 108 return false;
109 } 109 }
110 110
111 bool BluetoothDeviceWin::IsConnecting() const { 111 bool BluetoothDeviceWin::IsConnecting() const {
112 return false; 112 return false;
113 } 113 }
114 114
115 BluetoothDevice::UUIDList BluetoothDeviceWin::GetUUIDs() const { 115 BluetoothDevice::UUIDSet BluetoothDeviceWin::GetUUIDs() const {
116 return uuids_; 116 return uuids_;
117 } 117 }
118 118
119 base::Optional<int8_t> BluetoothDeviceWin::GetInquiryRSSI() const { 119 base::Optional<int8_t> BluetoothDeviceWin::GetInquiryRSSI() const {
120 // In windows, we can only get connected devices and connected 120 // In windows, we can only get connected devices and connected
121 // devices don't have an Inquiry RSSI. 121 // devices don't have an Inquiry RSSI.
122 return base::nullopt; 122 return base::nullopt;
123 } 123 }
124 124
125 base::Optional<int8_t> BluetoothDeviceWin::GetInquiryTxPower() const { 125 base::Optional<int8_t> BluetoothDeviceWin::GetInquiryTxPower() const {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 const BluetoothTaskManagerWin::DeviceState& device_state) { 226 const BluetoothTaskManagerWin::DeviceState& device_state) {
227 if (address_ != device_state.address || name_ != device_state.name || 227 if (address_ != device_state.address || name_ != device_state.name ||
228 bluetooth_class_ != device_state.bluetooth_class || 228 bluetooth_class_ != device_state.bluetooth_class ||
229 visible_ != device_state.visible || 229 visible_ != device_state.visible ||
230 connected_ != device_state.connected || 230 connected_ != device_state.connected ||
231 paired_ != device_state.authenticated) { 231 paired_ != device_state.authenticated) {
232 return false; 232 return false;
233 } 233 }
234 234
235 // Checks service collection 235 // Checks service collection
236 typedef std::set<BluetoothUUID> UUIDSet;
237 typedef base::ScopedPtrHashMap<std::string, 236 typedef base::ScopedPtrHashMap<std::string,
238 std::unique_ptr<BluetoothServiceRecordWin>> 237 std::unique_ptr<BluetoothServiceRecordWin>>
239 ServiceRecordMap; 238 ServiceRecordMap;
240 239
241 UUIDSet known_services; 240 UUIDSet known_services = uuids_;
Jeffrey Yasskin 2016/08/19 15:09:53 Try not to make a copy here, if uuids_ doesn't cha
ortuno 2016/08/19 20:50:33 Done.
242 for (UUIDList::const_iterator iter = uuids_.begin(); iter != uuids_.end();
243 ++iter) {
244 known_services.insert((*iter));
245 }
246 241
247 UUIDSet new_services; 242 UUIDSet new_services;
248 ServiceRecordMap new_service_records; 243 ServiceRecordMap new_service_records;
249 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator 244 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
250 iter = device_state.service_record_states.begin(); 245 iter = device_state.service_record_states.begin();
251 iter != device_state.service_record_states.end(); ++iter) { 246 iter != device_state.service_record_states.end(); ++iter) {
252 BluetoothServiceRecordWin* service_record = new BluetoothServiceRecordWin( 247 BluetoothServiceRecordWin* service_record = new BluetoothServiceRecordWin(
253 address_, (*iter)->name, (*iter)->sdp_bytes, (*iter)->gatt_uuid); 248 address_, (*iter)->name, (*iter)->sdp_bytes, (*iter)->gatt_uuid);
254 new_services.insert(service_record->uuid()); 249 new_services.insert(service_record->uuid());
255 new_service_records.set( 250 new_service_records.set(
256 service_record->uuid().canonical_value(), 251 service_record->uuid().canonical_value(),
257 std::unique_ptr<BluetoothServiceRecordWin>(service_record)); 252 std::unique_ptr<BluetoothServiceRecordWin>(service_record));
258 } 253 }
259 254
260 UUIDSet removed_services = 255 // Check that no new services have been added or removed.
261 base::STLSetDifference<UUIDSet>(known_services, new_services); 256 if (known_services != new_services) {
262 if (!removed_services.empty()) {
263 return false;
264 }
265 UUIDSet added_devices =
266 base::STLSetDifference<UUIDSet>(new_services, known_services);
267 if (!added_devices.empty()) {
268 return false; 257 return false;
269 } 258 }
270 259
271 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); 260 for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
272 iter != service_record_list_.end(); ++iter) { 261 iter != service_record_list_.end(); ++iter) {
273 BluetoothServiceRecordWin* service_record = (*iter); 262 BluetoothServiceRecordWin* service_record = (*iter);
274 BluetoothServiceRecordWin* new_service_record = 263 BluetoothServiceRecordWin* new_service_record =
275 new_service_records.get((*iter)->uuid().canonical_value()); 264 new_service_records.get((*iter)->uuid().canonical_value());
276 if (!service_record->IsEqual(*new_service_record)) 265 if (!service_record->IsEqual(*new_service_record))
277 return false; 266 return false;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 uuids_.clear(); 302 uuids_.clear();
314 service_record_list_.clear(); 303 service_record_list_.clear();
315 304
316 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator 305 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
317 iter = device_state.service_record_states.begin(); 306 iter = device_state.service_record_states.begin();
318 iter != device_state.service_record_states.end(); ++iter) { 307 iter != device_state.service_record_states.end(); ++iter) {
319 BluetoothServiceRecordWin* service_record = 308 BluetoothServiceRecordWin* service_record =
320 new BluetoothServiceRecordWin(device_state.address, (*iter)->name, 309 new BluetoothServiceRecordWin(device_state.address, (*iter)->name,
321 (*iter)->sdp_bytes, (*iter)->gatt_uuid); 310 (*iter)->sdp_bytes, (*iter)->gatt_uuid);
322 service_record_list_.push_back(service_record); 311 service_record_list_.push_back(service_record);
323 uuids_.push_back(service_record->uuid()); 312 uuids_.insert(service_record->uuid());
324 } 313 }
325 314
326 if (!device_state.is_bluetooth_classic()) 315 if (!device_state.is_bluetooth_classic())
327 UpdateGattServices(device_state.service_record_states); 316 UpdateGattServices(device_state.service_record_states);
328 } 317 }
329 318
330 bool BluetoothDeviceWin::IsGattServiceDiscovered(BluetoothUUID& uuid, 319 bool BluetoothDeviceWin::IsGattServiceDiscovered(BluetoothUUID& uuid,
331 uint16_t attribute_handle) { 320 uint16_t attribute_handle) {
332 GattServiceMap::iterator it = gatt_services_.begin(); 321 GattServiceMap::iterator it = gatt_services_.begin();
333 for (; it != gatt_services_.end(); it++) { 322 for (; it != gatt_services_.end(); it++) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 primary_service->GetIdentifier(), 386 primary_service->GetIdentifier(),
398 std::unique_ptr<BluetoothRemoteGattService>(primary_service)); 387 std::unique_ptr<BluetoothRemoteGattService>(primary_service));
399 adapter_->NotifyGattServiceAdded(primary_service); 388 adapter_->NotifyGattServiceAdded(primary_service);
400 } 389 }
401 } 390 }
402 391
403 adapter_->NotifyGattServicesDiscovered(this); 392 adapter_->NotifyGattServicesDiscovered(this);
404 } 393 }
405 394
406 } // namespace device 395 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698