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

Side by Side Diff: components/proximity_auth/proximity_monitor_impl.h

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 unified diff | Download patch
OLDNEW
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 #ifndef COMPONENTS_PROXIMITY_AUTH_PROXIMITY_MONITOR_IMPL_H 5 #ifndef COMPONENTS_PROXIMITY_AUTH_PROXIMITY_MONITOR_IMPL_H
6 #define COMPONENTS_PROXIMITY_AUTH_PROXIMITY_MONITOR_IMPL_H 6 #define COMPONENTS_PROXIMITY_AUTH_PROXIMITY_MONITOR_IMPL_H
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "components/cryptauth/connection.h" 14 #include "components/cryptauth/connection.h"
15 #include "components/cryptauth/remote_device.h" 15 #include "components/cryptauth/remote_device.h"
16 #include "components/proximity_auth/proximity_monitor.h" 16 #include "components/proximity_auth/proximity_monitor.h"
17 #include "device/bluetooth/bluetooth_device.h" 17 #include "device/bluetooth/bluetooth_device.h"
18 18
19 class PrefService;
20
19 namespace base { 21 namespace base {
20 class TickClock; 22 class TickClock;
21 } 23 }
22 24
23 namespace device { 25 namespace device {
24 class BluetoothAdapter; 26 class BluetoothAdapter;
25 } 27 }
26 28
27 namespace proximity_auth { 29 namespace proximity_auth {
28 30
31 class ProximityAuthPrefManager;
29 class ProximityMonitorObserver; 32 class ProximityMonitorObserver;
30 33
31 // The concrete implemenation of the proximity monitor interface. 34 // The concrete implemenation of the proximity monitor interface.
32 class ProximityMonitorImpl : public ProximityMonitor { 35 class ProximityMonitorImpl : public ProximityMonitor {
33 public: 36 public:
34 // The |connection| is not owned, and must outlive |this| instance. 37 // The |connection| is not owned, and must outlive |this| instance.
35 ProximityMonitorImpl(cryptauth::Connection* connection, 38 ProximityMonitorImpl(cryptauth::Connection* connection,
36 std::unique_ptr<base::TickClock> clock); 39 std::unique_ptr<base::TickClock> clock,
40 std::unique_ptr<ProximityAuthPrefManager> pref_manager);
37 ~ProximityMonitorImpl() override; 41 ~ProximityMonitorImpl() override;
38 42
39 // ProximityMonitor: 43 // ProximityMonitor:
40 void Start() override; 44 void Start() override;
41 void Stop() override; 45 void Stop() override;
42 bool IsUnlockAllowed() const override; 46 bool IsUnlockAllowed() const override;
43 void RecordProximityMetricsOnAuthSuccess() override; 47 void RecordProximityMetricsOnAuthSuccess() override;
44 void AddObserver(ProximityMonitorObserver* observer) override; 48 void AddObserver(ProximityMonitorObserver* observer) override;
45 void RemoveObserver(ProximityMonitorObserver* observer) override; 49 void RemoveObserver(ProximityMonitorObserver* observer) override;
46 50
(...skipping 28 matching lines...) Expand all
75 79
76 // Updates the proximity state with a new |connection_info| sample of the 80 // Updates the proximity state with a new |connection_info| sample of the
77 // current RSSI. 81 // current RSSI.
78 void AddSample( 82 void AddSample(
79 const device::BluetoothDevice::ConnectionInfo& connection_info); 83 const device::BluetoothDevice::ConnectionInfo& connection_info);
80 84
81 // Checks whether the proximity state has changed based on the current 85 // Checks whether the proximity state has changed based on the current
82 // samples. Notifies |observers_| on a change. 86 // samples. Notifies |observers_| on a change.
83 void CheckForProximityStateChange(); 87 void CheckForProximityStateChange();
84 88
89 // Gets the user-selected proximity threshold and converts it to a
90 // RSSI value.
91 void GetRssiThresholdFromPrefs();
92
85 // The current connection being monitored. Not owned and must outlive this 93 // The current connection being monitored. Not owned and must outlive this
86 // instance. 94 // instance.
87 cryptauth::Connection* connection_; 95 cryptauth::Connection* connection_;
88 96
89 // The observers attached to the ProximityMonitor. 97 // The observers attached to the ProximityMonitor.
90 base::ObserverList<ProximityMonitorObserver> observers_; 98 base::ObserverList<ProximityMonitorObserver> observers_;
91 99
92 // The Bluetooth adapter that will be polled for connection info. 100 // The Bluetooth adapter that will be polled for connection info.
93 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; 101 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_;
94 102
95 // Whether the remote device is currently in close proximity to the local 103 // Whether the remote device is currently in close proximity to the local
96 // device. 104 // device.
97 bool remote_device_is_in_proximity_; 105 bool remote_device_is_in_proximity_;
98 106
99 // Whether the proximity monitor is active, i.e. should possibly be scanning 107 // Whether the proximity monitor is active, i.e. should possibly be scanning
100 // for proximity to the remote device. 108 // for proximity to the remote device.
101 bool is_active_; 109 bool is_active_;
102 110
111 // When the RSSI is below this value the phone the unlock is not allowed.
112 int rssi_threshold_;
113
103 // The exponentailly weighted rolling average of the RSSI, used to smooth the 114 // The exponentailly weighted rolling average of the RSSI, used to smooth the
104 // RSSI readings. Null if the monitor is inactive, has not recently observed 115 // RSSI readings. Null if the monitor is inactive, has not recently observed
105 // an RSSI reading, or the most recent connection info included an invalid 116 // an RSSI reading, or the most recent connection info included an invalid
106 // measurement. 117 // measurement.
107 std::unique_ptr<double> rssi_rolling_average_; 118 std::unique_ptr<double> rssi_rolling_average_;
108 119
109 // Used to access non-decreasing time measurements. 120 // Used to access non-decreasing time measurements.
110 std::unique_ptr<base::TickClock> clock_; 121 std::unique_ptr<base::TickClock> clock_;
111 122
123 // Contains perferences that outlive the lifetime of this object and across
124 // process restarts. Not owned and must outlive this instance.
125 std::unique_ptr<ProximityAuthPrefManager> pref_manager_;
126
112 // Used to vend weak pointers for polling. Using a separate factory for these 127 // Used to vend weak pointers for polling. Using a separate factory for these
113 // weak pointers allows the weak pointers to be invalidated when polling 128 // weak pointers allows the weak pointers to be invalidated when polling
114 // stops, which effectively cancels the scheduled tasks. 129 // stops, which effectively cancels the scheduled tasks.
115 base::WeakPtrFactory<ProximityMonitorImpl> polling_weak_ptr_factory_; 130 base::WeakPtrFactory<ProximityMonitorImpl> polling_weak_ptr_factory_;
116 131
117 // Used to vend all other weak pointers. 132 // Used to vend all other weak pointers.
118 base::WeakPtrFactory<ProximityMonitorImpl> weak_ptr_factory_; 133 base::WeakPtrFactory<ProximityMonitorImpl> weak_ptr_factory_;
119 134
120 DISALLOW_COPY_AND_ASSIGN(ProximityMonitorImpl); 135 DISALLOW_COPY_AND_ASSIGN(ProximityMonitorImpl);
121 }; 136 };
122 137
123 } // namespace proximity_auth 138 } // namespace proximity_auth
124 139
125 #endif // COMPONENTS_PROXIMITY_AUTH_PROXIMITY_MONITOR_IMPL_H 140 #endif // COMPONENTS_PROXIMITY_AUTH_PROXIMITY_MONITOR_IMPL_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698