Chromium Code Reviews| Index: components/proximity_auth/proximity_monitor_impl.cc |
| diff --git a/components/proximity_auth/proximity_monitor_impl.cc b/components/proximity_auth/proximity_monitor_impl.cc |
| index 202be9defe0de6ae3fb285a3e81bcb71d66a61c9..a6034dfb0f3f3580a636aaf1f2247275dfcd7e24 100644 |
| --- a/components/proximity_auth/proximity_monitor_impl.cc |
| +++ b/components/proximity_auth/proximity_monitor_impl.cc |
| @@ -14,6 +14,7 @@ |
| #include "base/time/time.h" |
| #include "components/proximity_auth/logging/logging.h" |
| #include "components/proximity_auth/metrics.h" |
| +#include "components/proximity_auth/proximity_auth_pref_manager.h" |
| #include "components/proximity_auth/proximity_monitor_observer.h" |
| #include "device/bluetooth/bluetooth_adapter.h" |
| #include "device/bluetooth/bluetooth_adapter_factory.h" |
| @@ -25,22 +26,18 @@ namespace proximity_auth { |
| // The time to wait, in milliseconds, between proximity polling iterations. |
| const int kPollingTimeoutMs = 250; |
| -// The RSSI threshold below which we consider the remote device to not be in |
| -// proximity. |
| -// Note: Because this threshold is unconfigurable right now, it is set quite |
| -// conservatively in order to avoid blocking users. |
| -const int kRssiThreshold = -70; |
| - |
| // The weight of the most recent RSSI sample. |
| const double kRssiSampleWeight = 0.3; |
| ProximityMonitorImpl::ProximityMonitorImpl( |
| cryptauth::Connection* connection, |
| - std::unique_ptr<base::TickClock> clock) |
| + std::unique_ptr<base::TickClock> clock, |
| + ProximityAuthPrefManager* pref_manager) |
| : connection_(connection), |
| remote_device_is_in_proximity_(false), |
| is_active_(false), |
| clock_(std::move(clock)), |
| + pref_manager_(pref_manager), |
| polling_weak_ptr_factory_(this), |
| weak_ptr_factory_(this) { |
| if (device::BluetoothAdapterFactory::IsBluetoothSupported()) { |
| @@ -58,6 +55,7 @@ ProximityMonitorImpl::~ProximityMonitorImpl() { |
| void ProximityMonitorImpl::Start() { |
| is_active_ = true; |
| + GetRssiThresholdFromPrefs(); |
| UpdatePollingState(); |
| } |
| @@ -192,7 +190,7 @@ void ProximityMonitorImpl::AddSample( |
| void ProximityMonitorImpl::CheckForProximityStateChange() { |
| bool is_now_in_proximity = |
| - rssi_rolling_average_ && *rssi_rolling_average_ > kRssiThreshold; |
| + rssi_rolling_average_ && *rssi_rolling_average_ > rssi_threshold_; |
| if (rssi_rolling_average_) |
| PA_LOG(INFO) << " Rolling RSSI: " << *rssi_rolling_average_; |
| @@ -206,4 +204,28 @@ void ProximityMonitorImpl::CheckForProximityStateChange() { |
| } |
| } |
| +void ProximityMonitorImpl::GetRssiThresholdFromPrefs() { |
| + ProximityAuthPrefManager::ProximityThreshold threshold = |
| + pref_manager_->GetProximityThreshold(); |
| + switch (threshold) { |
| + case ProximityAuthPrefManager::ProximityThreshold::kVeryClose: |
| + rssi_threshold_ = -45; |
| + return; |
| + case ProximityAuthPrefManager::ProximityThreshold::kClose: |
| + rssi_threshold_ = -60; |
| + return; |
| + case ProximityAuthPrefManager::ProximityThreshold::kFar: |
| + rssi_threshold_ = -70; |
| + return; |
| + case ProximityAuthPrefManager::ProximityThreshold::kVeryFar: |
| + rssi_threshold_ = -85; |
| + return; |
| + default: |
|
battre
2017/07/12 07:18:47
I would suggest to drop the default block. The com
sacomoto
2017/07/12 15:52:53
Done.
|
| + PA_LOG(WARNING) << "[Proximity] Unmapped proximityThreshold: " |
| + << threshold; |
| + rssi_threshold_ = -70; |
| + return; |
| + } |
| +} |
| + |
| } // namespace proximity_auth |