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

Unified Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 2853933002: bluetooth: macOS: Support for extra didConnectPeripheral event from macOS. (Closed)
Patch Set: Adding Android bug Created 3 years, 8 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
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 20694e4953b97d7ca5d4edc882a0a4b0aab06864..fb0e4f42af40d7d44398296ca4d41120c13b2569 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 {
@@ -186,6 +191,18 @@ void BluetoothLowEnergyDeviceMac::DisconnectGatt() {
GetMacAdapter()->DisconnectGatt(this);
}
+void BluetoothLowEnergyDeviceMac::DidConnectGatt() {
+ VLOG(1) << *this << ": Gatt connected.";
+ bool should_discover_services = !connected_;
+ connected_ = true;
+ BluetoothDeviceMac::DidConnectGatt();
+ if (should_discover_services) {
+ DiscoverPrimaryServices();
+ } else {
+ VLOG(1) << *this << ": Already connected, no need to discover services.";
+ }
+}
+
void BluetoothLowEnergyDeviceMac::DidDiscoverPrimaryServices(NSError* error) {
--discovery_pending_count_;
if (discovery_pending_count_ < 0) {
@@ -435,6 +452,7 @@ BluetoothLowEnergyDeviceMac::GetBluetoothRemoteGattDescriptor(
}
void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(NSError* error) {
+ connected_ = false;
VLOG(1) << *this << ": Disconnected from peripheral.";
if (error) {
VLOG(1) << *this
@@ -468,8 +486,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

Powered by Google App Engine
This is Rietveld 408576698