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/remote_device_life_cycle_impl.h" | 5 #include "components/proximity_auth/remote_device_life_cycle_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // The UUID of the Bluetooth Low Energy service. | 34 // The UUID of the Bluetooth Low Energy service. |
35 const char kBLESmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; | 35 const char kBLESmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; |
36 | 36 |
37 // The time to wait, in seconds, after authentication fails, before retrying | 37 // The time to wait, in seconds, after authentication fails, before retrying |
38 // another connection. | 38 // another connection. |
39 const int kAuthenticationRecoveryTimeSeconds = 10; | 39 const int kAuthenticationRecoveryTimeSeconds = 10; |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 RemoteDeviceLifeCycleImpl::RemoteDeviceLifeCycleImpl( | 43 RemoteDeviceLifeCycleImpl::RemoteDeviceLifeCycleImpl( |
44 const RemoteDevice& remote_device, | 44 const cryptauth::RemoteDevice& remote_device, |
45 ProximityAuthClient* proximity_auth_client) | 45 ProximityAuthClient* proximity_auth_client) |
46 : remote_device_(remote_device), | 46 : remote_device_(remote_device), |
47 proximity_auth_client_(proximity_auth_client), | 47 proximity_auth_client_(proximity_auth_client), |
48 state_(RemoteDeviceLifeCycle::State::STOPPED), | 48 state_(RemoteDeviceLifeCycle::State::STOPPED), |
49 observers_(base::ObserverList<Observer>::NOTIFY_EXISTING_ONLY), | 49 observers_(base::ObserverList<Observer>::NOTIFY_EXISTING_ONLY), |
50 bluetooth_throttler_(new BluetoothThrottlerImpl( | 50 bluetooth_throttler_(new BluetoothThrottlerImpl( |
51 base::WrapUnique(new base::DefaultTickClock()))), | 51 base::WrapUnique(new base::DefaultTickClock()))), |
52 weak_ptr_factory_(this) {} | 52 weak_ptr_factory_(this) {} |
53 | 53 |
54 RemoteDeviceLifeCycleImpl::~RemoteDeviceLifeCycleImpl() {} | 54 RemoteDeviceLifeCycleImpl::~RemoteDeviceLifeCycleImpl() {} |
55 | 55 |
56 void RemoteDeviceLifeCycleImpl::Start() { | 56 void RemoteDeviceLifeCycleImpl::Start() { |
57 PA_LOG(INFO) << "Life cycle for " << remote_device_.bluetooth_address | 57 PA_LOG(INFO) << "Life cycle for " << remote_device_.bluetooth_address |
58 << " started."; | 58 << " started."; |
59 DCHECK(state_ == RemoteDeviceLifeCycle::State::STOPPED); | 59 DCHECK(state_ == RemoteDeviceLifeCycle::State::STOPPED); |
60 FindConnection(); | 60 FindConnection(); |
61 } | 61 } |
62 | 62 |
63 RemoteDevice RemoteDeviceLifeCycleImpl::GetRemoteDevice() const { | 63 cryptauth::RemoteDevice RemoteDeviceLifeCycleImpl::GetRemoteDevice() const { |
64 return remote_device_; | 64 return remote_device_; |
65 } | 65 } |
66 | 66 |
67 RemoteDeviceLifeCycle::State RemoteDeviceLifeCycleImpl::GetState() const { | 67 RemoteDeviceLifeCycle::State RemoteDeviceLifeCycleImpl::GetState() const { |
68 return state_; | 68 return state_; |
69 } | 69 } |
70 | 70 |
71 Messenger* RemoteDeviceLifeCycleImpl::GetMessenger() { | 71 Messenger* RemoteDeviceLifeCycleImpl::GetMessenger() { |
72 return messenger_.get(); | 72 return messenger_.get(); |
73 } | 73 } |
74 | 74 |
75 void RemoteDeviceLifeCycleImpl::AddObserver(Observer* observer) { | 75 void RemoteDeviceLifeCycleImpl::AddObserver(Observer* observer) { |
76 observers_.AddObserver(observer); | 76 observers_.AddObserver(observer); |
77 } | 77 } |
78 | 78 |
79 void RemoteDeviceLifeCycleImpl::RemoveObserver(Observer* observer) { | 79 void RemoteDeviceLifeCycleImpl::RemoveObserver(Observer* observer) { |
80 observers_.RemoveObserver(observer); | 80 observers_.RemoveObserver(observer); |
81 } | 81 } |
82 | 82 |
83 std::unique_ptr<ConnectionFinder> | 83 std::unique_ptr<ConnectionFinder> |
84 RemoteDeviceLifeCycleImpl::CreateConnectionFinder() { | 84 RemoteDeviceLifeCycleImpl::CreateConnectionFinder() { |
85 if (remote_device_.bluetooth_type == RemoteDevice::BLUETOOTH_LE) { | 85 if (remote_device_.bluetooth_type == cryptauth::RemoteDevice::BLUETOOTH_LE) { |
86 return base::MakeUnique<BluetoothLowEnergyConnectionFinder>( | 86 return base::MakeUnique<BluetoothLowEnergyConnectionFinder>( |
87 remote_device_, kBLESmartLockServiceUUID, | 87 remote_device_, kBLESmartLockServiceUUID, |
88 BluetoothLowEnergyConnectionFinder::FinderStrategy::FIND_PAIRED_DEVICE, | 88 BluetoothLowEnergyConnectionFinder::FinderStrategy::FIND_PAIRED_DEVICE, |
89 nullptr, bluetooth_throttler_.get(), 3); | 89 nullptr, bluetooth_throttler_.get(), 3); |
90 } else { | 90 } else { |
91 return base::MakeUnique<BluetoothConnectionFinder>( | 91 return base::MakeUnique<BluetoothConnectionFinder>( |
92 remote_device_, device::BluetoothUUID(kClassicBluetoothServiceUUID), | 92 remote_device_, device::BluetoothUUID(kClassicBluetoothServiceUUID), |
93 base::TimeDelta::FromSeconds(3)); | 93 base::TimeDelta::FromSeconds(3)); |
94 } | 94 } |
95 } | 95 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 TransitionToState(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); | 166 TransitionToState(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
167 } | 167 } |
168 | 168 |
169 void RemoteDeviceLifeCycleImpl::OnDisconnected() { | 169 void RemoteDeviceLifeCycleImpl::OnDisconnected() { |
170 DCHECK(state_ == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); | 170 DCHECK(state_ == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
171 messenger_.reset(); | 171 messenger_.reset(); |
172 FindConnection(); | 172 FindConnection(); |
173 } | 173 } |
174 | 174 |
175 } // namespace proximity_auth | 175 } // namespace proximity_auth |
OLD | NEW |