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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chromeos/components/tether/tether_host_fetcher.h" | 8 #include "chromeos/components/tether/tether_host_fetcher.h" |
| 9 #include "chromeos/network/network_state.h" |
9 #include "components/cryptauth/remote_device_loader.h" | 10 #include "components/cryptauth/remote_device_loader.h" |
10 | 11 |
11 namespace chromeos { | 12 namespace chromeos { |
12 | 13 |
13 namespace tether { | 14 namespace tether { |
14 | 15 |
15 HostScanner::HostScanner( | 16 HostScanner::HostScanner( |
16 TetherHostFetcher* tether_host_fetcher, | 17 TetherHostFetcher* tether_host_fetcher, |
17 BleConnectionManager* connection_manager, | 18 BleConnectionManager* connection_manager, |
18 HostScanDevicePrioritizer* host_scan_device_prioritizer) | 19 HostScanDevicePrioritizer* host_scan_device_prioritizer, |
| 20 NetworkStateHandler* network_state_handler, |
| 21 NotificationPresenter* notification_presenter) |
19 : tether_host_fetcher_(tether_host_fetcher), | 22 : tether_host_fetcher_(tether_host_fetcher), |
20 connection_manager_(connection_manager), | 23 connection_manager_(connection_manager), |
21 host_scan_device_prioritizer_(host_scan_device_prioritizer), | 24 host_scan_device_prioritizer_(host_scan_device_prioritizer), |
| 25 network_state_handler_(network_state_handler), |
| 26 notification_presenter_(notification_presenter), |
22 is_fetching_hosts_(false), | 27 is_fetching_hosts_(false), |
23 weak_ptr_factory_(this) {} | 28 weak_ptr_factory_(this) {} |
24 | 29 |
25 HostScanner::~HostScanner() {} | 30 HostScanner::~HostScanner() {} |
26 | 31 |
27 void HostScanner::StartScan() { | 32 void HostScanner::StartScan() { |
28 if (host_scanner_operation_) { | 33 if (host_scanner_operation_) { |
29 // If a scan is already active, do not continue. | 34 // If a scan is already active, do not continue. |
30 return; | 35 return; |
31 } | 36 } |
(...skipping 21 matching lines...) Expand all Loading... |
53 host_scanner_operation_->AddObserver(this); | 58 host_scanner_operation_->AddObserver(this); |
54 host_scanner_operation_->Initialize(); | 59 host_scanner_operation_->Initialize(); |
55 } | 60 } |
56 | 61 |
57 void HostScanner::OnTetherAvailabilityResponse( | 62 void HostScanner::OnTetherAvailabilityResponse( |
58 std::vector<HostScannerOperation::ScannedDeviceInfo>& | 63 std::vector<HostScannerOperation::ScannedDeviceInfo>& |
59 scanned_device_list_so_far, | 64 scanned_device_list_so_far, |
60 bool is_final_scan_result) { | 65 bool is_final_scan_result) { |
61 most_recent_scan_results_ = scanned_device_list_so_far; | 66 most_recent_scan_results_ = scanned_device_list_so_far; |
62 | 67 |
63 // TODO(hansberry): Hook up to networking code. | 68 if (!scanned_device_list_so_far.empty()) { |
| 69 // TODO (hansberry): Clear out old scanned hosts from NetworkStateHandler. |
| 70 // TODO (hansberry): Add battery and cell strength properties once |
| 71 // available. |
| 72 for (auto& scanned_device_info : scanned_device_list_so_far) { |
| 73 cryptauth::RemoteDevice remote_device = scanned_device_info.remote_device; |
| 74 network_state_handler_->AddTetherNetworkState(remote_device.GetDeviceId(), |
| 75 remote_device.name); |
| 76 } |
| 77 |
| 78 if (scanned_device_list_so_far.size() == 1) { |
| 79 notification_presenter_->NotifyPotentialHotspotNearby( |
| 80 scanned_device_list_so_far.at(0).remote_device); |
| 81 } else { |
| 82 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); |
| 83 } |
| 84 } |
64 | 85 |
65 if (is_final_scan_result) { | 86 if (is_final_scan_result) { |
66 // If the final scan result has been received, the operation is finished. | 87 // If the final scan result has been received, the operation is finished. |
67 // Delete it. | 88 // Delete it. |
68 host_scanner_operation_->RemoveObserver(this); | 89 host_scanner_operation_->RemoveObserver(this); |
69 host_scanner_operation_.reset(); | 90 host_scanner_operation_.reset(); |
70 } | 91 } |
71 } | 92 } |
72 | 93 |
73 } // namespace tether | 94 } // namespace tether |
74 | 95 |
75 } // namespace chromeos | 96 } // namespace chromeos |
OLD | NEW |