Chromium Code Reviews| Index: chromeos/components/tether/host_scanner.cc |
| diff --git a/chromeos/components/tether/host_scanner.cc b/chromeos/components/tether/host_scanner.cc |
| index e74407454e4f667e68e155838ecd6926e7b86104..93bef25442f9775c634951501bc0314f2d48d2f3 100644 |
| --- a/chromeos/components/tether/host_scanner.cc |
| +++ b/chromeos/components/tether/host_scanner.cc |
| @@ -5,6 +5,7 @@ |
| #include "chromeos/components/tether/host_scanner.h" |
| #include "base/bind.h" |
| +#include "chromeos/components/tether/device_id_tether_network_guid_map.h" |
| #include "chromeos/components/tether/tether_host_fetcher.h" |
| #include "chromeos/network/network_state.h" |
| #include "components/cryptauth/remote_device_loader.h" |
| @@ -13,17 +14,33 @@ namespace chromeos { |
| namespace tether { |
| +namespace { |
| + |
| +// TODO(khorimoto): Localize this name. |
| +const char kDefaultCellCarrierName[] = "Unknown Carrier"; |
| + |
| +int32_t ForceBetweenZeroAndOneHundred(int32_t value) { |
| + if (value < 0) |
| + return 0; |
| + if (value > 100) |
| + return 100; |
| + return value; |
| +} |
| +} |
| + |
| HostScanner::HostScanner( |
| TetherHostFetcher* tether_host_fetcher, |
| BleConnectionManager* connection_manager, |
| HostScanDevicePrioritizer* host_scan_device_prioritizer, |
| NetworkStateHandler* network_state_handler, |
| - NotificationPresenter* notification_presenter) |
| + NotificationPresenter* notification_presenter, |
| + DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map) |
| : tether_host_fetcher_(tether_host_fetcher), |
| connection_manager_(connection_manager), |
| host_scan_device_prioritizer_(host_scan_device_prioritizer), |
| network_state_handler_(network_state_handler), |
| notification_presenter_(notification_presenter), |
| + device_id_tether_network_guid_map_(device_id_tether_network_guid_map), |
| is_fetching_hosts_(false), |
| weak_ptr_factory_(this) {} |
| @@ -66,13 +83,34 @@ void HostScanner::OnTetherAvailabilityResponse( |
| most_recent_scan_results_ = scanned_device_list_so_far; |
| if (!scanned_device_list_so_far.empty()) { |
| - // TODO (hansberry): Clear out old scanned hosts from NetworkStateHandler. |
| - // TODO (hansberry): Add battery and cell strength properties once |
| - // available. |
| + // TODO(khorimoto): Clear out old scanned hosts from NetworkStateHandler. |
| + // Currently, AddTetherNetworkState() is called each time this function is |
| + // invoked, which will add a bunch of duplicate networks. |
|
Ryan Hansberry
2017/04/18 16:08:55
This is incorrect. When AddTetherNetworkState is c
Kyle Horimoto
2017/04/18 17:15:23
Done.
|
| for (auto& scanned_device_info : scanned_device_list_so_far) { |
| - cryptauth::RemoteDevice remote_device = scanned_device_info.remote_device; |
| - network_state_handler_->AddTetherNetworkState(remote_device.GetDeviceId(), |
| - remote_device.name); |
| + const DeviceStatus& status = scanned_device_info.device_status; |
| + const cryptauth::RemoteDevice& remote_device = |
| + scanned_device_info.remote_device; |
| + |
| + const std::string carrier = |
| + (!status.has_cell_provider() || status.cell_provider().empty()) |
| + ? kDefaultCellCarrierName |
| + : status.cell_provider(); |
| + |
| + // If battery or signal strength are missing, assume they are 100. |
|
Ryan Hansberry
2017/04/18 16:08:55
Signal strength is between 0 and 4 inclusive.
Kyle Horimoto
2017/04/18 17:15:23
Thanks for catching this. Chrome OS measures signa
|
| + // Additionally, force their values |
| + const int32_t battery_percentage = |
| + status.has_battery_percentage() |
| + ? 100 |
| + : ForceBetweenZeroAndOneHundred(status.battery_percentage()); |
| + const int32_t signal_strength = |
| + status.has_connection_strength() |
| + ? 100 |
| + : ForceBetweenZeroAndOneHundred(status.connection_strength()); |
| + |
| + network_state_handler_->AddTetherNetworkState( |
| + device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( |
| + remote_device.GetDeviceId()), |
| + remote_device.name, carrier, battery_percentage, signal_strength); |
| } |
| if (scanned_device_list_so_far.size() == 1) { |