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

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

Powered by Google App Engine
This is Rietveld 408576698