Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Unified Diff: chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc

Issue 2245603003: Add signal strength indicator icon to WebBluetooth chooser on non-Mac desktops (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed unused include file Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc
diff --git a/chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc b/chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc
index 49dccb9597a74dc264ad4d833939de0df9a7e93d..6b97053831611135ba6de1afb632d6ca138c8339 100644
--- a/chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc
+++ b/chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc
@@ -26,6 +26,27 @@ Browser* GetBrowser() {
return browser_displayer.browser();
}
+// Anything worse than or equal to this will show 0 bars.
+const int kMinRSSI = -100;
+// Anything better than or equal to this will show the maximum bars.
+const int kMaxRSSI = -55;
+// Number of RSSI levels used in the signal strength icon.
+const int kNumLevels = 5;
+
+// Received Signal Strength Indicator (RSSI) is a measurement of the power
+// present in a received radio signal.
+int CalculateSignalLevel(int8_t rssi) {
+ if (rssi <= kMinRSSI)
+ return 0;
+
+ if (rssi >= kMaxRSSI)
+ return kNumLevels - 1;
+
+ double input_range = kMaxRSSI - kMinRSSI;
+ double output_range = kNumLevels - 1;
+ return static_cast<int>((rssi - kMinRSSI) * output_range / input_range);
+}
+
} // namespace
BluetoothChooserController::BluetoothChooserController(
@@ -40,6 +61,10 @@ BluetoothChooserController::BluetoothChooserController(
BluetoothChooserController::~BluetoothChooserController() {}
+bool BluetoothChooserController::ShouldShowIconBeforeText() const {
+ return true;
+}
+
base::string16 BluetoothChooserController::GetNoOptionsText() const {
return no_devices_text_;
}
@@ -50,12 +75,16 @@ base::string16 BluetoothChooserController::GetOkButtonLabel() const {
}
size_t BluetoothChooserController::NumOptions() const {
- return device_ids_.size();
+ return devices_.size();
+}
+
+int BluetoothChooserController::GetSignalStrengthLevel(size_t index) const {
+ return devices_[index].signal_strength_level;
}
base::string16 BluetoothChooserController::GetOption(size_t index) const {
- DCHECK_LT(index, device_ids_.size());
- const std::string& device_id = device_ids_[index];
+ DCHECK_LT(index, devices_.size());
+ const std::string& device_id = devices_[index].id;
const auto& device_name_it = device_id_to_name_map_.find(device_id);
DCHECK(device_name_it != device_id_to_name_map_.end());
const auto& it = device_name_map_.find(device_name_it->second);
@@ -85,9 +114,9 @@ void BluetoothChooserController::Select(size_t index) {
BLUETOOTH_CHOOSER_EVENT_HANDLER_INVALID);
return;
}
- DCHECK_LT(index, device_ids_.size());
+ DCHECK_LT(index, devices_.size());
event_handler_.Run(content::BluetoothChooser::Event::SELECTED,
- device_ids_[index]);
+ devices_[index].id);
}
void BluetoothChooserController::Cancel() {
@@ -179,10 +208,11 @@ void BluetoothChooserController::AddOrUpdateDevice(
return;
}
- device_ids_.push_back(device_id);
+ int level = rssi ? CalculateSignalLevel(*rssi) : -1;
ortuno 2016/08/16 15:39:18 Is it possible to update the icon?
juncai 2016/08/16 17:49:52 Yes, I commented at: https://codereview.chromium.o
+ devices_.push_back({device_id, level});
++device_name_map_[device_name];
if (view())
- view()->OnOptionAdded(device_ids_.size() - 1);
+ view()->OnOptionAdded(devices_.size() - 1);
}
void BluetoothChooserController::RemoveDevice(const std::string& device_id) {
@@ -191,13 +221,13 @@ void BluetoothChooserController::RemoveDevice(const std::string& device_id) {
return;
size_t index = 0;
- for (const auto& saved_device_id : device_ids_) {
- if (saved_device_id != device_id) {
+ for (const auto& saved_device_info : devices_) {
+ if (saved_device_info.id != device_id) {
++index;
continue;
}
- device_ids_.erase(device_ids_.begin() + index);
+ devices_.erase(devices_.begin() + index);
const auto& it = device_name_map_.find(name_it->second);
DCHECK(it != device_name_map_.end());
@@ -219,7 +249,7 @@ void BluetoothChooserController::ResetEventHandler() {
}
void BluetoothChooserController::ClearAllDevices() {
- device_ids_.clear();
+ devices_.clear();
device_id_to_name_map_.clear();
device_name_map_.clear();
}

Powered by Google App Engine
This is Rietveld 408576698