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

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

Issue 1372283002: 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)
37 : remote_device_(remote_device), 36 : remote_device_(remote_device),
38 observer_(observer),
39 strategy_(Strategy::NONE), 37 strategy_(Strategy::NONE),
40 remote_device_is_in_proximity_(false), 38 remote_device_is_in_proximity_(false),
41 is_active_(false), 39 is_active_(false),
42 clock_(clock.Pass()), 40 clock_(clock.Pass()),
43 polling_weak_ptr_factory_(this), 41 polling_weak_ptr_factory_(this),
44 weak_ptr_factory_(this) { 42 weak_ptr_factory_(this) {
45 if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { 43 if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
46 device::BluetoothAdapterFactory::GetAdapter( 44 device::BluetoothAdapterFactory::GetAdapter(
47 base::Bind(&ProximityMonitorImpl::OnAdapterInitialized, 45 base::Bind(&ProximityMonitorImpl::OnAdapterInitialized,
48 weak_ptr_factory_.GetWeakPtr())); 46 weak_ptr_factory_.GetWeakPtr()));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 std::string remote_device_model = metrics::kUnknownDeviceModel; 103 std::string remote_device_model = metrics::kUnknownDeviceModel;
106 if (remote_device_.name != remote_device_.bluetooth_address) 104 if (remote_device_.name != remote_device_.bluetooth_address)
107 remote_device_model = remote_device_.name; 105 remote_device_model = remote_device_.name;
108 106
109 metrics::RecordAuthProximityRollingRssi(round(rssi_rolling_average)); 107 metrics::RecordAuthProximityRollingRssi(round(rssi_rolling_average));
110 metrics::RecordAuthProximityTransmitPowerDelta(last_transmit_power_delta); 108 metrics::RecordAuthProximityTransmitPowerDelta(last_transmit_power_delta);
111 metrics::RecordAuthProximityTimeSinceLastZeroRssi(time_since_last_zero_rssi); 109 metrics::RecordAuthProximityTimeSinceLastZeroRssi(time_since_last_zero_rssi);
112 metrics::RecordAuthProximityRemoteDeviceModelHash(remote_device_model); 110 metrics::RecordAuthProximityRemoteDeviceModelHash(remote_device_model);
113 } 111 }
114 112
113 void ProximityMonitorImpl::AddObserver(ProximityMonitorObserver* observer) {
114 observers_.AddObserver(observer);
115 }
116
117 void ProximityMonitorImpl::RemoveObserver(ProximityMonitorObserver* observer) {
118 observers_.RemoveObserver(observer);
119 }
120
115 void ProximityMonitorImpl::SetStrategy(Strategy strategy) { 121 void ProximityMonitorImpl::SetStrategy(Strategy strategy) {
116 if (strategy_ == strategy) 122 if (strategy_ == strategy)
117 return; 123 return;
118 strategy_ = strategy; 124 strategy_ = strategy;
119 CheckForProximityStateChange(); 125 CheckForProximityStateChange();
120 UpdatePollingState(); 126 UpdatePollingState();
121 } 127 }
122 128
123 ProximityMonitorImpl::TransmitPowerReading::TransmitPowerReading( 129 ProximityMonitorImpl::TransmitPowerReading::TransmitPowerReading(
124 int transmit_power, 130 int transmit_power,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 << connection_info.rssi << " " 211 << connection_info.rssi << " "
206 << connection_info.transmit_power << " " 212 << connection_info.transmit_power << " "
207 << connection_info.max_transmit_power; 213 << connection_info.max_transmit_power;
208 rssi_rolling_average_.reset(); 214 rssi_rolling_average_.reset();
209 last_transmit_power_reading_.reset(); 215 last_transmit_power_reading_.reset();
210 CheckForProximityStateChange(); 216 CheckForProximityStateChange();
211 } 217 }
212 } 218 }
213 219
214 void ProximityMonitorImpl::ClearProximityState() { 220 void ProximityMonitorImpl::ClearProximityState() {
215 if (is_active_ && remote_device_is_in_proximity_) 221 if (is_active_ && remote_device_is_in_proximity_) {
216 observer_->OnProximityStateChanged(); 222 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_,
223 OnProximityStateChanged());
224 }
217 225
218 remote_device_is_in_proximity_ = false; 226 remote_device_is_in_proximity_ = false;
219 rssi_rolling_average_.reset(); 227 rssi_rolling_average_.reset();
220 last_transmit_power_reading_.reset(); 228 last_transmit_power_reading_.reset();
221 last_zero_rssi_timestamp_.reset(); 229 last_zero_rssi_timestamp_.reset();
222 } 230 }
223 231
224 void ProximityMonitorImpl::AddSample( 232 void ProximityMonitorImpl::AddSample(
225 const BluetoothDevice::ConnectionInfo& connection_info) { 233 const BluetoothDevice::ConnectionInfo& connection_info) {
226 double weight = kRssiSampleWeight; 234 double weight = kRssiSampleWeight;
(...skipping 29 matching lines...) Expand all
256 case Strategy::CHECK_TRANSMIT_POWER: 264 case Strategy::CHECK_TRANSMIT_POWER:
257 is_now_in_proximity = (last_transmit_power_reading_ && 265 is_now_in_proximity = (last_transmit_power_reading_ &&
258 last_transmit_power_reading_->IsInProximity()); 266 last_transmit_power_reading_->IsInProximity());
259 break; 267 break;
260 } 268 }
261 269
262 if (remote_device_is_in_proximity_ != is_now_in_proximity) { 270 if (remote_device_is_in_proximity_ != is_now_in_proximity) {
263 PA_LOG(INFO) << "[Proximity] Updated proximity state: " 271 PA_LOG(INFO) << "[Proximity] Updated proximity state: "
264 << (is_now_in_proximity ? "proximate" : "distant"); 272 << (is_now_in_proximity ? "proximate" : "distant");
265 remote_device_is_in_proximity_ = is_now_in_proximity; 273 remote_device_is_in_proximity_ = is_now_in_proximity;
266 observer_->OnProximityStateChanged(); 274 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_,
275 OnProximityStateChanged());
267 } 276 }
268 } 277 }
269 278
270 } // namespace proximity_auth 279 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698