diff options
author | bryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-11 19:08:36 +0000 |
---|---|---|
committer | bryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-11 19:08:36 +0000 |
commit | e325d0c2b842404eef887faa5bb894270b8e7b0c (patch) | |
tree | 0c3bd92100d128cff076ba87e712b9b4cd64f7de | |
parent | 8825864e7915f914c7d34e21e721d7a3a2305126 (diff) | |
download | chromium_src-e325d0c2b842404eef887faa5bb894270b8e7b0c.zip chromium_src-e325d0c2b842404eef887faa5bb894270b8e7b0c.tar.gz chromium_src-e325d0c2b842404eef887faa5bb894270b8e7b0c.tar.bz2 |
Add VoidResultCallback to BluetoothAdapter.
This allows users of BluetoothAdapter to know when actions are
completed.
TEST=compiles
BUG=none
R=keybuk@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10537085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141451 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 56 insertions, 24 deletions
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc b/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc index 2ffd17f..5088b00 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc +++ b/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc @@ -149,18 +149,25 @@ bool BluetoothAdapter::IsPowered() const { return powered_; } -void BluetoothAdapter::SetPowered(bool powered, ErrorCallback callback) { +void BluetoothAdapter::SetPowered(bool powered, + const base::Closure& callback, + const ErrorCallback& error_callback) { DBusThreadManager::Get()->GetBluetoothAdapterClient()-> GetProperties(object_path_)->powered.Set( powered, base::Bind(&BluetoothAdapter::OnSetPowered, weak_ptr_factory_.GetWeakPtr(), - callback)); + callback, + error_callback)); } -void BluetoothAdapter::OnSetPowered(ErrorCallback callback, bool success) { - if (!success) +void BluetoothAdapter::OnSetPowered(const base::Closure& callback, + const ErrorCallback& error_callback, + bool success) { + if (success) callback.Run(); + else + error_callback.Run(); } void BluetoothAdapter::PoweredChanged(bool powered) { @@ -178,23 +185,27 @@ bool BluetoothAdapter::IsDiscovering() const { } void BluetoothAdapter::SetDiscovering(bool discovering, - ErrorCallback callback) { + const base::Closure& callback, + const ErrorCallback& error_callback) { if (discovering) { DBusThreadManager::Get()->GetBluetoothAdapterClient()-> StartDiscovery(object_path_, base::Bind(&BluetoothAdapter::OnStartDiscovery, weak_ptr_factory_.GetWeakPtr(), - callback)); + callback, + error_callback)); } else { DBusThreadManager::Get()->GetBluetoothAdapterClient()-> StopDiscovery(object_path_, base::Bind(&BluetoothAdapter::OnStopDiscovery, weak_ptr_factory_.GetWeakPtr(), - callback)); + callback, + error_callback)); } } -void BluetoothAdapter::OnStartDiscovery(ErrorCallback callback, +void BluetoothAdapter::OnStartDiscovery(const base::Closure& callback, + const ErrorCallback& error_callback, const dbus::ObjectPath& adapter_path, bool success) { if (success) { @@ -202,24 +213,26 @@ void BluetoothAdapter::OnStartDiscovery(ErrorCallback callback, // Clear devices found in previous discovery attempts ClearDiscoveredDevices(); + callback.Run(); } else { // TODO(keybuk): in future, don't run the callback if the error was just // that we were already discovering. - callback.Run(); + error_callback.Run(); } } -void BluetoothAdapter::OnStopDiscovery(ErrorCallback callback, +void BluetoothAdapter::OnStopDiscovery(const base::Closure& callback, + const ErrorCallback& error_callback, const dbus::ObjectPath& adapter_path, bool success) { if (success) { DVLOG(1) << object_path_.value() << ": stopped discovery."; - + callback.Run(); // Leave found devices available for perusing. } else { // TODO(keybuk): in future, don't run the callback if the error was just // that we weren't discovering. - callback.Run(); + error_callback.Run(); } } diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.h b/chrome/browser/chromeos/bluetooth/bluetooth_adapter.h index e61768a..599a221 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.h +++ b/chrome/browser/chromeos/bluetooth/bluetooth_adapter.h @@ -102,10 +102,12 @@ class BluetoothAdapter : private BluetoothManagerClient::Observer, // Indicates whether the adapter radio is powered. virtual bool IsPowered() const; - // Requests a change to the adapter radio power, setting |powered| to - // true will turn on the radio and false will turn it off. |callback| - // will only be called if the request fails. - void SetPowered(bool powered, ErrorCallback callback); + // Requests a change to the adapter radio power, setting |powered| to true + // will turn on the radio and false will turn it off. On success, callback + // will be called. On failure, |error_callback| will be called. + void SetPowered(bool powered, + const base::Closure& callback, + const ErrorCallback& error_callback); // Indicates whether the adapter is currently discovering new devices, // note that a typical discovery process has phases of this being true @@ -114,9 +116,11 @@ class BluetoothAdapter : private BluetoothManagerClient::Observer, bool IsDiscovering() const; // Requests that the adapter either begin discovering new devices when - // |discovering| is true, or cease any discovery when false. |callback| - // will only be called if the request fails. - void SetDiscovering(bool discovering, ErrorCallback callback); + // |discovering| is true, or cease any discovery when false. On success, + // callback will be called. On failure, |error_callback| will be called. + void SetDiscovering(bool discovering, + const base::Closure& callback, + const ErrorCallback& error_callback); // Requests the list of devices from the adapter, all are returned // including those currently connected and those paired. Use the @@ -183,7 +187,10 @@ class BluetoothAdapter : private BluetoothManagerClient::Observer, void RemoveAdapter(); // Called by dbus:: in response to the method call send by SetPowered(). - void OnSetPowered(ErrorCallback callback, bool success); + // |callback| and |error_callback| are the callbacks passed to SetPowered(). + void OnSetPowered(const base::Closure& callback, + const ErrorCallback& error_callback, + bool success); // Updates the tracked state of the adapter's radio power to |powered| // and notifies observers. Called on receipt of a property changed signal, @@ -191,10 +198,16 @@ class BluetoothAdapter : private BluetoothManagerClient::Observer, void PoweredChanged(bool powered); // Called by dbus:: in response to the method calls send by SetDiscovering(). - void OnStartDiscovery(ErrorCallback callback, - const dbus::ObjectPath& adapter_path, bool success); - void OnStopDiscovery(ErrorCallback callback, - const dbus::ObjectPath& adapter_path, bool success); + // |callback| and |error_callback| are the callbacks passed to + // SetDiscovering(). + void OnStartDiscovery(const base::Closure& callback, + const ErrorCallback& error_callback, + const dbus::ObjectPath& adapter_path, + bool success); + void OnStopDiscovery(const base::Closure& callback, + const ErrorCallback& error_callback, + const dbus::ObjectPath& adapter_path, + bool success); // Updates the tracked state of the adapter's discovering state to // |discovering| and notifies observers. Called on receipt of a property diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index dcf5190..9ef607a 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -20,6 +20,7 @@ #include "ash/system/tray_caps_lock.h" #include "ash/system/user/update_observer.h" #include "ash/system/user/user_observer.h" +#include "base/callback.h" #include "base/chromeos/chromeos_version.h" #include "base/logging.h" #include "base/memory/weak_ptr.h" @@ -679,6 +680,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, virtual void ToggleBluetooth() OVERRIDE { bluetooth_adapter_->SetPowered(!bluetooth_adapter_->IsPowered(), + base::Closure(), base::Bind(&BluetoothPowerFailure)); } 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 d4f3a76..9ddb6fcf 100644 --- a/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc +++ b/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.h" #include "base/bind.h" +#include "base/callback.h" #include "base/command_line.h" #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" @@ -185,6 +186,7 @@ void BluetoothOptionsHandler::EnableChangeCallback( args->GetBoolean(0, &bluetooth_enabled); adapter_->SetPowered(bluetooth_enabled, + base::Closure(), base::Bind(&BluetoothOptionsHandler::EnableChangeError, weak_ptr_factory_.GetWeakPtr())); } @@ -198,6 +200,7 @@ void BluetoothOptionsHandler::FindDevicesCallback( const ListValue* args) { adapter_->SetDiscovering( true, + base::Closure(), base::Bind(&BluetoothOptionsHandler::FindDevicesError, weak_ptr_factory_.GetWeakPtr())); } @@ -304,6 +307,7 @@ void BluetoothOptionsHandler::StopDiscoveryCallback( const ListValue* args) { adapter_->SetDiscovering( false, + base::Closure(), base::Bind(&BluetoothOptionsHandler::StopDiscoveryError, weak_ptr_factory_.GetWeakPtr())); } |