diff options
author | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-20 03:11:10 +0000 |
---|---|---|
committer | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-20 03:11:10 +0000 |
commit | 382720d8d5d1cf85b56a4243af59f5115b127940 (patch) | |
tree | 866fa4b58b904bbc3c1b9d68a0023cea7f03f9c5 /device/bluetooth | |
parent | 7cf7ccb7750a8bb104fe9eb6fce3312871346237 (diff) | |
download | chromium_src-382720d8d5d1cf85b56a4243af59f5115b127940.zip chromium_src-382720d8d5d1cf85b56a4243af59f5115b127940.tar.gz chromium_src-382720d8d5d1cf85b56a4243af59f5115b127940.tar.bz2 |
Bluetooth: Send UI notifications when the connecting status changes.
This fix sends a DeviceChanged notification to all the
BluetoothAdapter::Observer when a BluetoothDevice::Connect makes the
BluetoothDevice::IsConnecting property change.
BUG=231985
TEST=None
Review URL: https://chromiumcodereview.appspot.com/12374062
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195375 0039d316-1c4b-4281-b951-d872f2087c98
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( |