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

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

Issue 1377313002: Revert of Hook up ProximityAuthSystem in EasyUnlockService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth_connection
Patch Set: Created 5 years, 2 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 #include "components/proximity_auth/proximity_monitor_impl.h" 5 #include "components/proximity_auth/proximity_monitor_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 14 matching lines...) Expand all
25 const int kPollingTimeoutMs = 250; 25 const int kPollingTimeoutMs = 250;
26 26
27 // The RSSI threshold below which we consider the remote device to not be in 27 // The RSSI threshold below which we consider the remote device to not be in
28 // proximity. 28 // proximity.
29 const int kRssiThreshold = -5; 29 const int kRssiThreshold = -5;
30 30
31 // The weight of the most recent RSSI sample. 31 // The weight of the most recent RSSI sample.
32 const double kRssiSampleWeight = 0.3; 32 const double kRssiSampleWeight = 0.3;
33 33
34 ProximityMonitorImpl::ProximityMonitorImpl(const RemoteDevice& remote_device, 34 ProximityMonitorImpl::ProximityMonitorImpl(const RemoteDevice& remote_device,
35 scoped_ptr<base::TickClock> clock) 35 scoped_ptr<base::TickClock> clock,
36 ProximityMonitorObserver* observer)
36 : remote_device_(remote_device), 37 : remote_device_(remote_device),
38 observer_(observer),
37 strategy_(Strategy::NONE), 39 strategy_(Strategy::NONE),
38 remote_device_is_in_proximity_(false), 40 remote_device_is_in_proximity_(false),
39 is_active_(false), 41 is_active_(false),
40 clock_(clock.Pass()), 42 clock_(clock.Pass()),
41 polling_weak_ptr_factory_(this), 43 polling_weak_ptr_factory_(this),
42 weak_ptr_factory_(this) { 44 weak_ptr_factory_(this) {
43 if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { 45 if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
44 device::BluetoothAdapterFactory::GetAdapter( 46 device::BluetoothAdapterFactory::GetAdapter(
45 base::Bind(&ProximityMonitorImpl::OnAdapterInitialized, 47 base::Bind(&ProximityMonitorImpl::OnAdapterInitialized,
46 weak_ptr_factory_.GetWeakPtr())); 48 weak_ptr_factory_.GetWeakPtr()));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 std::string remote_device_model = metrics::kUnknownDeviceModel; 105 std::string remote_device_model = metrics::kUnknownDeviceModel;
104 if (remote_device_.name != remote_device_.bluetooth_address) 106 if (remote_device_.name != remote_device_.bluetooth_address)
105 remote_device_model = remote_device_.name; 107 remote_device_model = remote_device_.name;
106 108
107 metrics::RecordAuthProximityRollingRssi(round(rssi_rolling_average)); 109 metrics::RecordAuthProximityRollingRssi(round(rssi_rolling_average));
108 metrics::RecordAuthProximityTransmitPowerDelta(last_transmit_power_delta); 110 metrics::RecordAuthProximityTransmitPowerDelta(last_transmit_power_delta);
109 metrics::RecordAuthProximityTimeSinceLastZeroRssi(time_since_last_zero_rssi); 111 metrics::RecordAuthProximityTimeSinceLastZeroRssi(time_since_last_zero_rssi);
110 metrics::RecordAuthProximityRemoteDeviceModelHash(remote_device_model); 112 metrics::RecordAuthProximityRemoteDeviceModelHash(remote_device_model);
111 } 113 }
112 114
113 void ProximityMonitorImpl::AddObserver(ProximityMonitorObserver* observer) {
114 observers_.AddObserver(observer);
115 }
116
117 void ProximityMonitorImpl::RemoveObserver(ProximityMonitorObserver* observer) {
118 observers_.RemoveObserver(observer);
119 }
120
121 void ProximityMonitorImpl::SetStrategy(Strategy strategy) { 115 void ProximityMonitorImpl::SetStrategy(Strategy strategy) {
122 if (strategy_ == strategy) 116 if (strategy_ == strategy)
123 return; 117 return;
124 strategy_ = strategy; 118 strategy_ = strategy;
125 CheckForProximityStateChange(); 119 CheckForProximityStateChange();
126 UpdatePollingState(); 120 UpdatePollingState();
127 } 121 }
128 122
129 ProximityMonitorImpl::TransmitPowerReading::TransmitPowerReading( 123 ProximityMonitorImpl::TransmitPowerReading::TransmitPowerReading(
130 int transmit_power, 124 int transmit_power,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 << connection_info.rssi << " " 205 << connection_info.rssi << " "
212 << connection_info.transmit_power << " " 206 << connection_info.transmit_power << " "
213 << connection_info.max_transmit_power; 207 << connection_info.max_transmit_power;
214 rssi_rolling_average_.reset(); 208 rssi_rolling_average_.reset();
215 last_transmit_power_reading_.reset(); 209 last_transmit_power_reading_.reset();
216 CheckForProximityStateChange(); 210 CheckForProximityStateChange();
217 } 211 }
218 } 212 }
219 213
220 void ProximityMonitorImpl::ClearProximityState() { 214 void ProximityMonitorImpl::ClearProximityState() {
221 if (is_active_ && remote_device_is_in_proximity_) { 215 if (is_active_ && remote_device_is_in_proximity_)
222 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_, 216 observer_->OnProximityStateChanged();
223 OnProximityStateChanged());
224 }
225 217
226 remote_device_is_in_proximity_ = false; 218 remote_device_is_in_proximity_ = false;
227 rssi_rolling_average_.reset(); 219 rssi_rolling_average_.reset();
228 last_transmit_power_reading_.reset(); 220 last_transmit_power_reading_.reset();
229 last_zero_rssi_timestamp_.reset(); 221 last_zero_rssi_timestamp_.reset();
230 } 222 }
231 223
232 void ProximityMonitorImpl::AddSample( 224 void ProximityMonitorImpl::AddSample(
233 const BluetoothDevice::ConnectionInfo& connection_info) { 225 const BluetoothDevice::ConnectionInfo& connection_info) {
234 double weight = kRssiSampleWeight; 226 double weight = kRssiSampleWeight;
(...skipping 29 matching lines...) Expand all
264 case Strategy::CHECK_TRANSMIT_POWER: 256 case Strategy::CHECK_TRANSMIT_POWER:
265 is_now_in_proximity = (last_transmit_power_reading_ && 257 is_now_in_proximity = (last_transmit_power_reading_ &&
266 last_transmit_power_reading_->IsInProximity()); 258 last_transmit_power_reading_->IsInProximity());
267 break; 259 break;
268 } 260 }
269 261
270 if (remote_device_is_in_proximity_ != is_now_in_proximity) { 262 if (remote_device_is_in_proximity_ != is_now_in_proximity) {
271 PA_LOG(INFO) << "[Proximity] Updated proximity state: " 263 PA_LOG(INFO) << "[Proximity] Updated proximity state: "
272 << (is_now_in_proximity ? "proximate" : "distant"); 264 << (is_now_in_proximity ? "proximate" : "distant");
273 remote_device_is_in_proximity_ = is_now_in_proximity; 265 remote_device_is_in_proximity_ = is_now_in_proximity;
274 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_, 266 observer_->OnProximityStateChanged();
275 OnProximityStateChanged());
276 } 267 }
277 } 268 }
278 269
279 } // namespace proximity_auth 270 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/proximity_monitor_impl.h ('k') | components/proximity_auth/proximity_monitor_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698