Index: chrome/browser/ui/ash/system_tray_delegate_chromeos.cc |
diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc |
index 19fbfdbb9fe0e3aa2918f076fd759a8c8c2781ca..70a644acd3428968927146d22f4f0b5382ccc74a 100644 |
--- a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc |
+++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc |
@@ -250,6 +250,7 @@ SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS() |
screen_locked_(false), |
have_session_start_time_(false), |
have_session_length_limit_(false), |
+ bluetooth_should_discover_(false), |
volume_control_delegate_(new VolumeController()), |
device_settings_observer_(CrosSettings::Get()->AddSettingsObserver( |
kSystemUse24HourClock, |
@@ -702,12 +703,28 @@ void SystemTrayDelegateChromeOS::GetAvailableBluetoothDevices( |
} |
void SystemTrayDelegateChromeOS::BluetoothStartDiscovering() { |
- bluetooth_adapter_->StartDiscovering( |
- base::Bind(&base::DoNothing), base::Bind(&BluetoothSetDiscoveringError)); |
+ if (bluetooth_discovery_session_.get() && |
+ bluetooth_discovery_session_->IsActive()) { |
+ LOG(WARNING) << "Already have active Bluetooth device discovery session."; |
+ return; |
+ } |
+ VLOG(1) << "Requesting new Bluetooth device discovery session."; |
+ bluetooth_should_discover_ = true; |
+ bluetooth_adapter_->StartDiscoverySession( |
+ base::Bind(&SystemTrayDelegateChromeOS::OnStartDiscoverySession, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ base::Bind(&BluetoothSetDiscoveringError)); |
} |
void SystemTrayDelegateChromeOS::BluetoothStopDiscovering() { |
- bluetooth_adapter_->StopDiscovering( |
+ bluetooth_should_discover_ = false; |
+ if (!bluetooth_discovery_session_.get() || |
+ !bluetooth_discovery_session_->IsActive()) { |
+ LOG(WARNING) << "No active Bluetooth device discovery session."; |
+ return; |
+ } |
+ VLOG(1) << "Stopping Bluetooth device discovery session."; |
+ bluetooth_discovery_session_->Stop( |
base::Bind(&base::DoNothing), base::Bind(&BluetoothSetDiscoveringError)); |
} |
@@ -1279,6 +1296,17 @@ void SystemTrayDelegateChromeOS::DeviceRemoved( |
GetSystemTrayNotifier()->NotifyRefreshBluetooth(); |
} |
+void SystemTrayDelegateChromeOS::OnStartDiscoverySession( |
+ scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
+ // If the discovery session was returned after a request to stop discovery |
+ // (e.g. the user dismissed the Bluetooth detailed view before the call |
+ // returned), don't claim the discovery session and let it clean up. |
+ if (!bluetooth_should_discover_) |
+ return; |
+ VLOG(1) << "Claiming new Bluetooth device discovery session."; |
+ bluetooth_discovery_session_ = discovery_session.Pass(); |
+} |
+ |
// Overridden from SystemKeyEventListener::CapsLockObserver. |
void SystemTrayDelegateChromeOS::OnCapsLockChange(bool enabled) { |
bool search_mapped_to_caps_lock = false; |