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

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: added signal strength indicator icon to WebBluetooth chooser 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..9897962925e354e07c03fcab8f7d854d8484eb50 100644
--- a/chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc
+++ b/chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc
@@ -26,6 +26,26 @@ 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;
+
+int CalculateSignalLevel(int rssi) {
msw 2016/08/12 23:08:48 nit: add a comment, explain the rssi acronym (I ha
juncai 2016/08/15 21:53:19 Done.
+ if (rssi <= kMinRSSI) {
+ return 0;
+ } else if (rssi >= kMaxRSSI) {
msw 2016/08/12 23:08:48 nit: no else after return here and below.
juncai 2016/08/15 21:53:19 Done.
+ return kNumLevels - 1;
+ } else {
+ double input_range = kMaxRSSI - kMinRSSI;
+ double output_range = kNumLevels - 1;
+ return static_cast<int>(
+ (static_cast<double>(rssi - kMinRSSI) * output_range / input_range));
msw 2016/08/12 23:08:48 nit: you shouldn't need this static cast, right?
juncai 2016/08/15 21:53:19 Done.
+ }
+}
+
} // namespace
BluetoothChooserController::BluetoothChooserController(
@@ -40,6 +60,10 @@ BluetoothChooserController::BluetoothChooserController(
BluetoothChooserController::~BluetoothChooserController() {}
+bool BluetoothChooserController::HasIconBeforeText() const {
+ return true;
+}
+
base::string16 BluetoothChooserController::GetNoOptionsText() const {
return no_devices_text_;
}
@@ -50,12 +74,16 @@ base::string16 BluetoothChooserController::GetOkButtonLabel() const {
}
size_t BluetoothChooserController::NumOptions() const {
- return device_ids_.size();
+ return devices_info_.size();
+}
+
+int BluetoothChooserController::GetSignalStrengthLevel(size_t index) const {
+ return devices_info_[index].signal_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_info_.size());
+ const std::string& device_id = devices_info_[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 +113,9 @@ void BluetoothChooserController::Select(size_t index) {
BLUETOOTH_CHOOSER_EVENT_HANDLER_INVALID);
return;
}
- DCHECK_LT(index, device_ids_.size());
+ DCHECK_LT(index, devices_info_.size());
event_handler_.Run(content::BluetoothChooser::Event::SELECTED,
- device_ids_[index]);
+ devices_info_[index].id);
}
void BluetoothChooserController::Cancel() {
@@ -179,10 +207,11 @@ void BluetoothChooserController::AddOrUpdateDevice(
return;
}
- device_ids_.push_back(device_id);
+ int level = rssi ? CalculateSignalLevel(static_cast<int>(*rssi)) : -1;
msw 2016/08/12 23:08:48 nit: this static cast shouldn't be necessary, righ
juncai 2016/08/15 21:53:19 Done.
+ devices_info_.push_back({device_id, level});
++device_name_map_[device_name];
if (view())
- view()->OnOptionAdded(device_ids_.size() - 1);
+ view()->OnOptionAdded(devices_info_.size() - 1);
}
void BluetoothChooserController::RemoveDevice(const std::string& device_id) {
@@ -191,13 +220,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_info_) {
+ if (saved_device_info.id != device_id) {
++index;
continue;
}
- device_ids_.erase(device_ids_.begin() + index);
+ devices_info_.erase(devices_info_.begin() + index);
const auto& it = device_name_map_.find(name_it->second);
DCHECK(it != device_name_map_.end());
@@ -219,7 +248,7 @@ void BluetoothChooserController::ResetEventHandler() {
}
void BluetoothChooserController::ClearAllDevices() {
- device_ids_.clear();
+ devices_info_.clear();
device_id_to_name_map_.clear();
device_name_map_.clear();
}

Powered by Google App Engine
This is Rietveld 408576698