diff options
author | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-26 20:35:07 +0000 |
---|---|---|
committer | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-26 20:35:07 +0000 |
commit | 60625cb1fb7cf9f075048175cc4872f050011830 (patch) | |
tree | cca52456e42b5dee84172dedd3c70a2bb048128f /device | |
parent | dcdda4312c4e0524ba9d35ab5ae78c8f9f69689b (diff) | |
download | chromium_src-60625cb1fb7cf9f075048175cc4872f050011830.zip chromium_src-60625cb1fb7cf9f075048175cc4872f050011830.tar.gz chromium_src-60625cb1fb7cf9f075048175cc4872f050011830.tar.bz2 |
Bluetooth: Add a "connecting" property to BluetoothDevice.
The current BluetoothDevice doesn't not permit an external observer (like
an option handler) to know if there is a connection in process for a given
device. This fix adds the IsConnecting() method exposing if there's is a
connection going on for such device.
BUG=chromium-os:38411
TEST=Add a log message after each connecting_calls_ change to watch the value in the logs. Works as intended.
Review URL: https://chromiumcodereview.appspot.com/12335086
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184721 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_device.cc | 7 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device.h | 8 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.cc | 46 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.h | 12 |
4 files changed, 65 insertions, 8 deletions
diff --git a/device/bluetooth/bluetooth_device.cc b/device/bluetooth/bluetooth_device.cc index 5bad91a..a2249c5 100644 --- a/device/bluetooth/bluetooth_device.cc +++ b/device/bluetooth/bluetooth_device.cc @@ -23,7 +23,8 @@ BluetoothDevice::BluetoothDevice() visible_(false), bonded_(false), connected_(false), - connectable_(true) { + connectable_(true), + connecting_(false) { } BluetoothDevice::~BluetoothDevice() { @@ -180,6 +181,10 @@ bool BluetoothDevice::IsConnectable() const { return connectable_; } +bool BluetoothDevice::IsConnecting() const { + return connecting_; +} + bool BluetoothDevice::ProvidesServiceWithUUID( const std::string& uuid) const { std::string canonical_uuid = bluetooth_utils::CanonicalUuid(uuid); diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index e07806c..b7dc9e2 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -187,6 +187,11 @@ class BluetoothDevice { // adapter. This value is undefined for unbonded devices. virtual bool IsConnectable() const; + // Indicates whether there is a call to Connect() ongoing. For this attribute, + // we consider a call is ongoing if none of the callbacks passed to Connect() + // were called after the corresponding call to Connect(). + virtual bool IsConnecting() const; + // Returns the services (as UUID strings) that this device provides. typedef std::vector<std::string> ServiceList; virtual const ServiceList& GetServices() const = 0; @@ -341,6 +346,9 @@ class BluetoothDevice { // the adapter once paired. bool connectable_; + // Indicated whether the device is in a connecting status. + bool connecting_; + // The services (identified by UUIDs) that this device provides. ServiceList service_uuids_; diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index fdd7f06..d40e092 100644 --- a/device/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -52,6 +52,7 @@ BluetoothDeviceChromeOS::BluetoothDeviceChromeOS( adapter_(adapter), pairing_delegate_(NULL), connecting_applications_counter_(0), + connecting_calls_(0), service_records_loaded_(false), weak_ptr_factory_(this) { } @@ -114,9 +115,23 @@ void BluetoothDeviceChromeOS::Connect( PairingDelegate* pairing_delegate, const base::Closure& callback, const ConnectErrorCallback& error_callback) { + // This is safe because Connect() and its callbacks are called in the same + // thread. + connecting_calls_++; + connecting_ = !!connecting_calls_; + // Set the decrement to be issued when either callback is called. + base::Closure wrapped_callback = base::Bind( + &BluetoothDeviceChromeOS::OnConnectCallbackCalled, + weak_ptr_factory_.GetWeakPtr(), + callback); + ConnectErrorCallback wrapped_error_callback = base::Bind( + &BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled, + weak_ptr_factory_.GetWeakPtr(), + error_callback); + if (IsPaired() || IsBonded() || IsConnected()) { // Connection to already paired or connected device. - ConnectApplications(callback, error_callback); + ConnectApplications(wrapped_callback, wrapped_error_callback); } else if (!pairing_delegate) { // No pairing delegate supplied, initiate low-security connection only. @@ -125,11 +140,11 @@ void BluetoothDeviceChromeOS::Connect( address_, base::Bind(&BluetoothDeviceChromeOS::OnCreateDevice, weak_ptr_factory_.GetWeakPtr(), - callback, - error_callback), + wrapped_callback, + wrapped_error_callback), base::Bind(&BluetoothDeviceChromeOS::OnCreateDeviceError, weak_ptr_factory_.GetWeakPtr(), - error_callback)); + wrapped_error_callback)); } else { // Initiate high-security connection with pairing. DCHECK(!pairing_delegate_); @@ -163,11 +178,11 @@ void BluetoothDeviceChromeOS::Connect( bluetooth_agent::kDisplayYesNoCapability, base::Bind(&BluetoothDeviceChromeOS::OnCreateDevice, weak_ptr_factory_.GetWeakPtr(), - callback, - error_callback), + wrapped_callback, + wrapped_error_callback), base::Bind(&BluetoothDeviceChromeOS::OnCreateDeviceError, weak_ptr_factory_.GetWeakPtr(), - error_callback)); + wrapped_error_callback)); } } @@ -503,6 +518,23 @@ void BluetoothDeviceChromeOS::OnGetServiceRecordsError( } } +void BluetoothDeviceChromeOS::OnConnectCallbackCalled( + const base::Closure& callback) { + // Update the connecting status. + connecting_calls_--; + connecting_ = !!connecting_calls_; + callback.Run(); +} + +void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled( + const ConnectErrorCallback& error_callback, + enum ConnectErrorCode error_code) { + // Update the connecting status. + connecting_calls_--; + connecting_ = !!connecting_calls_; + error_callback.Run(error_code); +} + void BluetoothDeviceChromeOS::ConnectApplications( const base::Closure& callback, const ConnectErrorCallback& error_callback) { diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h index d93dfdc..824eadd 100644 --- a/device/bluetooth/bluetooth_device_chromeos.h +++ b/device/bluetooth/bluetooth_device_chromeos.h @@ -154,6 +154,15 @@ class BluetoothDeviceChromeOS const base::Closure& callback, const ConnectErrorCallback& error_callback); + // Called by Connect() when it succeeds. The |callback| is the value passed to + // the Connect() call. + void OnConnectCallbackCalled(const base::Closure& callback); + + // Called by Connect() when it fails. The |error_callback| is the value passed + // to the Connect() call. + void OnConnectErrorCallbackCalled(const ConnectErrorCallback& error_callback, + enum ConnectErrorCode error_code); + // Connect application-level protocols of the device to the system, called // on a successful connection or to reconnect to a device that is already // paired or previously connected. |error_callback| is called on failure. @@ -389,6 +398,9 @@ class BluetoothDeviceChromeOS // Used to keep track of pending application connection requests. int connecting_applications_counter_; + // Used to keep track of ongoing calls to Connect(). + int connecting_calls_; + // A service records cache. ServiceRecordList service_records_; |