Commit 382720d8 authored by deymo@chromium.org's avatar deymo@chromium.org

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
parent 7cf7ccb7
...@@ -234,6 +234,14 @@ void BluetoothAdapterChromeOS::PoweredChanged(bool powered) { ...@@ -234,6 +234,14 @@ void BluetoothAdapterChromeOS::PoweredChanged(bool powered) {
AdapterPoweredChanged(this, 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( void BluetoothAdapterChromeOS::OnStartDiscovery(
const base::Closure& callback, const base::Closure& callback,
const ErrorCallback& error_callback, const ErrorCallback& error_callback,
...@@ -366,10 +374,9 @@ void BluetoothAdapterChromeOS::UpdateDevice( ...@@ -366,10 +374,9 @@ void BluetoothAdapterChromeOS::UpdateDevice(
} }
device->Update(properties, true); device->Update(properties, true);
if (update_device) { if (update_device)
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, NotifyDeviceChanged(device);
DeviceChanged(this, device)); else {
} else {
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
DeviceAdded(this, device)); DeviceAdded(this, device));
} }
...@@ -428,8 +435,7 @@ void BluetoothAdapterChromeOS::DeviceRemoved( ...@@ -428,8 +435,7 @@ void BluetoothAdapterChromeOS::DeviceRemoved(
VLOG(1) << "Removed object path from device " << device->GetAddress(); VLOG(1) << "Removed object path from device " << device->GetAddress();
device->RemoveObjectPath(); device->RemoveObjectPath();
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, NotifyDeviceChanged(device);
DeviceChanged(this, device));
} }
} }
} }
...@@ -485,10 +491,9 @@ void BluetoothAdapterChromeOS::DeviceFound( ...@@ -485,10 +491,9 @@ void BluetoothAdapterChromeOS::DeviceFound(
device->SetDiscovered(true); device->SetDiscovered(true);
device->Update(&properties, false); device->Update(&properties, false);
if (update_device) { if (update_device)
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, NotifyDeviceChanged(device);
DeviceChanged(this, device)); else {
} else {
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
DeviceAdded(this, device)); DeviceAdded(this, device));
} }
...@@ -524,8 +529,7 @@ void BluetoothAdapterChromeOS::DeviceDisappeared( ...@@ -524,8 +529,7 @@ void BluetoothAdapterChromeOS::DeviceDisappeared(
<< " is no longer visible to the adapter"; << " is no longer visible to the adapter";
device->SetDiscovered(false); device->SetDiscovered(false);
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, NotifyDeviceChanged(device);
DeviceChanged(this, device));
} }
} }
......
...@@ -109,6 +109,10 @@ class BluetoothAdapterChromeOS ...@@ -109,6 +109,10 @@ class BluetoothAdapterChromeOS
// and directly using values obtained from properties. // and directly using values obtained from properties.
void PoweredChanged(bool powered); 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 // Called by BluetoothAdapterClient in response to the method call sent
// by StartDiscovering(), |callback| and |error_callback| are the callbacks // by StartDiscovering(), |callback| and |error_callback| are the callbacks
// provided to that method. // provided to that method.
......
...@@ -148,6 +148,10 @@ void BluetoothDeviceChromeOS::Connect( ...@@ -148,6 +148,10 @@ void BluetoothDeviceChromeOS::Connect(
// This is safe because Connect() and its callbacks are called in the same // This is safe because Connect() and its callbacks are called in the same
// thread. // thread.
connecting_calls_++; connecting_calls_++;
if (!connecting_) {
connecting_ = true;
adapter_->NotifyDeviceChanged(this);
}
connecting_ = !!connecting_calls_; connecting_ = !!connecting_calls_;
// Set the decrement to be issued when either callback is called. // Set the decrement to be issued when either callback is called.
base::Closure wrapped_callback = base::Bind( base::Closure wrapped_callback = base::Bind(
...@@ -535,18 +539,22 @@ void BluetoothDeviceChromeOS::OnGetServiceRecordsError( ...@@ -535,18 +539,22 @@ void BluetoothDeviceChromeOS::OnGetServiceRecordsError(
void BluetoothDeviceChromeOS::OnConnectCallbackCalled( void BluetoothDeviceChromeOS::OnConnectCallbackCalled(
const base::Closure& callback) { const base::Closure& callback) {
// Update the connecting status. // Update the connecting status.
bool prev_connecting = connecting_;
connecting_calls_--; connecting_calls_--;
connecting_ = !!connecting_calls_; connecting_ = !!connecting_calls_;
callback.Run(); callback.Run();
if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this);
} }
void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled( void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled(
const ConnectErrorCallback& error_callback, const ConnectErrorCallback& error_callback,
enum ConnectErrorCode error_code) { enum ConnectErrorCode error_code) {
// Update the connecting status. // Update the connecting status.
bool prev_connecting = connecting_;
connecting_calls_--; connecting_calls_--;
connecting_ = !!connecting_calls_; connecting_ = !!connecting_calls_;
error_callback.Run(error_code); error_callback.Run(error_code);
if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this);
} }
void BluetoothDeviceChromeOS::ConnectApplications( void BluetoothDeviceChromeOS::ConnectApplications(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment