Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: chromeos/components/tether/host_scanner.cc

Issue 2781263004: HostScanner: Add scanned hosts to NetworkStateHandler and NotificationPresenter. (Closed)
Patch Set: Add tests. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 if (scanned_device_list_so_far.size() == 1) {
Kyle Horimoto 2017/04/07 01:08:07 nit: Do the UI stuff after the networks have been
Ryan Hansberry 2017/04/07 01:25:04 Done.
70 notification_presenter_->NotifyPotentialHotspotNearby(
71 scanned_device_list_so_far.at(0).remote_device);
72 } else {
73 notification_presenter_->NotifyMultiplePotentialHotspotsNearby();
74 }
75
76 // TODO (hansberry): Clear out old scanned hosts from NetworkStateHandler.
Kyle Horimoto 2017/04/07 01:08:08 You'll also need a TODO for adding the device info
Ryan Hansberry 2017/04/07 01:25:04 Done.
77 for (auto scanned_device_info : scanned_device_list_so_far) {
78 cryptauth::RemoteDevice remote_device = scanned_device_info.remote_device;
79 network_state_handler_->AddTetherNetworkState(remote_device.GetDeviceId(),
80 remote_device.name);
81 }
82 }
64 83
65 if (is_final_scan_result) { 84 if (is_final_scan_result) {
66 // If the final scan result has been received, the operation is finished. 85 // If the final scan result has been received, the operation is finished.
67 // Delete it. 86 // Delete it.
68 host_scanner_operation_->RemoveObserver(this); 87 host_scanner_operation_->RemoveObserver(this);
69 host_scanner_operation_.reset(); 88 host_scanner_operation_.reset();
70 } 89 }
71 } 90 }
72 91
73 } // namespace tether 92 } // namespace tether
74 93
75 } // namespace chromeos 94 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698