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 27 matching lines...) Expand all Loading... | |
116 : 100; | 119 : 100; |
117 | 120 |
118 network_state_handler_->AddTetherNetworkState( | 121 network_state_handler_->AddTetherNetworkState( |
119 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( | 122 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( |
120 remote_device.GetDeviceId()), | 123 remote_device.GetDeviceId()), |
121 remote_device.name, carrier, battery_percentage, signal_strength); | 124 remote_device.name, carrier, battery_percentage, signal_strength); |
122 } | 125 } |
123 | 126 |
124 if (scanned_device_list_so_far.size() == 1) { | 127 if (scanned_device_list_so_far.size() == 1) { |
125 notification_presenter_->NotifyPotentialHotspotNearby( | 128 notification_presenter_->NotifyPotentialHotspotNearby( |
126 scanned_device_list_so_far.at(0).remote_device); | 129 scanned_device_list_so_far.at(0).remote_device); |
Ryan Hansberry
2017/04/27 17:45:54
How do you plan to inform the UI layer that the Co
Kyle Horimoto
2017/04/27 17:51:42
I'm adding a new HasConnectedToHost network proper
Ryan Hansberry
2017/04/27 18:08:25
Got it. I assume that will be passed as a new argu
Kyle Horimoto
2017/04/27 18:10:55
Done.
| |
127 } else { | 130 } else { |
128 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); | 131 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); |
129 } | 132 } |
130 } | 133 } |
131 | 134 |
132 if (is_final_scan_result) { | 135 if (is_final_scan_result) { |
133 // If the final scan result has been received, the operation is finished. | 136 // If the final scan result has been received, the operation is finished. |
134 // Delete it. | 137 // Delete it. |
135 host_scanner_operation_->RemoveObserver(this); | 138 host_scanner_operation_->RemoveObserver(this); |
136 host_scanner_operation_.reset(); | 139 host_scanner_operation_.reset(); |
137 } | 140 } |
138 } | 141 } |
139 | 142 |
140 } // namespace tether | 143 } // namespace tether |
141 | 144 |
142 } // namespace chromeos | 145 } // namespace chromeos |
OLD | NEW |