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

Unified Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 2853933002: bluetooth: macOS: Support for extra didConnectPeripheral event from macOS. (Closed)
Patch Set: merge Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_device_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_low_energy_device_mac.mm
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.mm b/device/bluetooth/bluetooth_low_energy_device_mac.mm
index 8e624e2d0386b2d52179e57af90c820fa3284558..b8afdfdaf7db96a49a18e6a0305b09780214b20e 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -28,6 +28,7 @@ BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
CBPeripheral* peripheral)
: BluetoothDeviceMac(adapter),
peripheral_(peripheral, base::scoped_policy::RETAIN),
+ connected_(false),
discovery_pending_count_(0) {
DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
DCHECK(peripheral_.get());
@@ -96,7 +97,11 @@ bool BluetoothLowEnergyDeviceMac::IsConnected() const {
}
bool BluetoothLowEnergyDeviceMac::IsGattConnected() const {
- return ([peripheral_ state] == CBPeripheralStateConnected);
+ // |connected_| can be false while |[peripheral_ state]| is
+ // |CBPeripheralStateConnected|. This happens
+ // BluetoothAdapterMac::DidConnectPeripheral() is called and
+ // BluetoothLowEnergyDeviceMac::DidConnectGatt() has not been called yet.
+ return connected_;
}
bool BluetoothLowEnergyDeviceMac::IsConnectable() const {
@@ -388,6 +393,20 @@ std::string BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(
return BluetoothDevice::CanonicalizeAddress(hash);
}
+void BluetoothLowEnergyDeviceMac::DidConnectPeripheral() {
+ VLOG(1) << *this << ": GATT connected.";
+ if (!connected_) {
+ connected_ = true;
+ DidConnectGatt();
+ DiscoverPrimaryServices();
+ } else {
+ // -[<CBCentralManagerDelegate> centralManager:didConnectPeripheral:] can be
+ // called twice because of a macOS bug. This second call should be ignored.
+ // See crbug.com/681414.
+ VLOG(1) << *this << ": Already connected, ignoring event.";
+ }
+}
+
void BluetoothLowEnergyDeviceMac::DiscoverPrimaryServices() {
VLOG(1) << *this << ": DiscoverPrimaryServices, pending count "
<< discovery_pending_count_;
@@ -452,6 +471,7 @@ BluetoothLowEnergyDeviceMac::GetBluetoothRemoteGattDescriptor(
}
void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(NSError* error) {
+ connected_ = false;
VLOG(1) << *this << ": Disconnected from peripheral.";
if (error) {
VLOG(1) << *this
@@ -485,8 +505,10 @@ std::ostream& operator<<(std::ostream& out,
// TODO(crbug.com/703878): Should use
// BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead.
base::Optional<std::string> name = device.GetName();
- const char* name_cstr = name ? name->c_str() : "";
+ const char* is_gatt_connected =
+ device.IsGattConnected() ? "GATT connected" : "GATT disconnected";
return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/"
- << &device << ", \"" << name_cstr << "\">";
+ << &device << ", " << is_gatt_connected << ", \""
+ << name.value_or("Unnamed device") << "\">";
}
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_device_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698