| 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 "device/bluetooth/bluetooth_low_energy_device_mac.h" | 5 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" |
| 6 | 6 |
| 7 #import <CoreFoundation/CoreFoundation.h> | 7 #import <CoreFoundation/CoreFoundation.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); | 315 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); |
| 316 if (gatt_service_mac->GetService() == cb_service) | 316 if (gatt_service_mac->GetService() == cb_service) |
| 317 return gatt_service_mac; | 317 return gatt_service_mac; |
| 318 } | 318 } |
| 319 return nullptr; | 319 return nullptr; |
| 320 } | 320 } |
| 321 | 321 |
| 322 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral( | 322 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral( |
| 323 BluetoothDevice::ConnectErrorCode error_code) { | 323 BluetoothDevice::ConnectErrorCode error_code) { |
| 324 SetGattServicesDiscoveryComplete(false); | 324 SetGattServicesDiscoveryComplete(false); |
| 325 // Explicitly take and erase GATT services one by one to ensure that calling | 325 // Removing all services at once to ensure that calling GetGattService on |
| 326 // GetGattService on removed service in GattServiceRemoved returns null. | 326 // removed service in GattServiceRemoved returns null. |
| 327 std::vector<std::string> service_keys; | 327 GattServiceMap gatt_services_swapped; |
| 328 for (const auto& gatt_service : gatt_services_) { | 328 gatt_services_swapped.swap(gatt_services_); |
| 329 service_keys.push_back(gatt_service.first); | 329 gatt_services_swapped.clear(); |
| 330 } | |
| 331 for (const auto& key : service_keys) { | |
| 332 gatt_services_.take_and_erase(key); | |
| 333 } | |
| 334 if (create_gatt_connection_error_callbacks_.empty()) { | 330 if (create_gatt_connection_error_callbacks_.empty()) { |
| 335 // TODO(http://crbug.com/585897): Need to pass the error. | 331 // TODO(http://crbug.com/585897): Need to pass the error. |
| 336 DidDisconnectGatt(); | 332 DidDisconnectGatt(); |
| 337 } else { | 333 } else { |
| 338 DidFailToConnectGatt(error_code); | 334 DidFailToConnectGatt(error_code); |
| 339 } | 335 } |
| 340 } | 336 } |
| OLD | NEW |