| 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 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "base/time/tick_clock.h" | 13 #include "base/time/tick_clock.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "components/proximity_auth/logging/logging.h" | 15 #include "components/proximity_auth/logging/logging.h" |
| 16 #include "components/proximity_auth/metrics.h" | 16 #include "components/proximity_auth/metrics.h" |
| 17 #include "components/proximity_auth/proximity_monitor_observer.h" | 17 #include "components/proximity_auth/proximity_monitor_observer.h" |
| 18 #include "device/bluetooth/bluetooth_adapter.h" | 18 #include "device/bluetooth/bluetooth_adapter.h" |
| 19 #include "device/bluetooth/bluetooth_adapter_factory.h" | 19 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 20 | 20 |
| 21 using device::BluetoothDevice; | 21 using device::BluetoothDevice; |
| 22 | 22 |
| 23 namespace proximity_auth { | 23 namespace proximity_auth { |
| 24 | 24 |
| 25 // The time to wait, in milliseconds, between proximity polling iterations. | 25 // The time to wait, in milliseconds, between proximity polling iterations. |
| 26 const int kPollingTimeoutMs = 250; | 26 const int kPollingTimeoutMs = 250; |
| 27 | 27 |
| 28 // The RSSI threshold below which we consider the remote device to not be in | 28 // The RSSI threshold below which we consider the remote device to not be in |
| 29 // proximity. | 29 // proximity. |
| 30 // Tentative value, tested between a cave and Nexus 6 device. | 30 // Note: Because this threshold is unconfigurable right now, it is set quite |
| 31 const int kRssiThreshold = -50; | 31 // conservatively in order to avoid blocking users. |
| 32 const int kRssiThreshold = -70; |
| 32 | 33 |
| 33 // The weight of the most recent RSSI sample. | 34 // The weight of the most recent RSSI sample. |
| 34 const double kRssiSampleWeight = 0.3; | 35 const double kRssiSampleWeight = 0.3; |
| 35 | 36 |
| 36 ProximityMonitorImpl::ProximityMonitorImpl( | 37 ProximityMonitorImpl::ProximityMonitorImpl( |
| 37 cryptauth::Connection* connection, | 38 cryptauth::Connection* connection, |
| 38 std::unique_ptr<base::TickClock> clock) | 39 std::unique_ptr<base::TickClock> clock) |
| 39 : connection_(connection), | 40 : connection_(connection), |
| 40 remote_device_is_in_proximity_(false), | 41 remote_device_is_in_proximity_(false), |
| 41 is_active_(false), | 42 is_active_(false), |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 if (remote_device_is_in_proximity_ != is_now_in_proximity) { | 200 if (remote_device_is_in_proximity_ != is_now_in_proximity) { |
| 200 PA_LOG(INFO) << "[Proximity] Updated proximity state: " | 201 PA_LOG(INFO) << "[Proximity] Updated proximity state: " |
| 201 << (is_now_in_proximity ? "proximate" : "distant"); | 202 << (is_now_in_proximity ? "proximate" : "distant"); |
| 202 remote_device_is_in_proximity_ = is_now_in_proximity; | 203 remote_device_is_in_proximity_ = is_now_in_proximity; |
| 203 for (auto& observer : observers_) | 204 for (auto& observer : observers_) |
| 204 observer.OnProximityStateChanged(); | 205 observer.OnProximityStateChanged(); |
| 205 } | 206 } |
| 206 } | 207 } |
| 207 | 208 |
| 208 } // namespace proximity_auth | 209 } // namespace proximity_auth |
| OLD | NEW |