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

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: Update TODOs. 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";
stevenjb 2017/04/19 17:34:17 We shouldn't be doing localization in this code. J
Kyle Horimoto 2017/04/19 19:23:28 Done.
21
22 // Android signal strength is measured between 0 and 4 (inclusive), but Chrome
23 // OS signal strength is measured between 0 and 100 (inclusive). In order to
24 // convert between Android signal strength to Chrome OS signal strength, the
25 // value must be multiplied by the below value.
26 const int32_t kAndroidTetherHostToChromeOSSignalStrengthMultiplier = 25;
27
28 int32_t ForceBetweenZeroAndOneHundred(int32_t value) {
29 if (value < 0)
30 return 0;
31 if (value > 100)
32 return 100;
33 return value;
34 }
stevenjb 2017/04/19 17:34:17 std::min(std::max(valuue, 0), 100);
Kyle Horimoto 2017/04/19 19:23:28 Done.
35 }
36
16 HostScanner::HostScanner( 37 HostScanner::HostScanner(
17 TetherHostFetcher* tether_host_fetcher, 38 TetherHostFetcher* tether_host_fetcher,
18 BleConnectionManager* connection_manager, 39 BleConnectionManager* connection_manager,
19 HostScanDevicePrioritizer* host_scan_device_prioritizer, 40 HostScanDevicePrioritizer* host_scan_device_prioritizer,
20 NetworkStateHandler* network_state_handler, 41 NetworkStateHandler* network_state_handler,
21 NotificationPresenter* notification_presenter) 42 NotificationPresenter* notification_presenter,
43 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map)
22 : tether_host_fetcher_(tether_host_fetcher), 44 : tether_host_fetcher_(tether_host_fetcher),
23 connection_manager_(connection_manager), 45 connection_manager_(connection_manager),
24 host_scan_device_prioritizer_(host_scan_device_prioritizer), 46 host_scan_device_prioritizer_(host_scan_device_prioritizer),
25 network_state_handler_(network_state_handler), 47 network_state_handler_(network_state_handler),
26 notification_presenter_(notification_presenter), 48 notification_presenter_(notification_presenter),
49 device_id_tether_network_guid_map_(device_id_tether_network_guid_map),
27 is_fetching_hosts_(false), 50 is_fetching_hosts_(false),
28 weak_ptr_factory_(this) {} 51 weak_ptr_factory_(this) {}
29 52
30 HostScanner::~HostScanner() {} 53 HostScanner::~HostScanner() {}
31 54
32 void HostScanner::StartScan() { 55 void HostScanner::StartScan() {
33 if (host_scanner_operation_) { 56 if (host_scanner_operation_) {
34 // If a scan is already active, do not continue. 57 // If a scan is already active, do not continue.
35 return; 58 return;
36 } 59 }
(...skipping 22 matching lines...) Expand all
59 host_scanner_operation_->Initialize(); 82 host_scanner_operation_->Initialize();
60 } 83 }
61 84
62 void HostScanner::OnTetherAvailabilityResponse( 85 void HostScanner::OnTetherAvailabilityResponse(
63 std::vector<HostScannerOperation::ScannedDeviceInfo>& 86 std::vector<HostScannerOperation::ScannedDeviceInfo>&
64 scanned_device_list_so_far, 87 scanned_device_list_so_far,
65 bool is_final_scan_result) { 88 bool is_final_scan_result) {
66 most_recent_scan_results_ = scanned_device_list_so_far; 89 most_recent_scan_results_ = scanned_device_list_so_far;
67 90
68 if (!scanned_device_list_so_far.empty()) { 91 if (!scanned_device_list_so_far.empty()) {
69 // TODO (hansberry): Clear out old scanned hosts from NetworkStateHandler. 92 // TODO(hansberry): Clear out old scanned hosts from NetworkStateHandler.
70 // TODO (hansberry): Add battery and cell strength properties once 93 // TODO(khorimoto): Use UpdateTetherNetworkProperties if the network already
71 // available. 94 // exists.
72 for (auto& scanned_device_info : scanned_device_list_so_far) { 95 for (auto& scanned_device_info : scanned_device_list_so_far) {
73 cryptauth::RemoteDevice remote_device = scanned_device_info.remote_device; 96 const DeviceStatus& status = scanned_device_info.device_status;
74 network_state_handler_->AddTetherNetworkState(remote_device.GetDeviceId(), 97 const cryptauth::RemoteDevice& remote_device =
75 remote_device.name); 98 scanned_device_info.remote_device;
99
100 const std::string carrier =
101 (!status.has_cell_provider() || status.cell_provider().empty())
102 ? kDefaultCellCarrierName
103 : status.cell_provider();
104
105 // If battery or signal strength are missing, assume they are 100. For
106 // battery percentage, force the value to be between 0 and 100. For signal
107 // strength, convert from Android signal strength to Chrome OS signal
108 // strength and force the value to be between 0 and 100.
109 const int32_t battery_percentage =
110 status.has_battery_percentage()
111 ? 100
112 : ForceBetweenZeroAndOneHundred(status.battery_percentage());
stevenjb 2017/04/19 17:34:17 invert
Kyle Horimoto 2017/04/19 19:23:28 Done.
113 const int32_t signal_strength =
114 status.has_connection_strength()
115 ? 100
116 : ForceBetweenZeroAndOneHundred(
117 kAndroidTetherHostToChromeOSSignalStrengthMultiplier *
118 status.connection_strength());
stevenjb 2017/04/19 17:34:17 invert
Kyle Horimoto 2017/04/19 19:23:28 Done.
119
120 network_state_handler_->AddTetherNetworkState(
121 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId(
122 remote_device.GetDeviceId()),
123 remote_device.name, carrier, battery_percentage, signal_strength);
76 } 124 }
77 125
78 if (scanned_device_list_so_far.size() == 1) { 126 if (scanned_device_list_so_far.size() == 1) {
79 notification_presenter_->NotifyPotentialHotspotNearby( 127 notification_presenter_->NotifyPotentialHotspotNearby(
80 scanned_device_list_so_far.at(0).remote_device); 128 scanned_device_list_so_far.at(0).remote_device);
81 } else { 129 } else {
82 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); 130 notification_presenter_->NotifyMultiplePotentialHotspotsNearby();
83 } 131 }
84 } 132 }
85 133
86 if (is_final_scan_result) { 134 if (is_final_scan_result) {
87 // If the final scan result has been received, the operation is finished. 135 // If the final scan result has been received, the operation is finished.
88 // Delete it. 136 // Delete it.
89 host_scanner_operation_->RemoveObserver(this); 137 host_scanner_operation_->RemoveObserver(this);
90 host_scanner_operation_.reset(); 138 host_scanner_operation_.reset();
91 } 139 }
92 } 140 }
93 141
94 } // namespace tether 142 } // namespace tether
95 143
96 } // namespace chromeos 144 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698