bluetooth: Remove indicator only when there are no more devices connected
Before, if multiple devices were connected and we disconnected from one
we would remove the indicator even though a device could still be connected.
BUG=599281
Review URL: https://codereview.chromium.org/1848663002
Cr-Commit-Position: refs/heads/master@{#385942}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 1a345ab..a95aa74 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -359,7 +359,7 @@
accessibility_mode_(
BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
audio_stream_monitor_(this),
- bluetooth_device_connected_(false),
+ bluetooth_connected_device_count_(0),
virtual_keyboard_requested_(false),
page_scale_factor_is_one_(true),
text_input_state_(new TextInputState()),
@@ -1124,14 +1124,25 @@
NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
}
-bool WebContentsImpl::IsBluetoothDeviceConnected() const {
- return bluetooth_device_connected_;
+void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
+ // Notify for UI updates if the state changes.
+ bluetooth_connected_device_count_++;
+ if (bluetooth_connected_device_count_ == 1) {
+ NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
+ }
}
-void WebContentsImpl::SetBluetoothDeviceConnected(bool connected) {
- bluetooth_device_connected_ = connected;
- // Notification for UI updates in response to the connected device.
- NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
+void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
+ // Notify for UI updates if the state changes.
+ DCHECK(bluetooth_connected_device_count_ != 0);
+ bluetooth_connected_device_count_--;
+ if (bluetooth_connected_device_count_ == 0) {
+ NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
+ }
+}
+
+bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
+ return bluetooth_connected_device_count_ > 0;
}
bool WebContentsImpl::IsCrashed() const {
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
index 581f346..75eb253 100644
--- a/content/browser/web_contents/web_contents_impl.h
+++ b/content/browser/web_contents/web_contents_impl.h
@@ -277,8 +277,9 @@
int GetCapturerCount() const override;
bool IsAudioMuted() const override;
void SetAudioMuted(bool mute) override;
- bool IsBluetoothDeviceConnected() const override;
- void SetBluetoothDeviceConnected(bool connected) override;
+ void IncrementBluetoothConnectedDeviceCount();
+ void DecrementBluetoothConnectedDeviceCount();
+ bool IsConnectedToBluetoothDevice() const override;
bool IsCrashed() const override;
void SetIsCrashed(base::TerminationStatus status, int error_code) override;
base::TerminationStatus GetCrashedStatus() const override;
@@ -1313,7 +1314,7 @@
// Created on-demand to mute all audio output from this WebContents.
scoped_ptr<WebContentsAudioMuter> audio_muter_;
- bool bluetooth_device_connected_;
+ size_t bluetooth_connected_device_count_;
bool virtual_keyboard_requested_;