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

Unified Diff: components/proximity_auth/proximity_monitor_impl.cc

Issue 2973243002: Adding pref to store the user-selected proximity threshold. (Closed)
Patch Set: Missing comment 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..3326990757f29a9620207c5b6f135b56b218f06f 100644
--- a/components/proximity_auth/proximity_monitor_impl.cc
+++ b/components/proximity_auth/proximity_monitor_impl.cc
@@ -12,6 +12,8 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/tick_clock.h"
#include "base/time/time.h"
+#include "chrome/common/pref_names.h"
+#include "components/prefs/pref_service.h"
#include "components/proximity_auth/logging/logging.h"
#include "components/proximity_auth/metrics.h"
#include "components/proximity_auth/proximity_monitor_observer.h"
@@ -34,13 +36,20 @@ 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,
+ PrefService* pref_service)
: connection_(connection),
remote_device_is_in_proximity_(false),
is_active_(false),
clock_(std::move(clock)),
+ pref_service_(pref_service),
polling_weak_ptr_factory_(this),
weak_ptr_factory_(this) {
if (device::BluetoothAdapterFactory::IsBluetoothSupported()) {
@@ -58,6 +67,7 @@ ProximityMonitorImpl::~ProximityMonitorImpl() {
void ProximityMonitorImpl::Start() {
is_active_ = true;
+ GetRssiThresholdFromPrefs();
UpdatePollingState();
}
@@ -206,4 +216,24 @@ void ProximityMonitorImpl::CheckForProximityStateChange() {
}
}
+void ProximityMonitorImpl::GetRssiThresholdFromPrefs() {
+ int pref_value =
+ pref_service_->GetInteger(prefs::kEasyUnlockProximityThreshold);
+ ProximityThreshold threshold = static_cast<ProximityThreshold>(pref_value);
+ switch (threshold) {
Tim Song 2017/07/07 21:48:24 Add a default case as well.
sacomoto 2017/07/10 16:54:07 Done.
+ case ProximityThreshold::kVeryClose:
+ rssi_threshold_ = -55;
Tim Song 2017/07/07 21:48:24 I would spread out these values out a bit more. Pe
sacomoto 2017/07/10 16:54:07 I spread it a bit more, but I think -30 is really
+ return;
+ case ProximityThreshold::kClose:
+ rssi_threshold_ = -65;
+ return;
+ case ProximityThreshold::kFar:
+ rssi_threshold_ = -75;
+ return;
+ case ProximityThreshold::kVeryFar:
+ rssi_threshold_ = -85;
+ return;
+ }
+}
+
} // namespace proximity_auth

Powered by Google App Engine
This is Rietveld 408576698