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" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
13 #include "base/time/default_tick_clock.h" | 13 #include "base/time/default_tick_clock.h" |
| 14 #include "components/cryptauth/bluetooth_throttler_impl.h" |
| 15 #include "components/cryptauth/connection_finder.h" |
14 #include "components/cryptauth/secure_message_delegate.h" | 16 #include "components/cryptauth/secure_message_delegate.h" |
15 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" | 17 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" |
16 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
" | 18 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
" |
17 #include "components/proximity_auth/bluetooth_connection.h" | 19 #include "components/proximity_auth/bluetooth_connection.h" |
18 #include "components/proximity_auth/bluetooth_connection_finder.h" | 20 #include "components/proximity_auth/bluetooth_connection_finder.h" |
19 #include "components/proximity_auth/bluetooth_throttler_impl.h" | |
20 #include "components/proximity_auth/device_to_device_authenticator.h" | 21 #include "components/proximity_auth/device_to_device_authenticator.h" |
21 #include "components/proximity_auth/logging/logging.h" | 22 #include "components/proximity_auth/logging/logging.h" |
22 #include "components/proximity_auth/messenger_impl.h" | 23 #include "components/proximity_auth/messenger_impl.h" |
23 #include "components/proximity_auth/proximity_auth_client.h" | 24 #include "components/proximity_auth/proximity_auth_client.h" |
24 #include "components/proximity_auth/secure_context.h" | 25 #include "components/proximity_auth/secure_context.h" |
25 | 26 |
26 namespace proximity_auth { | 27 namespace proximity_auth { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
(...skipping 10 matching lines...) Expand all Loading... |
40 | 41 |
41 } // namespace | 42 } // namespace |
42 | 43 |
43 RemoteDeviceLifeCycleImpl::RemoteDeviceLifeCycleImpl( | 44 RemoteDeviceLifeCycleImpl::RemoteDeviceLifeCycleImpl( |
44 const cryptauth::RemoteDevice& remote_device, | 45 const cryptauth::RemoteDevice& remote_device, |
45 ProximityAuthClient* proximity_auth_client) | 46 ProximityAuthClient* proximity_auth_client) |
46 : remote_device_(remote_device), | 47 : remote_device_(remote_device), |
47 proximity_auth_client_(proximity_auth_client), | 48 proximity_auth_client_(proximity_auth_client), |
48 state_(RemoteDeviceLifeCycle::State::STOPPED), | 49 state_(RemoteDeviceLifeCycle::State::STOPPED), |
49 observers_(base::ObserverList<Observer>::NOTIFY_EXISTING_ONLY), | 50 observers_(base::ObserverList<Observer>::NOTIFY_EXISTING_ONLY), |
50 bluetooth_throttler_(new BluetoothThrottlerImpl( | 51 bluetooth_throttler_(new cryptauth::BluetoothThrottlerImpl( |
51 base::WrapUnique(new base::DefaultTickClock()))), | 52 base::WrapUnique(new base::DefaultTickClock()))), |
52 weak_ptr_factory_(this) {} | 53 weak_ptr_factory_(this) {} |
53 | 54 |
54 RemoteDeviceLifeCycleImpl::~RemoteDeviceLifeCycleImpl() {} | 55 RemoteDeviceLifeCycleImpl::~RemoteDeviceLifeCycleImpl() {} |
55 | 56 |
56 void RemoteDeviceLifeCycleImpl::Start() { | 57 void RemoteDeviceLifeCycleImpl::Start() { |
57 PA_LOG(INFO) << "Life cycle for " << remote_device_.bluetooth_address | 58 PA_LOG(INFO) << "Life cycle for " << remote_device_.bluetooth_address |
58 << " started."; | 59 << " started."; |
59 DCHECK(state_ == RemoteDeviceLifeCycle::State::STOPPED); | 60 DCHECK(state_ == RemoteDeviceLifeCycle::State::STOPPED); |
60 FindConnection(); | 61 FindConnection(); |
(...skipping 12 matching lines...) Expand all Loading... |
73 } | 74 } |
74 | 75 |
75 void RemoteDeviceLifeCycleImpl::AddObserver(Observer* observer) { | 76 void RemoteDeviceLifeCycleImpl::AddObserver(Observer* observer) { |
76 observers_.AddObserver(observer); | 77 observers_.AddObserver(observer); |
77 } | 78 } |
78 | 79 |
79 void RemoteDeviceLifeCycleImpl::RemoveObserver(Observer* observer) { | 80 void RemoteDeviceLifeCycleImpl::RemoveObserver(Observer* observer) { |
80 observers_.RemoveObserver(observer); | 81 observers_.RemoveObserver(observer); |
81 } | 82 } |
82 | 83 |
83 std::unique_ptr<ConnectionFinder> | 84 std::unique_ptr<cryptauth::ConnectionFinder> |
84 RemoteDeviceLifeCycleImpl::CreateConnectionFinder() { | 85 RemoteDeviceLifeCycleImpl::CreateConnectionFinder() { |
85 if (remote_device_.bluetooth_type == cryptauth::RemoteDevice::BLUETOOTH_LE) { | 86 if (remote_device_.bluetooth_type == cryptauth::RemoteDevice::BLUETOOTH_LE) { |
86 return base::MakeUnique<BluetoothLowEnergyConnectionFinder>( | 87 return base::MakeUnique<BluetoothLowEnergyConnectionFinder>( |
87 remote_device_, kBLESmartLockServiceUUID, | 88 remote_device_, kBLESmartLockServiceUUID, |
88 BluetoothLowEnergyConnectionFinder::FinderStrategy::FIND_PAIRED_DEVICE, | 89 BluetoothLowEnergyConnectionFinder::FinderStrategy::FIND_PAIRED_DEVICE, |
89 nullptr, bluetooth_throttler_.get(), 3); | 90 nullptr, bluetooth_throttler_.get(), 3); |
90 } else { | 91 } else { |
91 return base::MakeUnique<BluetoothConnectionFinder>( | 92 return base::MakeUnique<BluetoothConnectionFinder>( |
92 remote_device_, device::BluetoothUUID(kClassicBluetoothServiceUUID), | 93 remote_device_, device::BluetoothUUID(kClassicBluetoothServiceUUID), |
93 base::TimeDelta::FromSeconds(3)); | 94 base::TimeDelta::FromSeconds(3)); |
(...skipping 19 matching lines...) Expand all Loading... |
113 | 114 |
114 void RemoteDeviceLifeCycleImpl::FindConnection() { | 115 void RemoteDeviceLifeCycleImpl::FindConnection() { |
115 connection_finder_ = CreateConnectionFinder(); | 116 connection_finder_ = CreateConnectionFinder(); |
116 connection_finder_->Find( | 117 connection_finder_->Find( |
117 base::Bind(&RemoteDeviceLifeCycleImpl::OnConnectionFound, | 118 base::Bind(&RemoteDeviceLifeCycleImpl::OnConnectionFound, |
118 weak_ptr_factory_.GetWeakPtr())); | 119 weak_ptr_factory_.GetWeakPtr())); |
119 TransitionToState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION); | 120 TransitionToState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION); |
120 } | 121 } |
121 | 122 |
122 void RemoteDeviceLifeCycleImpl::OnConnectionFound( | 123 void RemoteDeviceLifeCycleImpl::OnConnectionFound( |
123 std::unique_ptr<Connection> connection) { | 124 std::unique_ptr<cryptauth::Connection> connection) { |
124 DCHECK(state_ == RemoteDeviceLifeCycle::State::FINDING_CONNECTION); | 125 DCHECK(state_ == RemoteDeviceLifeCycle::State::FINDING_CONNECTION); |
125 connection_ = std::move(connection); | 126 connection_ = std::move(connection); |
126 authenticator_ = CreateAuthenticator(); | 127 authenticator_ = CreateAuthenticator(); |
127 authenticator_->Authenticate( | 128 authenticator_->Authenticate( |
128 base::Bind(&RemoteDeviceLifeCycleImpl::OnAuthenticationResult, | 129 base::Bind(&RemoteDeviceLifeCycleImpl::OnAuthenticationResult, |
129 weak_ptr_factory_.GetWeakPtr())); | 130 weak_ptr_factory_.GetWeakPtr())); |
130 TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATING); | 131 TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATING); |
131 } | 132 } |
132 | 133 |
133 void RemoteDeviceLifeCycleImpl::OnAuthenticationResult( | 134 void RemoteDeviceLifeCycleImpl::OnAuthenticationResult( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 TransitionToState(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); | 167 TransitionToState(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
167 } | 168 } |
168 | 169 |
169 void RemoteDeviceLifeCycleImpl::OnDisconnected() { | 170 void RemoteDeviceLifeCycleImpl::OnDisconnected() { |
170 DCHECK(state_ == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); | 171 DCHECK(state_ == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); |
171 messenger_.reset(); | 172 messenger_.reset(); |
172 FindConnection(); | 173 FindConnection(); |
173 } | 174 } |
174 | 175 |
175 } // namespace proximity_auth | 176 } // namespace proximity_auth |
OLD | NEW |