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

Side by Side Diff: device/bluetooth/bluetooth_adapter_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_adapter_mac.h" 5 #include "device/bluetooth/bluetooth_adapter_mac.h"
6 6
7 #import <IOBluetooth/objc/IOBluetoothDevice.h> 7 #import <IOBluetooth/objc/IOBluetoothDevice.h>
8 #import <IOBluetooth/objc/IOBluetoothHostController.h> 8 #import <IOBluetooth/objc/IOBluetoothHostController.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 } 554 }
555 555
556 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral, 556 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral,
557 NSError* error) { 557 NSError* error) {
558 BluetoothLowEnergyDeviceMac* device_mac = 558 BluetoothLowEnergyDeviceMac* device_mac =
559 GetBluetoothLowEnergyDeviceMac(peripheral); 559 GetBluetoothLowEnergyDeviceMac(peripheral);
560 if (!device_mac) { 560 if (!device_mac) {
561 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; 561 [low_energy_central_manager_ cancelPeripheralConnection:peripheral];
562 return; 562 return;
563 } 563 }
564 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String
565 << ", error code: " << error.code;
566 BluetoothDevice::ConnectErrorCode error_code = 564 BluetoothDevice::ConnectErrorCode error_code =
567 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); 565 BluetoothDevice::ConnectErrorCode::ERROR_FAILED;
568 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String 566 VLOG(1) << "Fail to connect to peripheral";
569 << ", error code: " << error.code 567 if (error) {
ortuno 2016/08/09 15:40:25 DidFailToConnectPeripheral should always be called
jlebel 2016/08/09 16:23:57 From the documentation it is not obvious, but from
570 << ", converted into: " << error_code; 568 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error);
ortuno 2016/08/09 15:40:25 Did you mean to save the result of this function i
jlebel 2016/08/09 16:23:57 Done.
569 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String
570 << ", error code: " << error.code
571 << ", converted into: " << error_code;
572 }
571 device_mac->DidFailToConnectGatt(error_code); 573 device_mac->DidFailToConnectGatt(error_code);
572 } 574 }
573 575
574 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, 576 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral,
575 NSError* error) { 577 NSError* error) {
576 BluetoothLowEnergyDeviceMac* device_mac = 578 BluetoothLowEnergyDeviceMac* device_mac =
577 GetBluetoothLowEnergyDeviceMac(peripheral); 579 GetBluetoothLowEnergyDeviceMac(peripheral);
578 if (!device_mac) { 580 if (!device_mac) {
579 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; 581 [low_energy_central_manager_ cancelPeripheralConnection:peripheral];
580 return; 582 return;
581 } 583 }
582 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String 584 VLOG(1) << "Peripheral disconnected";
583 << ", error code: " << error.code; 585 if (error) {
584 BluetoothDevice::ConnectErrorCode error_code = 586 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String
585 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); 587 << ", error code: " << error.code;
586 device_mac->DidDisconnectPeripheral(error_code); 588 BluetoothDevice::ConnectErrorCode error_code =
589 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error);
590 device_mac->DidDisconnectPeripheral(error_code);
591 } else {
592 device_mac->DidDisconnectPeripheral();
ortuno 2016/08/09 15:40:25 Maybe just pass in BluetoothDevice::ConnectErrorCo
jlebel 2016/08/09 16:23:58 But if we disconnect explicitly, we should not gen
593 }
587 } 594 }
588 595
589 BluetoothLowEnergyDeviceMac* 596 BluetoothLowEnergyDeviceMac*
590 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) { 597 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) {
591 std::string device_address = 598 std::string device_address =
592 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 599 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
593 DevicesMap::const_iterator iter = devices_.find(device_address); 600 DevicesMap::const_iterator iter = devices_.find(device_address);
594 if (iter == devices_.end()) { 601 if (iter == devices_.end()) {
595 return nil; 602 return nil;
596 } 603 }
597 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 604 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
598 } 605 }
599 606
600 } // namespace device 607 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_low_energy_device_mac.h » ('j') | device/bluetooth/bluetooth_low_energy_device_mac.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698