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 2819383002: [CrOS Tether] Update NetworkState to include tether properties and integrate into NetworkStateHandl… (Closed)
Patch Set: Fix comments, add style change, change a LOG to a DCHECK. 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/device_id_tether_network_guid_map.h"
8 #include "chromeos/components/tether/tether_host_fetcher.h" 9 #include "chromeos/components/tether/tether_host_fetcher.h"
9 #include "chromeos/network/network_state.h" 10 #include "chromeos/network/network_state.h"
10 #include "components/cryptauth/remote_device_loader.h" 11 #include "components/cryptauth/remote_device_loader.h"
11 12
12 namespace chromeos { 13 namespace chromeos {
13 14
14 namespace tether { 15 namespace tether {
15 16
17 namespace {
18
19 // TODO(khorimoto): Localize this name.
20 const char kDefaultCellCarrierName[] = "Unknown Carrier";
21
22 int32_t ForceBetweenZeroAndOneHundred(int32_t value) {
23 if (value < 0)
24 return 0;
25 if (value > 100)
26 return 100;
27 return value;
28 }
29 }
30
16 HostScanner::HostScanner( 31 HostScanner::HostScanner(
17 TetherHostFetcher* tether_host_fetcher, 32 TetherHostFetcher* tether_host_fetcher,
18 BleConnectionManager* connection_manager, 33 BleConnectionManager* connection_manager,
19 HostScanDevicePrioritizer* host_scan_device_prioritizer, 34 HostScanDevicePrioritizer* host_scan_device_prioritizer,
20 NetworkStateHandler* network_state_handler, 35 NetworkStateHandler* network_state_handler,
21 NotificationPresenter* notification_presenter) 36 NotificationPresenter* notification_presenter,
37 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map)
22 : tether_host_fetcher_(tether_host_fetcher), 38 : tether_host_fetcher_(tether_host_fetcher),
23 connection_manager_(connection_manager), 39 connection_manager_(connection_manager),
24 host_scan_device_prioritizer_(host_scan_device_prioritizer), 40 host_scan_device_prioritizer_(host_scan_device_prioritizer),
25 network_state_handler_(network_state_handler), 41 network_state_handler_(network_state_handler),
26 notification_presenter_(notification_presenter), 42 notification_presenter_(notification_presenter),
43 device_id_tether_network_guid_map_(device_id_tether_network_guid_map),
27 is_fetching_hosts_(false), 44 is_fetching_hosts_(false),
28 weak_ptr_factory_(this) {} 45 weak_ptr_factory_(this) {}
29 46
30 HostScanner::~HostScanner() {} 47 HostScanner::~HostScanner() {}
31 48
32 void HostScanner::StartScan() { 49 void HostScanner::StartScan() {
33 if (host_scanner_operation_) { 50 if (host_scanner_operation_) {
34 // If a scan is already active, do not continue. 51 // If a scan is already active, do not continue.
35 return; 52 return;
36 } 53 }
(...skipping 22 matching lines...) Expand all
59 host_scanner_operation_->Initialize(); 76 host_scanner_operation_->Initialize();
60 } 77 }
61 78
62 void HostScanner::OnTetherAvailabilityResponse( 79 void HostScanner::OnTetherAvailabilityResponse(
63 std::vector<HostScannerOperation::ScannedDeviceInfo>& 80 std::vector<HostScannerOperation::ScannedDeviceInfo>&
64 scanned_device_list_so_far, 81 scanned_device_list_so_far,
65 bool is_final_scan_result) { 82 bool is_final_scan_result) {
66 most_recent_scan_results_ = scanned_device_list_so_far; 83 most_recent_scan_results_ = scanned_device_list_so_far;
67 84
68 if (!scanned_device_list_so_far.empty()) { 85 if (!scanned_device_list_so_far.empty()) {
69 // TODO (hansberry): Clear out old scanned hosts from NetworkStateHandler. 86 // TODO(khorimoto): Clear out old scanned hosts from NetworkStateHandler.
70 // TODO (hansberry): Add battery and cell strength properties once 87 // Currently, AddTetherNetworkState() is called each time this function is
71 // available. 88 // invoked, which will add a bunch of duplicate networks.
Ryan Hansberry 2017/04/18 16:08:55 This is incorrect. When AddTetherNetworkState is c
Kyle Horimoto 2017/04/18 17:15:23 Done.
72 for (auto& scanned_device_info : scanned_device_list_so_far) { 89 for (auto& scanned_device_info : scanned_device_list_so_far) {
73 cryptauth::RemoteDevice remote_device = scanned_device_info.remote_device; 90 const DeviceStatus& status = scanned_device_info.device_status;
74 network_state_handler_->AddTetherNetworkState(remote_device.GetDeviceId(), 91 const cryptauth::RemoteDevice& remote_device =
75 remote_device.name); 92 scanned_device_info.remote_device;
93
94 const std::string carrier =
95 (!status.has_cell_provider() || status.cell_provider().empty())
96 ? kDefaultCellCarrierName
97 : status.cell_provider();
98
99 // If battery or signal strength are missing, assume they are 100.
Ryan Hansberry 2017/04/18 16:08:55 Signal strength is between 0 and 4 inclusive.
Kyle Horimoto 2017/04/18 17:15:23 Thanks for catching this. Chrome OS measures signa
100 // Additionally, force their values
101 const int32_t battery_percentage =
102 status.has_battery_percentage()
103 ? 100
104 : ForceBetweenZeroAndOneHundred(status.battery_percentage());
105 const int32_t signal_strength =
106 status.has_connection_strength()
107 ? 100
108 : ForceBetweenZeroAndOneHundred(status.connection_strength());
109
110 network_state_handler_->AddTetherNetworkState(
111 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId(
112 remote_device.GetDeviceId()),
113 remote_device.name, carrier, battery_percentage, signal_strength);
76 } 114 }
77 115
78 if (scanned_device_list_so_far.size() == 1) { 116 if (scanned_device_list_so_far.size() == 1) {
79 notification_presenter_->NotifyPotentialHotspotNearby( 117 notification_presenter_->NotifyPotentialHotspotNearby(
80 scanned_device_list_so_far.at(0).remote_device); 118 scanned_device_list_so_far.at(0).remote_device);
81 } else { 119 } else {
82 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); 120 notification_presenter_->NotifyMultiplePotentialHotspotsNearby();
83 } 121 }
84 } 122 }
85 123
86 if (is_final_scan_result) { 124 if (is_final_scan_result) {
87 // If the final scan result has been received, the operation is finished. 125 // If the final scan result has been received, the operation is finished.
88 // Delete it. 126 // Delete it.
89 host_scanner_operation_->RemoveObserver(this); 127 host_scanner_operation_->RemoveObserver(this);
90 host_scanner_operation_.reset(); 128 host_scanner_operation_.reset();
91 } 129 }
92 } 130 }
93 131
94 } // namespace tether 132 } // namespace tether
95 133
96 } // namespace chromeos 134 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698