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

Unified Diff: components/proximity_auth/proximity_monitor_impl.cc

Issue 2973243002: Adding pref to store the user-selected proximity threshold. (Closed)
Patch Set: Fixing tests Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
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..fe13927fb1b779b219ff65f77515f2832dcb4b2f 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,23 @@ 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;
+// These are arbitrary labels displayed in the settings page for the user
+// to select. The correspondence to actual RSSI values is done in the
+// GetRssiThresholdFromPrefs().
+enum ProximityThreshold { kVeryClose = 0, kClose = 1, kFar = 2, kVeryFar = 3 };
+
ProximityMonitorImpl::ProximityMonitorImpl(
cryptauth::Connection* connection,
- std::unique_ptr<base::TickClock> clock)
+ std::unique_ptr<base::TickClock> clock,
+ std::unique_ptr<ProximityAuthPrefManager> pref_manager)
: connection_(connection),
remote_device_is_in_proximity_(false),
is_active_(false),
clock_(std::move(clock)),
+ pref_manager_(std::move(pref_manager)),
polling_weak_ptr_factory_(this),
weak_ptr_factory_(this) {
if (device::BluetoothAdapterFactory::IsBluetoothSupported()) {
@@ -58,6 +60,7 @@ ProximityMonitorImpl::~ProximityMonitorImpl() {
void ProximityMonitorImpl::Start() {
is_active_ = true;
+ GetRssiThresholdFromPrefs();
UpdatePollingState();
}
@@ -192,7 +195,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 +209,28 @@ void ProximityMonitorImpl::CheckForProximityStateChange() {
}
}
+void ProximityMonitorImpl::GetRssiThresholdFromPrefs() {
+ int pref_value = pref_manager_->GetProximityThreshold();
+ ProximityThreshold threshold = static_cast<ProximityThreshold>(pref_value);
+ switch (threshold) {
+ case ProximityThreshold::kVeryClose:
+ rssi_threshold_ = -45;
+ return;
+ case ProximityThreshold::kClose:
+ rssi_threshold_ = -60;
+ return;
+ case ProximityThreshold::kFar:
+ rssi_threshold_ = -70;
+ return;
+ case ProximityThreshold::kVeryFar:
+ rssi_threshold_ = -85;
+ return;
+ default:
+ PA_LOG(WARNING) << "[Proximity] Unmapped proximityThreshold: "
+ << threshold;
+ rssi_threshold_ = -70;
+ return;
+ }
+}
+
} // namespace proximity_auth

Powered by Google App Engine
This is Rietveld 408576698