| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/components/tether/host_scanner.h" | 5 #include "chromeos/components/tether/host_scanner.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "chromeos/components/tether/device_id_tether_network_guid_map.h" | 10 #include "chromeos/components/tether/device_id_tether_network_guid_map.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 int32_t ForceBetweenZeroAndOneHundred(int32_t value) { | 29 int32_t ForceBetweenZeroAndOneHundred(int32_t value) { |
| 30 return std::min(std::max(value, 0), 100); | 30 return std::min(std::max(value, 0), 100); |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 HostScanner::HostScanner( | 35 HostScanner::HostScanner( |
| 36 TetherHostFetcher* tether_host_fetcher, | 36 TetherHostFetcher* tether_host_fetcher, |
| 37 BleConnectionManager* connection_manager, | 37 BleConnectionManager* connection_manager, |
| 38 HostScanDevicePrioritizer* host_scan_device_prioritizer, | 38 HostScanDevicePrioritizer* host_scan_device_prioritizer, |
| 39 TetherHostResponseRecorder* tether_host_response_recorder, |
| 39 NetworkStateHandler* network_state_handler, | 40 NetworkStateHandler* network_state_handler, |
| 40 NotificationPresenter* notification_presenter, | 41 NotificationPresenter* notification_presenter, |
| 41 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map) | 42 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map) |
| 42 : tether_host_fetcher_(tether_host_fetcher), | 43 : tether_host_fetcher_(tether_host_fetcher), |
| 43 connection_manager_(connection_manager), | 44 connection_manager_(connection_manager), |
| 44 host_scan_device_prioritizer_(host_scan_device_prioritizer), | 45 host_scan_device_prioritizer_(host_scan_device_prioritizer), |
| 46 tether_host_response_recorder_(tether_host_response_recorder), |
| 45 network_state_handler_(network_state_handler), | 47 network_state_handler_(network_state_handler), |
| 46 notification_presenter_(notification_presenter), | 48 notification_presenter_(notification_presenter), |
| 47 device_id_tether_network_guid_map_(device_id_tether_network_guid_map), | 49 device_id_tether_network_guid_map_(device_id_tether_network_guid_map), |
| 48 is_fetching_hosts_(false), | 50 is_fetching_hosts_(false), |
| 49 weak_ptr_factory_(this) {} | 51 weak_ptr_factory_(this) {} |
| 50 | 52 |
| 51 HostScanner::~HostScanner() {} | 53 HostScanner::~HostScanner() {} |
| 52 | 54 |
| 53 void HostScanner::StartScan() { | 55 void HostScanner::StartScan() { |
| 54 if (host_scanner_operation_) { | 56 if (host_scanner_operation_) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 68 | 70 |
| 69 bool HostScanner::IsScanActive() { | 71 bool HostScanner::IsScanActive() { |
| 70 return is_fetching_hosts_ || host_scanner_operation_; | 72 return is_fetching_hosts_ || host_scanner_operation_; |
| 71 } | 73 } |
| 72 | 74 |
| 73 void HostScanner::OnTetherHostsFetched( | 75 void HostScanner::OnTetherHostsFetched( |
| 74 const cryptauth::RemoteDeviceList& tether_hosts) { | 76 const cryptauth::RemoteDeviceList& tether_hosts) { |
| 75 is_fetching_hosts_ = false; | 77 is_fetching_hosts_ = false; |
| 76 | 78 |
| 77 host_scanner_operation_ = HostScannerOperation::Factory::NewInstance( | 79 host_scanner_operation_ = HostScannerOperation::Factory::NewInstance( |
| 78 tether_hosts, connection_manager_, host_scan_device_prioritizer_); | 80 tether_hosts, connection_manager_, host_scan_device_prioritizer_, |
| 81 tether_host_response_recorder_); |
| 79 host_scanner_operation_->AddObserver(this); | 82 host_scanner_operation_->AddObserver(this); |
| 80 host_scanner_operation_->Initialize(); | 83 host_scanner_operation_->Initialize(); |
| 81 } | 84 } |
| 82 | 85 |
| 83 void HostScanner::OnTetherAvailabilityResponse( | 86 void HostScanner::OnTetherAvailabilityResponse( |
| 84 std::vector<HostScannerOperation::ScannedDeviceInfo>& | 87 std::vector<HostScannerOperation::ScannedDeviceInfo>& |
| 85 scanned_device_list_so_far, | 88 scanned_device_list_so_far, |
| 86 bool is_final_scan_result) { | 89 bool is_final_scan_result) { |
| 87 most_recent_scan_results_ = scanned_device_list_so_far; | 90 most_recent_scan_results_ = scanned_device_list_so_far; |
| 88 | 91 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 108 status.has_battery_percentage() | 111 status.has_battery_percentage() |
| 109 ? ForceBetweenZeroAndOneHundred(status.battery_percentage()) | 112 ? ForceBetweenZeroAndOneHundred(status.battery_percentage()) |
| 110 : 100; | 113 : 100; |
| 111 const int32_t signal_strength = | 114 const int32_t signal_strength = |
| 112 status.has_connection_strength() | 115 status.has_connection_strength() |
| 113 ? ForceBetweenZeroAndOneHundred( | 116 ? ForceBetweenZeroAndOneHundred( |
| 114 kAndroidTetherHostToChromeOSSignalStrengthMultiplier * | 117 kAndroidTetherHostToChromeOSSignalStrengthMultiplier * |
| 115 status.connection_strength()) | 118 status.connection_strength()) |
| 116 : 100; | 119 : 100; |
| 117 | 120 |
| 121 // TODO(khorimoto): Pass a HasConnectedToHost parameter to this function. |
| 118 network_state_handler_->AddTetherNetworkState( | 122 network_state_handler_->AddTetherNetworkState( |
| 119 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( | 123 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( |
| 120 remote_device.GetDeviceId()), | 124 remote_device.GetDeviceId()), |
| 121 remote_device.name, carrier, battery_percentage, signal_strength); | 125 remote_device.name, carrier, battery_percentage, signal_strength); |
| 122 } | 126 } |
| 123 | 127 |
| 124 if (scanned_device_list_so_far.size() == 1) { | 128 if (scanned_device_list_so_far.size() == 1) { |
| 125 notification_presenter_->NotifyPotentialHotspotNearby( | 129 notification_presenter_->NotifyPotentialHotspotNearby( |
| 126 scanned_device_list_so_far.at(0).remote_device); | 130 scanned_device_list_so_far.at(0).remote_device); |
| 127 } else { | 131 } else { |
| 128 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); | 132 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); |
| 129 } | 133 } |
| 130 } | 134 } |
| 131 | 135 |
| 132 if (is_final_scan_result) { | 136 if (is_final_scan_result) { |
| 133 // If the final scan result has been received, the operation is finished. | 137 // If the final scan result has been received, the operation is finished. |
| 134 // Delete it. | 138 // Delete it. |
| 135 host_scanner_operation_->RemoveObserver(this); | 139 host_scanner_operation_->RemoveObserver(this); |
| 136 host_scanner_operation_.reset(); | 140 host_scanner_operation_.reset(); |
| 137 } | 141 } |
| 138 } | 142 } |
| 139 | 143 |
| 140 } // namespace tether | 144 } // namespace tether |
| 141 | 145 |
| 142 } // namespace chromeos | 146 } // namespace chromeos |
| OLD | NEW |