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 #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 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/location.h" | 11 #include "base/location.h" |
11 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
12 #include "base/time/tick_clock.h" | 13 #include "base/time/tick_clock.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "components/proximity_auth/logging/logging.h" | 15 #include "components/proximity_auth/logging/logging.h" |
15 #include "components/proximity_auth/metrics.h" | 16 #include "components/proximity_auth/metrics.h" |
16 #include "components/proximity_auth/proximity_monitor_observer.h" | 17 #include "components/proximity_auth/proximity_monitor_observer.h" |
17 #include "device/bluetooth/bluetooth_adapter.h" | 18 #include "device/bluetooth/bluetooth_adapter.h" |
(...skipping 12 matching lines...) Expand all Loading... |
30 | 31 |
31 // The weight of the most recent RSSI sample. | 32 // The weight of the most recent RSSI sample. |
32 const double kRssiSampleWeight = 0.3; | 33 const double kRssiSampleWeight = 0.3; |
33 | 34 |
34 ProximityMonitorImpl::ProximityMonitorImpl(const RemoteDevice& remote_device, | 35 ProximityMonitorImpl::ProximityMonitorImpl(const RemoteDevice& remote_device, |
35 scoped_ptr<base::TickClock> clock) | 36 scoped_ptr<base::TickClock> clock) |
36 : remote_device_(remote_device), | 37 : remote_device_(remote_device), |
37 strategy_(Strategy::NONE), | 38 strategy_(Strategy::NONE), |
38 remote_device_is_in_proximity_(false), | 39 remote_device_is_in_proximity_(false), |
39 is_active_(false), | 40 is_active_(false), |
40 clock_(clock.Pass()), | 41 clock_(std::move(clock)), |
41 polling_weak_ptr_factory_(this), | 42 polling_weak_ptr_factory_(this), |
42 weak_ptr_factory_(this) { | 43 weak_ptr_factory_(this) { |
43 if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { | 44 if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { |
44 device::BluetoothAdapterFactory::GetAdapter( | 45 device::BluetoothAdapterFactory::GetAdapter( |
45 base::Bind(&ProximityMonitorImpl::OnAdapterInitialized, | 46 base::Bind(&ProximityMonitorImpl::OnAdapterInitialized, |
46 weak_ptr_factory_.GetWeakPtr())); | 47 weak_ptr_factory_.GetWeakPtr())); |
47 } else { | 48 } else { |
48 PA_LOG(ERROR) << "[Proximity] Proximity monitoring unavailable: " | 49 PA_LOG(ERROR) << "[Proximity] Proximity monitoring unavailable: " |
49 << "Bluetooth is unsupported on this platform."; | 50 << "Bluetooth is unsupported on this platform."; |
50 } | 51 } |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 if (remote_device_is_in_proximity_ != is_now_in_proximity) { | 271 if (remote_device_is_in_proximity_ != is_now_in_proximity) { |
271 PA_LOG(INFO) << "[Proximity] Updated proximity state: " | 272 PA_LOG(INFO) << "[Proximity] Updated proximity state: " |
272 << (is_now_in_proximity ? "proximate" : "distant"); | 273 << (is_now_in_proximity ? "proximate" : "distant"); |
273 remote_device_is_in_proximity_ = is_now_in_proximity; | 274 remote_device_is_in_proximity_ = is_now_in_proximity; |
274 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_, | 275 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_, |
275 OnProximityStateChanged()); | 276 OnProximityStateChanged()); |
276 } | 277 } |
277 } | 278 } |
278 | 279 |
279 } // namespace proximity_auth | 280 } // namespace proximity_auth |
OLD | NEW |