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> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
13 #include "components/proximity_auth/proximity_monitor.h" | 14 #include "components/proximity_auth/proximity_monitor.h" |
14 #include "components/proximity_auth/remote_device.h" | 15 #include "components/proximity_auth/remote_device.h" |
15 #include "device/bluetooth/bluetooth_device.h" | 16 #include "device/bluetooth/bluetooth_device.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class TickClock; | 19 class TickClock; |
19 class TimeTicks; | 20 class TimeTicks; |
20 } | 21 } |
21 | 22 |
22 namespace device { | 23 namespace device { |
23 class BluetoothAdapter; | 24 class BluetoothAdapter; |
24 } | 25 } |
25 | 26 |
26 namespace proximity_auth { | 27 namespace proximity_auth { |
27 | 28 |
28 class ProximityMonitorObserver; | 29 class ProximityMonitorObserver; |
29 | 30 |
30 // The concrete implemenation of the proximity monitor interface. | 31 // The concrete implemenation of the proximity monitor interface. |
31 class ProximityMonitorImpl : public ProximityMonitor { | 32 class ProximityMonitorImpl : public ProximityMonitor { |
32 public: | 33 public: |
33 // The |observer| is not owned, and must outlive |this| instance. | 34 // The |observer| is not owned, and must outlive |this| instance. |
34 ProximityMonitorImpl(const RemoteDevice& remote_device, | 35 ProximityMonitorImpl(const RemoteDevice& remote_device, |
35 scoped_ptr<base::TickClock> clock); | 36 std::unique_ptr<base::TickClock> clock); |
36 ~ProximityMonitorImpl() override; | 37 ~ProximityMonitorImpl() override; |
37 | 38 |
38 // ProximityMonitor: | 39 // ProximityMonitor: |
39 void Start() override; | 40 void Start() override; |
40 void Stop() override; | 41 void Stop() override; |
41 Strategy GetStrategy() const override; | 42 Strategy GetStrategy() const override; |
42 bool IsUnlockAllowed() const override; | 43 bool IsUnlockAllowed() const override; |
43 bool IsInRssiRange() const override; | 44 bool IsInRssiRange() const override; |
44 void RecordProximityMetricsOnAuthSuccess() override; | 45 void RecordProximityMetricsOnAuthSuccess() override; |
45 void AddObserver(ProximityMonitorObserver* observer) override; | 46 void AddObserver(ProximityMonitorObserver* observer) override; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 bool remote_device_is_in_proximity_; | 120 bool remote_device_is_in_proximity_; |
120 | 121 |
121 // Whether the proximity monitor is active, i.e. should possibly be scanning | 122 // Whether the proximity monitor is active, i.e. should possibly be scanning |
122 // for proximity to the remote device. | 123 // for proximity to the remote device. |
123 bool is_active_; | 124 bool is_active_; |
124 | 125 |
125 // The exponentailly weighted rolling average of the RSSI, used to smooth the | 126 // The exponentailly weighted rolling average of the RSSI, used to smooth the |
126 // RSSI readings. Null if the monitor is inactive, has not recently observed | 127 // RSSI readings. Null if the monitor is inactive, has not recently observed |
127 // an RSSI reading, or the most recent connection info included an invalid | 128 // an RSSI reading, or the most recent connection info included an invalid |
128 // measurement. | 129 // measurement. |
129 scoped_ptr<double> rssi_rolling_average_; | 130 std::unique_ptr<double> rssi_rolling_average_; |
130 | 131 |
131 // The last TX power reading. Null if the monitor is inactive, has not | 132 // The last TX power reading. Null if the monitor is inactive, has not |
132 // recently observed a TX power reading, or the most recent connection info | 133 // recently observed a TX power reading, or the most recent connection info |
133 // included an invalid measurement. | 134 // included an invalid measurement. |
134 scoped_ptr<TransmitPowerReading> last_transmit_power_reading_; | 135 std::unique_ptr<TransmitPowerReading> last_transmit_power_reading_; |
135 | 136 |
136 // The timestamp of the last zero RSSI reading. An RSSI value of 0 is special | 137 // The timestamp of the last zero RSSI reading. An RSSI value of 0 is special |
137 // because both devices adjust their transmit powers such that the RSSI is in | 138 // because both devices adjust their transmit powers such that the RSSI is in |
138 // this golden range, if possible. Null if the monitor is inactive, has not | 139 // this golden range, if possible. Null if the monitor is inactive, has not |
139 // recently observed an RSSI reading, or the most recent connection info | 140 // recently observed an RSSI reading, or the most recent connection info |
140 // included an invalid measurement. | 141 // included an invalid measurement. |
141 scoped_ptr<base::TimeTicks> last_zero_rssi_timestamp_; | 142 std::unique_ptr<base::TimeTicks> last_zero_rssi_timestamp_; |
142 | 143 |
143 // Used to access non-decreasing time measurements. | 144 // Used to access non-decreasing time measurements. |
144 scoped_ptr<base::TickClock> clock_; | 145 std::unique_ptr<base::TickClock> clock_; |
145 | 146 |
146 // Used to vend weak pointers for polling. Using a separate factory for these | 147 // Used to vend weak pointers for polling. Using a separate factory for these |
147 // weak pointers allows the weak pointers to be invalidated when polling | 148 // weak pointers allows the weak pointers to be invalidated when polling |
148 // stops, which effectively cancels the scheduled tasks. | 149 // stops, which effectively cancels the scheduled tasks. |
149 base::WeakPtrFactory<ProximityMonitorImpl> polling_weak_ptr_factory_; | 150 base::WeakPtrFactory<ProximityMonitorImpl> polling_weak_ptr_factory_; |
150 | 151 |
151 // Used to vend all other weak pointers. | 152 // Used to vend all other weak pointers. |
152 base::WeakPtrFactory<ProximityMonitorImpl> weak_ptr_factory_; | 153 base::WeakPtrFactory<ProximityMonitorImpl> weak_ptr_factory_; |
153 | 154 |
154 DISALLOW_COPY_AND_ASSIGN(ProximityMonitorImpl); | 155 DISALLOW_COPY_AND_ASSIGN(ProximityMonitorImpl); |
155 }; | 156 }; |
156 | 157 |
157 } // namespace proximity_auth | 158 } // namespace proximity_auth |
158 | 159 |
159 #endif // COMPONENTS_PROXIMITY_AUTH_PROXIMITY_MONITOR_IMPL_H | 160 #endif // COMPONENTS_PROXIMITY_AUTH_PROXIMITY_MONITOR_IMPL_H |
OLD | NEW |