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

Side by Side Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 2221353002: Bluetooth: mac: Crash while loging nil error. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better fix 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 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 it != gatt_services_.end(); ++it) { 384 it != gatt_services_.end(); ++it) {
385 device::BluetoothRemoteGattService* gatt_service = it->second; 385 device::BluetoothRemoteGattService* gatt_service = it->second;
386 device::BluetoothRemoteGattServiceMac* gatt_service_mac = 386 device::BluetoothRemoteGattServiceMac* gatt_service_mac =
387 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); 387 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service);
388 if (gatt_service_mac->GetService() == cb_service) 388 if (gatt_service_mac->GetService() == cb_service)
389 return gatt_service_mac; 389 return gatt_service_mac;
390 } 390 }
391 return nullptr; 391 return nullptr;
392 } 392 }
393 393
394 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral() {
395 RemoveAllServices();
396 if (create_gatt_connection_error_callbacks_.empty()) {
397 DidDisconnectGatt();
398 } else {
399 DidFailToConnectGatt(BluetoothDevice::ConnectErrorCode::ERROR_UNKNOWN);
400 }
401 }
402
394 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral( 403 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(
395 BluetoothDevice::ConnectErrorCode error_code) { 404 BluetoothDevice::ConnectErrorCode error_code) {
396 SetGattServicesDiscoveryComplete(false); 405 RemoveAllServices();
397 // Removing all services at once to ensure that calling GetGattService on
398 // removed service in GattServiceRemoved returns null.
399 GattServiceMap gatt_services_swapped;
400 gatt_services_swapped.swap(gatt_services_);
401 gatt_services_swapped.clear();
402 if (create_gatt_connection_error_callbacks_.empty()) { 406 if (create_gatt_connection_error_callbacks_.empty()) {
ortuno 2016/08/09 15:40:25 DidDisconnectPeripheral shouldn't be called after
jlebel 2016/08/09 16:23:58 I was guessing it disconnect is called before the
403 // TODO(http://crbug.com/585897): Need to pass the error. 407 // TODO(http://crbug.com/585897): Need to pass the error.
404 DidDisconnectGatt(); 408 DidDisconnectGatt();
405 } else { 409 } else {
406 DidFailToConnectGatt(error_code); 410 DidFailToConnectGatt(error_code);
407 } 411 }
408 } 412 }
413
414 void BluetoothLowEnergyDeviceMac::RemoveAllServices() {
415 SetGattServicesDiscoveryComplete(false);
416 // Removing all services at once to ensure that calling GetGattService on
417 // removed service in GattServiceRemoved returns null.
418 GattServiceMap gatt_services_swapped;
419 gatt_services_swapped.swap(gatt_services_);
420 gatt_services_swapped.clear();
421 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698