| 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 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 BluetoothDiscoveryManagerMac::CreateClassic(this)), | 93 BluetoothDiscoveryManagerMac::CreateClassic(this)), |
| 94 weak_ptr_factory_(this) { | 94 weak_ptr_factory_(this) { |
| 95 if (IsLowEnergyAvailable()) { | 95 if (IsLowEnergyAvailable()) { |
| 96 low_energy_discovery_manager_.reset( | 96 low_energy_discovery_manager_.reset( |
| 97 BluetoothLowEnergyDiscoveryManagerMac::Create(this)); | 97 BluetoothLowEnergyDiscoveryManagerMac::Create(this)); |
| 98 low_energy_central_manager_delegate_.reset( | 98 low_energy_central_manager_delegate_.reset( |
| 99 [[BluetoothLowEnergyCentralManagerDelegate alloc] | 99 [[BluetoothLowEnergyCentralManagerDelegate alloc] |
| 100 initWithDiscoveryManager:low_energy_discovery_manager_.get() | 100 initWithDiscoveryManager:low_energy_discovery_manager_.get() |
| 101 andAdapter:this]); | 101 andAdapter:this]); |
| 102 low_energy_central_manager_.reset([[CBCentralManager alloc] | 102 low_energy_central_manager_.reset([[CBCentralManager alloc] |
| 103 initWithDelegate:low_energy_central_manager_delegate_.get() | 103 initWithDelegate:low_energy_central_manager_delegate_ |
| 104 queue:dispatch_get_main_queue()]); | 104 queue:dispatch_get_main_queue()]); |
| 105 low_energy_discovery_manager_->SetCentralManager( | 105 low_energy_discovery_manager_->SetCentralManager( |
| 106 low_energy_central_manager_.get()); | 106 low_energy_central_manager_); |
| 107 } | 107 } |
| 108 DCHECK(classic_discovery_manager_.get()); | 108 DCHECK(classic_discovery_manager_); |
| 109 } | 109 } |
| 110 | 110 |
| 111 BluetoothAdapterMac::~BluetoothAdapterMac() { | 111 BluetoothAdapterMac::~BluetoothAdapterMac() { |
| 112 // When devices will be destroyed, they will need this current instance to | 112 // When devices will be destroyed, they will need this current instance to |
| 113 // disconnect the gatt connection. To make sure they don't use the mac | 113 // disconnect the gatt connection. To make sure they don't use the mac |
| 114 // adapter, they should be explicitly destroyed here. | 114 // adapter, they should be explicitly destroyed here. |
| 115 devices_.clear(); | 115 devices_.clear(); |
| 116 // Set low_energy_central_manager_ to nil so no devices will try to use it | 116 // Set low_energy_central_manager_ to nil so no devices will try to use it |
| 117 // while being destroyed after this method. |devices_| is owned by | 117 // while being destroyed after this method. |devices_| is owned by |
| 118 // BluetoothAdapter. | 118 // BluetoothAdapter. |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 286 |
| 287 void BluetoothAdapterMac::RemovePairingDelegateInternal( | 287 void BluetoothAdapterMac::RemovePairingDelegateInternal( |
| 288 BluetoothDevice::PairingDelegate* pairing_delegate) {} | 288 BluetoothDevice::PairingDelegate* pairing_delegate) {} |
| 289 | 289 |
| 290 void BluetoothAdapterMac::SetCentralManagerForTesting( | 290 void BluetoothAdapterMac::SetCentralManagerForTesting( |
| 291 CBCentralManager* central_manager) { | 291 CBCentralManager* central_manager) { |
| 292 CHECK(BluetoothAdapterMac::IsLowEnergyAvailable()); | 292 CHECK(BluetoothAdapterMac::IsLowEnergyAvailable()); |
| 293 central_manager.delegate = low_energy_central_manager_delegate_; | 293 central_manager.delegate = low_energy_central_manager_delegate_; |
| 294 low_energy_central_manager_.reset(central_manager, | 294 low_energy_central_manager_.reset(central_manager, |
| 295 base::scoped_policy::RETAIN); | 295 base::scoped_policy::RETAIN); |
| 296 low_energy_discovery_manager_->SetCentralManager( | 296 low_energy_discovery_manager_->SetCentralManager(low_energy_central_manager_); |
| 297 low_energy_central_manager_.get()); | |
| 298 } | 297 } |
| 299 | 298 |
| 300 CBCentralManager* BluetoothAdapterMac::GetCentralManager() { | 299 CBCentralManager* BluetoothAdapterMac::GetCentralManager() { |
| 301 return low_energy_central_manager_; | 300 return low_energy_central_manager_; |
| 302 } | 301 } |
| 303 | 302 |
| 304 void BluetoothAdapterMac::AddDiscoverySession( | 303 void BluetoothAdapterMac::AddDiscoverySession( |
| 305 BluetoothDiscoveryFilter* discovery_filter, | 304 BluetoothDiscoveryFilter* discovery_filter, |
| 306 const base::Closure& callback, | 305 const base::Closure& callback, |
| 307 const DiscoverySessionErrorCallback& error_callback) { | 306 const DiscoverySessionErrorCallback& error_callback) { |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 // hash the probability of this occuring with 10,000 devices | 748 // hash the probability of this occuring with 10,000 devices |
| 750 // simultaneously present is 1e-6 (see | 749 // simultaneously present is 1e-6 (see |
| 751 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We | 750 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We |
| 752 // ignore the second device by returning. | 751 // ignore the second device by returning. |
| 753 return true; | 752 return true; |
| 754 } | 753 } |
| 755 return false; | 754 return false; |
| 756 } | 755 } |
| 757 | 756 |
| 758 } // namespace device | 757 } // namespace device |
| OLD | NEW |