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

Side by Side Diff: components/proximity_auth/remote_device_life_cycle_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/remote_device_life_cycle_impl.h" 5 #include "components/proximity_auth/remote_device_life_cycle_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "base/time/default_tick_clock.h" 10 #include "base/time/default_tick_clock.h"
(...skipping 25 matching lines...) Expand all
36 const int kAuthenticationRecoveryTimeSeconds = 10; 36 const int kAuthenticationRecoveryTimeSeconds = 10;
37 37
38 } // namespace 38 } // namespace
39 39
40 RemoteDeviceLifeCycleImpl::RemoteDeviceLifeCycleImpl( 40 RemoteDeviceLifeCycleImpl::RemoteDeviceLifeCycleImpl(
41 const RemoteDevice& remote_device, 41 const RemoteDevice& remote_device,
42 ProximityAuthClient* proximity_auth_client) 42 ProximityAuthClient* proximity_auth_client)
43 : remote_device_(remote_device), 43 : remote_device_(remote_device),
44 proximity_auth_client_(proximity_auth_client), 44 proximity_auth_client_(proximity_auth_client),
45 state_(RemoteDeviceLifeCycle::State::STOPPED), 45 state_(RemoteDeviceLifeCycle::State::STOPPED),
46 observers_(base::ObserverList<Observer>::NOTIFY_EXISTING_ONLY),
46 bluetooth_throttler_(new BluetoothThrottlerImpl( 47 bluetooth_throttler_(new BluetoothThrottlerImpl(
47 make_scoped_ptr(new base::DefaultTickClock()))), 48 make_scoped_ptr(new base::DefaultTickClock()))),
48 weak_ptr_factory_(this) {} 49 weak_ptr_factory_(this) {}
49 50
50 RemoteDeviceLifeCycleImpl::~RemoteDeviceLifeCycleImpl() {} 51 RemoteDeviceLifeCycleImpl::~RemoteDeviceLifeCycleImpl() {}
51 52
52 void RemoteDeviceLifeCycleImpl::Start() { 53 void RemoteDeviceLifeCycleImpl::Start() {
53 PA_LOG(INFO) << "Life cycle started."; 54 PA_LOG(INFO) << "Life cycle started.";
54 DCHECK(state_ == RemoteDeviceLifeCycle::State::STOPPED); 55 DCHECK(state_ == RemoteDeviceLifeCycle::State::STOPPED);
55 FindConnection(); 56 FindConnection();
(...skipping 12 matching lines...) Expand all
68 } 69 }
69 70
70 void RemoteDeviceLifeCycleImpl::RemoveObserver(Observer* observer) { 71 void RemoteDeviceLifeCycleImpl::RemoveObserver(Observer* observer) {
71 observers_.RemoveObserver(observer); 72 observers_.RemoveObserver(observer);
72 } 73 }
73 74
74 scoped_ptr<ConnectionFinder> 75 scoped_ptr<ConnectionFinder>
75 RemoteDeviceLifeCycleImpl::CreateConnectionFinder() { 76 RemoteDeviceLifeCycleImpl::CreateConnectionFinder() {
76 // TODO(tengs): We should not rely on the assumption that an empty Bluetooth 77 // TODO(tengs): We should not rely on the assumption that an empty Bluetooth
77 // address means that the device is BLE. 78 // address means that the device is BLE.
78 if (remote_device_.bluetooth_address.empty()) { 79 if (remote_device_.bluetooth_address.empty()) {
sacomoto 2015/09/29 20:58:33 Please use |remove_device_.bluetooth_type| and rem
Tim Song 2015/09/30 00:05:04 Done.
79 return make_scoped_ptr(new BluetoothLowEnergyConnectionFinder( 80 return make_scoped_ptr(new BluetoothLowEnergyConnectionFinder(
80 remote_device_, kBLESmartLockServiceUUID, 81 remote_device_, kBLESmartLockServiceUUID,
81 BluetoothLowEnergyConnectionFinder::FinderStrategy::FIND_PAIRED_DEVICE, 82 BluetoothLowEnergyConnectionFinder::FinderStrategy::FIND_PAIRED_DEVICE,
82 nullptr, bluetooth_throttler_.get(), 3)); 83 nullptr, bluetooth_throttler_.get(), 3));
83 } else { 84 } else {
84 return make_scoped_ptr(new BluetoothConnectionFinder( 85 return make_scoped_ptr(new BluetoothConnectionFinder(
85 remote_device_, device::BluetoothUUID(kClassicBluetoothServiceUUID), 86 remote_device_, device::BluetoothUUID(kClassicBluetoothServiceUUID),
86 base::TimeDelta::FromSeconds(3))); 87 base::TimeDelta::FromSeconds(3)));
87 } 88 }
88 } 89 }
(...skipping 18 matching lines...) Expand all
107 connection_finder_ = CreateConnectionFinder(); 108 connection_finder_ = CreateConnectionFinder();
108 connection_finder_->Find( 109 connection_finder_->Find(
109 base::Bind(&RemoteDeviceLifeCycleImpl::OnConnectionFound, 110 base::Bind(&RemoteDeviceLifeCycleImpl::OnConnectionFound,
110 weak_ptr_factory_.GetWeakPtr())); 111 weak_ptr_factory_.GetWeakPtr()));
111 TransitionToState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION); 112 TransitionToState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
112 } 113 }
113 114
114 void RemoteDeviceLifeCycleImpl::OnConnectionFound( 115 void RemoteDeviceLifeCycleImpl::OnConnectionFound(
115 scoped_ptr<Connection> connection) { 116 scoped_ptr<Connection> connection) {
116 DCHECK(state_ == RemoteDeviceLifeCycle::State::FINDING_CONNECTION); 117 DCHECK(state_ == RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
118 connection_finder_.reset();
117 connection_ = connection.Pass(); 119 connection_ = connection.Pass();
118 authenticator_ = CreateAuthenticator(); 120 authenticator_ = CreateAuthenticator();
119 authenticator_->Authenticate( 121 authenticator_->Authenticate(
120 base::Bind(&RemoteDeviceLifeCycleImpl::OnAuthenticationResult, 122 base::Bind(&RemoteDeviceLifeCycleImpl::OnAuthenticationResult,
121 weak_ptr_factory_.GetWeakPtr())); 123 weak_ptr_factory_.GetWeakPtr()));
122 TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATING); 124 TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATING);
123 } 125 }
124 126
125 void RemoteDeviceLifeCycleImpl::OnAuthenticationResult( 127 void RemoteDeviceLifeCycleImpl::OnAuthenticationResult(
126 Authenticator::Result result, 128 Authenticator::Result result,
127 scoped_ptr<SecureContext> secure_context) { 129 scoped_ptr<SecureContext> secure_context) {
128 DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING); 130 DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING);
131 authenticator_.reset();
129 if (result != Authenticator::Result::SUCCESS) { 132 if (result != Authenticator::Result::SUCCESS) {
130 PA_LOG(WARNING) << "Waiting " << kAuthenticationRecoveryTimeSeconds 133 PA_LOG(WARNING) << "Waiting " << kAuthenticationRecoveryTimeSeconds
131 << " seconds to retry after authentication failure."; 134 << " seconds to retry after authentication failure.";
132 connection_->Disconnect(); 135 connection_->Disconnect();
133 authentication_recovery_timer_.Start( 136 authentication_recovery_timer_.Start(
134 FROM_HERE, 137 FROM_HERE,
135 base::TimeDelta::FromSeconds(kAuthenticationRecoveryTimeSeconds), this, 138 base::TimeDelta::FromSeconds(kAuthenticationRecoveryTimeSeconds), this,
136 &RemoteDeviceLifeCycleImpl::FindConnection); 139 &RemoteDeviceLifeCycleImpl::FindConnection);
137 TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED); 140 TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED);
138 return; 141 return;
139 } 142 }
140 143
141 // Create the MessengerImpl asynchronously. |messenger_| registers itself as 144 // Create the MessengerImpl asynchronously. |messenger_| registers itself as
142 // an 145 // an observer of |connection_|, so creating it synchronously would trigger
143 // observer of |connection_|, so creating it synchronously would 146 // |OnSendComplete()| as an observer call for |messenger_|.
sacomoto 2015/09/29 20:58:33 nit: s/OnSendComplete/OnSendCompleted/.
Tim Song 2015/09/30 00:05:04 Done.
144 // trigger |OnSendComplete()| as an observer call for |messenger_|.
145 secure_context_ = secure_context.Pass(); 147 secure_context_ = secure_context.Pass();
146 base::ThreadTaskRunnerHandle::Get()->PostTask( 148 base::ThreadTaskRunnerHandle::Get()->PostTask(
147 FROM_HERE, base::Bind(&RemoteDeviceLifeCycleImpl::CreateMessenger, 149 FROM_HERE, base::Bind(&RemoteDeviceLifeCycleImpl::CreateMessenger,
148 weak_ptr_factory_.GetWeakPtr())); 150 weak_ptr_factory_.GetWeakPtr()));
149 } 151 }
150 152
151 void RemoteDeviceLifeCycleImpl::CreateMessenger() { 153 void RemoteDeviceLifeCycleImpl::CreateMessenger() {
152 DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING); 154 DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING);
153 DCHECK(secure_context_); 155 DCHECK(secure_context_);
154 messenger_.reset( 156 messenger_.reset(
155 new MessengerImpl(connection_.Pass(), secure_context_.Pass())); 157 new MessengerImpl(connection_.Pass(), secure_context_.Pass()));
156 messenger_->AddObserver(this); 158 messenger_->AddObserver(this);
157 159
158 TransitionToState(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); 160 TransitionToState(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
159 } 161 }
160 162
161 void RemoteDeviceLifeCycleImpl::OnDisconnected() { 163 void RemoteDeviceLifeCycleImpl::OnDisconnected() {
162 DCHECK(state_ == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); 164 DCHECK(state_ == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
165 messenger_.reset();
163 FindConnection(); 166 FindConnection();
164 } 167 }
165 168
166 } // namespace proximity_auth 169 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698