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

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

Issue 2917813002: [CrOS Tether] Move the DeviceStatus normalizer code from HostScanner into its own file. (Closed)
Patch Set: Fix spelling error typo. Created 3 years, 6 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
« no previous file with comments | « chromeos/components/tether/device_status_util_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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"
11 #include "chromeos/components/tether/device_status_util.h"
11 #include "chromeos/components/tether/host_scan_cache.h" 12 #include "chromeos/components/tether/host_scan_cache.h"
12 #include "chromeos/components/tether/tether_host_fetcher.h" 13 #include "chromeos/components/tether/tether_host_fetcher.h"
13 #include "chromeos/network/network_state.h" 14 #include "chromeos/network/network_state.h"
14 #include "components/cryptauth/remote_device_loader.h" 15 #include "components/cryptauth/remote_device_loader.h"
15 16
16 namespace chromeos { 17 namespace chromeos {
17 18
18 namespace tether { 19 namespace tether {
19 20
20 namespace {
21
22 const char kDefaultCellCarrierName[] = "unknown-carrier";
23
24 // Android signal strength is measured between 0 and 4 (inclusive), but Chrome
25 // OS signal strength is measured between 0 and 100 (inclusive). In order to
26 // convert between Android signal strength to Chrome OS signal strength, the
27 // value must be multiplied by the below value.
28 const int32_t kAndroidTetherHostToChromeOSSignalStrengthMultiplier = 25;
29
30 int32_t ForceBetweenZeroAndOneHundred(int32_t value) {
31 return std::min(std::max(value, 0), 100);
32 }
33
34 } // namespace
35
36 HostScanner::HostScanner( 21 HostScanner::HostScanner(
37 TetherHostFetcher* tether_host_fetcher, 22 TetherHostFetcher* tether_host_fetcher,
38 BleConnectionManager* connection_manager, 23 BleConnectionManager* connection_manager,
39 HostScanDevicePrioritizer* host_scan_device_prioritizer, 24 HostScanDevicePrioritizer* host_scan_device_prioritizer,
40 TetherHostResponseRecorder* tether_host_response_recorder, 25 TetherHostResponseRecorder* tether_host_response_recorder,
41 NotificationPresenter* notification_presenter, 26 NotificationPresenter* notification_presenter,
42 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map, 27 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map,
43 HostScanCache* host_scan_cache, 28 HostScanCache* host_scan_cache,
44 base::Clock* clock) 29 base::Clock* clock)
45 : tether_host_fetcher_(tether_host_fetcher), 30 : tether_host_fetcher_(tether_host_fetcher),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 observer.ScanFinished(); 120 observer.ScanFinished();
136 } 121 }
137 } 122 }
138 123
139 void HostScanner::SetCacheEntry( 124 void HostScanner::SetCacheEntry(
140 const HostScannerOperation::ScannedDeviceInfo& scanned_device_info) { 125 const HostScannerOperation::ScannedDeviceInfo& scanned_device_info) {
141 const DeviceStatus& status = scanned_device_info.device_status; 126 const DeviceStatus& status = scanned_device_info.device_status;
142 const cryptauth::RemoteDevice& remote_device = 127 const cryptauth::RemoteDevice& remote_device =
143 scanned_device_info.remote_device; 128 scanned_device_info.remote_device;
144 129
145 // Use a sentinel value if carrier information is not available. This value is 130 std::string carrier;
146 // special-cased and replaced with a localized string in the settings UI. 131 int32_t battery_percentage;
147 const std::string carrier = 132 int32_t signal_strength;
148 (!status.has_cell_provider() || status.cell_provider().empty()) 133 NormalizeDeviceStatus(status, &carrier, &battery_percentage,
149 ? kDefaultCellCarrierName 134 &signal_strength);
150 : status.cell_provider();
151
152 // If battery or signal strength are missing, assume they are 100. For
153 // battery percentage, force the value to be between 0 and 100. For signal
154 // strength, convert from Android signal strength to Chrome OS signal
155 // strength and force the value to be between 0 and 100.
156 const int32_t battery_percentage =
157 status.has_battery_percentage()
158 ? ForceBetweenZeroAndOneHundred(status.battery_percentage())
159 : 100;
160 const int32_t signal_strength =
161 status.has_connection_strength()
162 ? ForceBetweenZeroAndOneHundred(
163 kAndroidTetherHostToChromeOSSignalStrengthMultiplier *
164 status.connection_strength())
165 : 100;
166 135
167 host_scan_cache_->SetHostScanResult( 136 host_scan_cache_->SetHostScanResult(
168 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId( 137 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId(
169 remote_device.GetDeviceId()), 138 remote_device.GetDeviceId()),
170 remote_device.name, carrier, battery_percentage, signal_strength); 139 remote_device.name, carrier, battery_percentage, signal_strength);
171 } 140 }
172 141
173 } // namespace tether 142 } // namespace tether
174 143
175 } // namespace chromeos 144 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/components/tether/device_status_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698