| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/proximity_monitor_impl.h" | 5 #include "components/proximity_auth/proximity_monitor_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool ProximityMonitorImpl::IsInRssiRange() const { | 82 bool ProximityMonitorImpl::IsInRssiRange() const { |
| 83 return (strategy_ != Strategy::NONE && rssi_rolling_average_ && | 83 return (strategy_ != Strategy::NONE && rssi_rolling_average_ && |
| 84 *rssi_rolling_average_ > kRssiThreshold); | 84 *rssi_rolling_average_ > kRssiThreshold); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void ProximityMonitorImpl::RecordProximityMetricsOnAuthSuccess() { | 87 void ProximityMonitorImpl::RecordProximityMetricsOnAuthSuccess() { |
| 88 double rssi_rolling_average = rssi_rolling_average_ | 88 double rssi_rolling_average = rssi_rolling_average_ |
| 89 ? *rssi_rolling_average_ | 89 ? *rssi_rolling_average_ |
| 90 : metrics::kUnknownProximityValue; | 90 : device::BluetoothDevice::kUnknownRSSI; |
| 91 | 91 |
| 92 int last_transmit_power_delta = | 92 int last_transmit_power_delta = |
| 93 last_transmit_power_reading_ | 93 last_transmit_power_reading_ |
| 94 ? (last_transmit_power_reading_->transmit_power - | 94 ? (last_transmit_power_reading_->transmit_power - |
| 95 last_transmit_power_reading_->max_transmit_power) | 95 last_transmit_power_reading_->max_transmit_power) |
| 96 : metrics::kUnknownProximityValue; | 96 : device::BluetoothDevice::kUnknownTxPower; |
| 97 | 97 |
| 98 // If no zero RSSI value has been read, then record an overflow. | 98 // If no zero RSSI value has been read, then record an overflow. |
| 99 base::TimeDelta time_since_last_zero_rssi; | 99 base::TimeDelta time_since_last_zero_rssi; |
| 100 if (last_zero_rssi_timestamp_) | 100 if (last_zero_rssi_timestamp_) |
| 101 time_since_last_zero_rssi = clock_->NowTicks() - *last_zero_rssi_timestamp_; | 101 time_since_last_zero_rssi = clock_->NowTicks() - *last_zero_rssi_timestamp_; |
| 102 else | 102 else |
| 103 time_since_last_zero_rssi = base::TimeDelta::FromDays(100); | 103 time_since_last_zero_rssi = base::TimeDelta::FromDays(100); |
| 104 | 104 |
| 105 std::string remote_device_model = metrics::kUnknownDeviceModel; | 105 std::string remote_device_model = metrics::kUnknownDeviceModel; |
| 106 if (remote_device_.name != remote_device_.bluetooth_address) | 106 if (remote_device_.name != remote_device_.bluetooth_address) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 weak_ptr_factory_.GetWeakPtr())); | 197 weak_ptr_factory_.GetWeakPtr())); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void ProximityMonitorImpl::OnConnectionInfo( | 200 void ProximityMonitorImpl::OnConnectionInfo( |
| 201 const BluetoothDevice::ConnectionInfo& connection_info) { | 201 const BluetoothDevice::ConnectionInfo& connection_info) { |
| 202 if (!is_active_) { | 202 if (!is_active_) { |
| 203 PA_LOG(INFO) << "[Proximity] Got connection info after stopping"; | 203 PA_LOG(INFO) << "[Proximity] Got connection info after stopping"; |
| 204 return; | 204 return; |
| 205 } | 205 } |
| 206 | 206 |
| 207 if (connection_info.rssi != BluetoothDevice::kUnknownPower && | 207 if (connection_info.rssi != BluetoothDevice::kUnknownRSSI && |
| 208 connection_info.transmit_power != BluetoothDevice::kUnknownPower && | 208 connection_info.transmit_power != BluetoothDevice::kUnknownTxPower && |
| 209 connection_info.max_transmit_power != BluetoothDevice::kUnknownPower) { | 209 connection_info.max_transmit_power != BluetoothDevice::kUnknownTxPower) { |
| 210 AddSample(connection_info); | 210 AddSample(connection_info); |
| 211 } else { | 211 } else { |
| 212 PA_LOG(WARNING) << "[Proximity] Unkown values received from API: " | 212 PA_LOG(WARNING) << "[Proximity] Unkown values received from API: " |
| 213 << connection_info.rssi << " " | 213 << connection_info.rssi << " " |
| 214 << connection_info.transmit_power << " " | 214 << connection_info.transmit_power << " " |
| 215 << connection_info.max_transmit_power; | 215 << connection_info.max_transmit_power; |
| 216 rssi_rolling_average_.reset(); | 216 rssi_rolling_average_.reset(); |
| 217 last_transmit_power_reading_.reset(); | 217 last_transmit_power_reading_.reset(); |
| 218 CheckForProximityStateChange(); | 218 CheckForProximityStateChange(); |
| 219 } | 219 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 if (remote_device_is_in_proximity_ != is_now_in_proximity) { | 272 if (remote_device_is_in_proximity_ != is_now_in_proximity) { |
| 273 PA_LOG(INFO) << "[Proximity] Updated proximity state: " | 273 PA_LOG(INFO) << "[Proximity] Updated proximity state: " |
| 274 << (is_now_in_proximity ? "proximate" : "distant"); | 274 << (is_now_in_proximity ? "proximate" : "distant"); |
| 275 remote_device_is_in_proximity_ = is_now_in_proximity; | 275 remote_device_is_in_proximity_ = is_now_in_proximity; |
| 276 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_, | 276 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_, |
| 277 OnProximityStateChanged()); | 277 OnProximityStateChanged()); |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 } // namespace proximity_auth | 281 } // namespace proximity_auth |
| OLD | NEW |