Chromium Code Reviews| 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(); | 
| } |