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