Chromium Code Reviews| Index: chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc |
| diff --git a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc |
| index 0be4fc9d14de566cb30d67e0fdbac47926a83358..c61d3bb6554c8a57d4860175c0b5e745b23378f3 100644 |
| --- a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc |
| +++ b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc |
| @@ -55,20 +55,13 @@ const int kInvalidEntered = 0xFFFF; |
| namespace chromeos { |
| namespace options { |
| -BluetoothOptionsHandler::BluetoothOptionsHandler() : |
| - discovering_(false), |
| - pairing_device_passkey_(1000000), |
| - pairing_device_entered_(kInvalidEntered), |
| - weak_ptr_factory_(this) { |
| +BluetoothOptionsHandler::BluetoothOptionsHandler() |
| + : pairing_device_passkey_(1000000), |
| + pairing_device_entered_(kInvalidEntered), |
| + weak_ptr_factory_(this) { |
| } |
| BluetoothOptionsHandler::~BluetoothOptionsHandler() { |
| - if (discovering_) { |
| - adapter_->StopDiscovering( |
| - base::Bind(&base::DoNothing), |
| - base::Bind(&base::DoNothing)); |
| - discovering_ = false; |
| - } |
| if (adapter_.get()) |
| adapter_->RemoveObserver(this); |
| } |
| @@ -235,13 +228,20 @@ void BluetoothOptionsHandler::EnableChangeError() { |
| void BluetoothOptionsHandler::FindDevicesCallback( |
| const base::ListValue* args) { |
| - if (!discovering_) { |
| - discovering_ = true; |
| - adapter_->StartDiscovering( |
| - base::Bind(&base::DoNothing), |
| - base::Bind(&BluetoothOptionsHandler::FindDevicesError, |
| - weak_ptr_factory_.GetWeakPtr())); |
| + if (discovery_session_.get() && discovery_session_->IsActive()) { |
| + VLOG(1) << "Already have an active discovery session."; |
| + return; |
| } |
| + adapter_->StartDiscoverySession( |
| + base::Bind(&BluetoothOptionsHandler::OnStartDiscoverySession, |
| + weak_ptr_factory_.GetWeakPtr()), |
| + base::Bind(&BluetoothOptionsHandler::FindDevicesError, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void BluetoothOptionsHandler::OnStartDiscoverySession( |
| + scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
| + discovery_session_ = discovery_session.Pass(); |
|
keybuk
2014/02/28 21:29:28
Doesn't this need the same logic as Aura, what if
armansito
2014/02/28 22:52:02
It certainly does. Done.
|
| } |
| void BluetoothOptionsHandler::FindDevicesError() { |
| @@ -402,13 +402,14 @@ void BluetoothOptionsHandler::ForgetError(const std::string& address) { |
| void BluetoothOptionsHandler::StopDiscoveryCallback( |
| const base::ListValue* args) { |
| - if (discovering_) { |
| - adapter_->StopDiscovering( |
| - base::Bind(&base::DoNothing), |
| - base::Bind(&BluetoothOptionsHandler::StopDiscoveryError, |
| - weak_ptr_factory_.GetWeakPtr())); |
| - discovering_ = false; |
| + if (!discovery_session_.get() || !discovery_session_->IsActive()) { |
| + VLOG(1) << "No active discovery session."; |
| + return; |
| } |
| + discovery_session_->Stop( |
| + base::Bind(&base::DoNothing), |
| + base::Bind(&BluetoothOptionsHandler::StopDiscoveryError, |
| + weak_ptr_factory_.GetWeakPtr())); |
| } |
| void BluetoothOptionsHandler::StopDiscoveryError() { |