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 e9e48d7edf55725713bb08fda93818d63357942a..8b91da7a5aae39af63a778dba3e5af059aca2363 100644 |
| --- a/chromeos/components/tether/host_scanner.cc |
| +++ b/chromeos/components/tether/host_scanner.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/bind.h" |
| #include "chromeos/components/tether/device_id_tether_network_guid_map.h" |
| +#include "chromeos/components/tether/host_scan_cache.h" |
| #include "chromeos/components/tether/tether_host_fetcher.h" |
| #include "chromeos/network/network_state.h" |
| #include "components/cryptauth/remote_device_loader.h" |
| @@ -37,16 +38,16 @@ HostScanner::HostScanner( |
| BleConnectionManager* connection_manager, |
| HostScanDevicePrioritizer* host_scan_device_prioritizer, |
| TetherHostResponseRecorder* tether_host_response_recorder, |
| - NetworkStateHandler* network_state_handler, |
| NotificationPresenter* notification_presenter, |
| - DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map) |
| + DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map, |
| + HostScanCache* host_scan_cache) |
| : tether_host_fetcher_(tether_host_fetcher), |
| connection_manager_(connection_manager), |
| host_scan_device_prioritizer_(host_scan_device_prioritizer), |
| tether_host_response_recorder_(tether_host_response_recorder), |
| - network_state_handler_(network_state_handler), |
| notification_presenter_(notification_presenter), |
| device_id_tether_network_guid_map_(device_id_tether_network_guid_map), |
| + host_scan_cache_(host_scan_cache), |
| is_fetching_hosts_(false), |
| weak_ptr_factory_(this) {} |
| @@ -87,42 +88,15 @@ void HostScanner::OnTetherAvailabilityResponse( |
| std::vector<HostScannerOperation::ScannedDeviceInfo>& |
| scanned_device_list_so_far, |
| bool is_final_scan_result) { |
| - 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(khorimoto): Use UpdateTetherNetworkProperties if the network already |
| - // exists. |
| + if (scanned_device_list_so_far.empty()) { |
| + // If a new scan is just starting up, remove existing cache entries; if they |
| + // are still within range to communicate with the current device, they will |
| + // show |
|
Ryan Hansberry
2017/04/28 22:31:04
Finish this sentence.
Kyle Horimoto
2017/04/28 22:45:04
Done.
|
| + host_scan_cache_->ClearCacheExceptForActiveHost(); |
| + } else { |
| + // Add all results received so far to the cache. |
| for (auto& scanned_device_info : scanned_device_list_so_far) { |
| - 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. For |
| - // battery percentage, force the value to be between 0 and 100. For signal |
| - // strength, convert from Android signal strength to Chrome OS signal |
| - // strength and force the value to be between 0 and 100. |
| - const int32_t battery_percentage = |
| - status.has_battery_percentage() |
| - ? ForceBetweenZeroAndOneHundred(status.battery_percentage()) |
| - : 100; |
| - const int32_t signal_strength = |
| - status.has_connection_strength() |
| - ? ForceBetweenZeroAndOneHundred( |
| - kAndroidTetherHostToChromeOSSignalStrengthMultiplier * |
| - status.connection_strength()) |
| - : 100; |
| - |
| - // TODO(khorimoto): Pass a HasConnectedToHost parameter to this function. |
| - network_state_handler_->AddTetherNetworkState( |
| - device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( |
| - remote_device.GetDeviceId()), |
| - remote_device.name, carrier, battery_percentage, signal_strength); |
| + SetCacheEntry(scanned_device_info); |
| } |
| if (scanned_device_list_so_far.size() == 1) { |
| @@ -141,6 +115,40 @@ void HostScanner::OnTetherAvailabilityResponse( |
| } |
| } |
| +void HostScanner::SetCacheEntry( |
| + const HostScannerOperation::ScannedDeviceInfo& scanned_device_info) { |
| + const DeviceStatus& status = scanned_device_info.device_status; |
| + const cryptauth::RemoteDevice& remote_device = |
| + scanned_device_info.remote_device; |
| + |
| + // Use a sentinel value if carrier information is not available. This value is |
| + // special-cased and replaced with a localized string in the settings UI. |
| + 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. For |
| + // battery percentage, force the value to be between 0 and 100. For signal |
| + // strength, convert from Android signal strength to Chrome OS signal |
| + // strength and force the value to be between 0 and 100. |
| + const int32_t battery_percentage = |
| + status.has_battery_percentage() |
| + ? ForceBetweenZeroAndOneHundred(status.battery_percentage()) |
| + : 100; |
| + const int32_t signal_strength = |
| + status.has_connection_strength() |
| + ? ForceBetweenZeroAndOneHundred( |
| + kAndroidTetherHostToChromeOSSignalStrengthMultiplier * |
| + status.connection_strength()) |
| + : 100; |
| + |
| + host_scan_cache_->SetHostScanResult( |
| + device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( |
| + remote_device.GetDeviceId()), |
| + remote_device.name, carrier, battery_percentage, signal_strength); |
| +} |
| + |
| } // namespace tether |
| } // namespace chromeos |