diff options
author | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-17 21:41:32 +0000 |
---|---|---|
committer | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-17 21:41:32 +0000 |
commit | 86dd17c3a84074f250d91ccff80d776ddba134ee (patch) | |
tree | 6ec2ceb0c8747b8a9dfa27bc2a851747a714e602 | |
parent | b7a76937484affc84d97d0ff2f4ca5e1ed0476d4 (diff) | |
download | chromium_src-86dd17c3a84074f250d91ccff80d776ddba134ee.zip chromium_src-86dd17c3a84074f250d91ccff80d776ddba134ee.tar.gz chromium_src-86dd17c3a84074f250d91ccff80d776ddba134ee.tar.bz2 |
bluetooth: use separate error callbacks, include address
For each command we issue use a different error callback, and for those
we issue on a device, include the device address in the callback
arguments.
This makes it easier to display appropriate errors in the UI.
BUG=none
TEST=emerge chromeos-chrome
Change-Id: I04da3f1bd0ddb2bbd20fd564a3c0b3a4b5f9de4d
R=jhawkins@chromium.org
Review URL: http://codereview.chromium.org/9705079
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127375 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc | 69 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.h | 26 |
2 files changed, 71 insertions, 24 deletions
diff --git a/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc b/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc index feec84b..dd45c75 100644 --- a/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc +++ b/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc @@ -197,15 +197,26 @@ void BluetoothOptionsHandler::EnableChangeCallback( args->GetBoolean(0, &bluetooth_enabled); adapter_->SetPowered(bluetooth_enabled, - base::Bind(&BluetoothOptionsHandler::ErrorCallback, + base::Bind(&BluetoothOptionsHandler::EnableChangeError, weak_ptr_factory_.GetWeakPtr())); } +void BluetoothOptionsHandler::EnableChangeError() { + // TODO(kevers): display an error in the UI. + DVLOG(1) << "Failed to change power state."; +} + void BluetoothOptionsHandler::FindDevicesCallback( const ListValue* args) { - adapter_->SetDiscovering(true, - base::Bind(&BluetoothOptionsHandler::ErrorCallback, - weak_ptr_factory_.GetWeakPtr())); + adapter_->SetDiscovering( + true, + base::Bind(&BluetoothOptionsHandler::FindDevicesError, + weak_ptr_factory_.GetWeakPtr())); +} + +void BluetoothOptionsHandler::FindDevicesError() { + // TODO(kevers): display an error in the UI. + DVLOG(1) << "Failed to start discovery."; } void BluetoothOptionsHandler::UpdateDeviceCallback( @@ -234,8 +245,9 @@ void BluetoothOptionsHandler::UpdateDeviceCallback( // Connection request. DVLOG(1) << "Connect: " << address; device->Connect( - this, base::Bind(&BluetoothOptionsHandler::ErrorCallback, - weak_ptr_factory_.GetWeakPtr())); + this, base::Bind(&BluetoothOptionsHandler::ConnectError, + weak_ptr_factory_.GetWeakPtr(), + device->address())); } } else if (command == kCancelCommand) { // Cancel pairing. @@ -252,23 +264,46 @@ void BluetoothOptionsHandler::UpdateDeviceCallback( } else if (command == kDisconnectCommand) { // Disconnect from device. DVLOG(1) << "Disconnect device: " << address; - device->Disconnect(base::Bind(&BluetoothOptionsHandler::ErrorCallback, - weak_ptr_factory_.GetWeakPtr())); + device->Disconnect(base::Bind(&BluetoothOptionsHandler::DisconnectError, + weak_ptr_factory_.GetWeakPtr(), + device->address())); } else if (command == kForgetCommand) { // Disconnect from device and delete pairing information. DVLOG(1) << "Forget device: " << address; - device->Forget(base::Bind(&BluetoothOptionsHandler::ErrorCallback, - weak_ptr_factory_.GetWeakPtr())); + device->Forget(base::Bind(&BluetoothOptionsHandler::ForgetError, + weak_ptr_factory_.GetWeakPtr(), + device->address())); } else { LOG(WARNING) << "Unknown updateBluetoothDevice command: " << command; } } +void BluetoothOptionsHandler::ConnectError(const std::string& address) { + // TODO(kevers): display an error in the UI. + DVLOG(1) << "Failed to connect to device: " << address; +} + +void BluetoothOptionsHandler::DisconnectError(const std::string& address) { + // TODO(kevers): display an error in the UI. + DVLOG(1) << "Failed to disconnect from device: " << address; +} + +void BluetoothOptionsHandler::ForgetError(const std::string& address) { + // TODO(kevers): display an error in the UI. + DVLOG(1) << "Failed to disconnect and unpair device: " << address; +} + void BluetoothOptionsHandler::StopDiscoveryCallback( const ListValue* args) { - adapter_->SetDiscovering(false, - base::Bind(&BluetoothOptionsHandler::ErrorCallback, - weak_ptr_factory_.GetWeakPtr())); + adapter_->SetDiscovering( + false, + base::Bind(&BluetoothOptionsHandler::StopDiscoveryError, + weak_ptr_factory_.GetWeakPtr())); +} + +void BluetoothOptionsHandler::StopDiscoveryError() { + // TODO(kevers): display an error in the UI. + DVLOG(1) << "Failed to stop discovery."; } void BluetoothOptionsHandler::GetPairedDevicesCallback( @@ -386,13 +421,5 @@ void BluetoothOptionsHandler::DeviceRemoved(BluetoothAdapter* adapter, address); } -void BluetoothOptionsHandler::ErrorCallback() { - // TODO(keybuk): we don't get any form of error response from dbus:: - // yet, other than an error occurred. I'm going to fix that, then this - // gets replaced by genuine error information from the method which we - // can act on, rather than a debug log statement. - DVLOG(1) << "Failed."; -} - } // namespace options2 } // namespace chromeos diff --git a/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.h b/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.h index b8aec77..c18f9a1 100644 --- a/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.h +++ b/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.h @@ -139,9 +139,29 @@ class BluetoothOptionsHandler : public OptionsPageUIHandler, BluetoothDevice* device) OVERRIDE; private: - // Called by BluetoothAdapter in response to our method calls in case of - // error. - void ErrorCallback(); + // Called by BluetoothAdapter in response to a failure to change the + // power status of the adapter. + void EnableChangeError(); + + // Called by BluetoothAdapter in response to a failure to set the adapter + // into discovery mode. + void FindDevicesError(); + + // Called by BluetoothAdapter in response to a failure to remove the adapter + // from discovery mode. + void StopDiscoveryError(); + + // Called by BluetoothDevice in response to a failure to connect to the + // device with bluetooth address |address|. + void ConnectError(const std::string& address); + + // Called by BluetoothDevice in response to a failure to disconnect the + // device with bluetooth address |address|. + void DisconnectError(const std::string& address); + + // Called by BluetoothDevice in response to a failure to disconnect and + // unpair the device with bluetooth address |address|. + void ForgetError(const std::string& address); // Called on completion of initialization of the settings page to update // the Bluetooth controls. |