diff options
Diffstat (limited to 'device/bluetooth')
-rw-r--r-- | device/bluetooth/bluetooth_adapter_chromeos.cc | 28 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_chromeos.h | 4 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.cc | 8 |
3 files changed, 28 insertions, 12 deletions
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc index a0b2681..c24341b 100644 --- a/device/bluetooth/bluetooth_adapter_chromeos.cc +++ b/device/bluetooth/bluetooth_adapter_chromeos.cc @@ -234,6 +234,14 @@ void BluetoothAdapterChromeOS::PoweredChanged(bool powered) { AdapterPoweredChanged(this, powered_)); } +void BluetoothAdapterChromeOS::NotifyDeviceChanged( + BluetoothDeviceChromeOS* device) { + DCHECK(device->adapter_ == this); + + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, + DeviceChanged(this, device)); +} + void BluetoothAdapterChromeOS::OnStartDiscovery( const base::Closure& callback, const ErrorCallback& error_callback, @@ -366,10 +374,9 @@ void BluetoothAdapterChromeOS::UpdateDevice( } device->Update(properties, true); - if (update_device) { - FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, - DeviceChanged(this, device)); - } else { + if (update_device) + NotifyDeviceChanged(device); + else { FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, DeviceAdded(this, device)); } @@ -428,8 +435,7 @@ void BluetoothAdapterChromeOS::DeviceRemoved( VLOG(1) << "Removed object path from device " << device->GetAddress(); device->RemoveObjectPath(); - FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, - DeviceChanged(this, device)); + NotifyDeviceChanged(device); } } } @@ -485,10 +491,9 @@ void BluetoothAdapterChromeOS::DeviceFound( device->SetDiscovered(true); device->Update(&properties, false); - if (update_device) { - FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, - DeviceChanged(this, device)); - } else { + if (update_device) + NotifyDeviceChanged(device); + else { FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, DeviceAdded(this, device)); } @@ -524,8 +529,7 @@ void BluetoothAdapterChromeOS::DeviceDisappeared( << " is no longer visible to the adapter"; device->SetDiscovered(false); - FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, - DeviceChanged(this, device)); + NotifyDeviceChanged(device); } } diff --git a/device/bluetooth/bluetooth_adapter_chromeos.h b/device/bluetooth/bluetooth_adapter_chromeos.h index c210a30..3f422b6 100644 --- a/device/bluetooth/bluetooth_adapter_chromeos.h +++ b/device/bluetooth/bluetooth_adapter_chromeos.h @@ -109,6 +109,10 @@ class BluetoothAdapterChromeOS // and directly using values obtained from properties. void PoweredChanged(bool powered); + // Notifies observers of a change in the device |device|. Used to signal + // changes initiated from the BluetoothDeviceChromeOS itself. + void NotifyDeviceChanged(BluetoothDeviceChromeOS* device); + // Called by BluetoothAdapterClient in response to the method call sent // by StartDiscovering(), |callback| and |error_callback| are the callbacks // provided to that method. diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index ce8cd9a..9eb3f4a 100644 --- a/device/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -148,6 +148,10 @@ void BluetoothDeviceChromeOS::Connect( // This is safe because Connect() and its callbacks are called in the same // thread. connecting_calls_++; + if (!connecting_) { + connecting_ = true; + adapter_->NotifyDeviceChanged(this); + } connecting_ = !!connecting_calls_; // Set the decrement to be issued when either callback is called. base::Closure wrapped_callback = base::Bind( @@ -535,18 +539,22 @@ void BluetoothDeviceChromeOS::OnGetServiceRecordsError( void BluetoothDeviceChromeOS::OnConnectCallbackCalled( const base::Closure& callback) { // Update the connecting status. + bool prev_connecting = connecting_; connecting_calls_--; connecting_ = !!connecting_calls_; callback.Run(); + if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this); } void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled( const ConnectErrorCallback& error_callback, enum ConnectErrorCode error_code) { // Update the connecting status. + bool prev_connecting = connecting_; connecting_calls_--; connecting_ = !!connecting_calls_; error_callback.Run(error_code); + if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this); } void BluetoothDeviceChromeOS::ConnectApplications( |