| OLD | NEW |
| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/mac/mac_util.h" | 18 #include "base/mac/mac_util.h" |
| 19 #include "base/mac/sdk_forward_declarations.h" | 19 #include "base/mac/sdk_forward_declarations.h" |
| 20 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 21 #include "base/profiler/scoped_tracker.h" | 21 #include "base/profiler/scoped_tracker.h" |
| 22 #include "base/sequenced_task_runner.h" | 22 #include "base/sequenced_task_runner.h" |
| 23 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 24 #include "base/strings/sys_string_conversions.h" | 24 #include "base/strings/sys_string_conversions.h" |
| 25 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
| 26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 27 #include "device/bluetooth/bluetooth_adapter_mac_metrics.h" |
| 27 #include "device/bluetooth/bluetooth_classic_device_mac.h" | 28 #include "device/bluetooth/bluetooth_classic_device_mac.h" |
| 28 #include "device/bluetooth/bluetooth_common.h" | 29 #include "device/bluetooth/bluetooth_common.h" |
| 29 #include "device/bluetooth/bluetooth_discovery_session.h" | 30 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 30 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" | 31 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" |
| 31 #include "device/bluetooth/bluetooth_low_energy_central_manager_delegate.h" | 32 #include "device/bluetooth/bluetooth_low_energy_central_manager_delegate.h" |
| 32 #include "device/bluetooth/bluetooth_socket_mac.h" | 33 #include "device/bluetooth/bluetooth_socket_mac.h" |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 // The frequency with which to poll the adapter for updates. | 37 // The frequency with which to poll the adapter for updates. |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 } | 693 } |
| 693 | 694 |
| 694 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral, | 695 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral, |
| 695 NSError* error) { | 696 NSError* error) { |
| 696 BluetoothLowEnergyDeviceMac* device_mac = | 697 BluetoothLowEnergyDeviceMac* device_mac = |
| 697 GetBluetoothLowEnergyDeviceMac(peripheral); | 698 GetBluetoothLowEnergyDeviceMac(peripheral); |
| 698 if (!device_mac) { | 699 if (!device_mac) { |
| 699 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; | 700 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; |
| 700 return; | 701 return; |
| 701 } | 702 } |
| 703 LogDidFailToConnectPeripheralErrorToHistogram(error); |
| 702 BluetoothDevice::ConnectErrorCode error_code = | 704 BluetoothDevice::ConnectErrorCode error_code = |
| 703 BluetoothDevice::ConnectErrorCode::ERROR_UNKNOWN; | 705 BluetoothDevice::ConnectErrorCode::ERROR_UNKNOWN; |
| 704 if (error) { | 706 if (error) { |
| 705 error_code = BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); | 707 error_code = BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); |
| 706 } | 708 } |
| 707 VLOG(1) << *device_mac << ": Failed to connect to peripheral with error " | 709 VLOG(1) << *device_mac << ": Failed to connect to peripheral with error " |
| 708 << BluetoothAdapterMac::String(error) | 710 << BluetoothAdapterMac::String(error) |
| 709 << ", error code: " << error_code; | 711 << ", error code: " << error_code; |
| 710 device_mac->DidFailToConnectGatt(error_code); | 712 device_mac->DidFailToConnectGatt(error_code); |
| 711 } | 713 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 // hash the probability of this occuring with 10,000 devices | 750 // hash the probability of this occuring with 10,000 devices |
| 749 // simultaneously present is 1e-6 (see | 751 // simultaneously present is 1e-6 (see |
| 750 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We | 752 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We |
| 751 // ignore the second device by returning. | 753 // ignore the second device by returning. |
| 752 return true; | 754 return true; |
| 753 } | 755 } |
| 754 return false; | 756 return false; |
| 755 } | 757 } |
| 756 | 758 |
| 757 } // namespace device | 759 } // namespace device |
| OLD | NEW |