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

Side by Side Diff: components/proximity_auth/remote_device_life_cycle_impl.cc

Issue 1377313002: Revert of 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),
47 bluetooth_throttler_(new BluetoothThrottlerImpl( 46 bluetooth_throttler_(new BluetoothThrottlerImpl(
48 make_scoped_ptr(new base::DefaultTickClock()))), 47 make_scoped_ptr(new base::DefaultTickClock()))),
49 weak_ptr_factory_(this) {} 48 weak_ptr_factory_(this) {}
50 49
51 RemoteDeviceLifeCycleImpl::~RemoteDeviceLifeCycleImpl() {} 50 RemoteDeviceLifeCycleImpl::~RemoteDeviceLifeCycleImpl() {}
52 51
53 void RemoteDeviceLifeCycleImpl::Start() { 52 void RemoteDeviceLifeCycleImpl::Start() {
54 PA_LOG(INFO) << "Life cycle started."; 53 PA_LOG(INFO) << "Life cycle started.";
55 DCHECK(state_ == RemoteDeviceLifeCycle::State::STOPPED); 54 DCHECK(state_ == RemoteDeviceLifeCycle::State::STOPPED);
56 FindConnection(); 55 FindConnection();
(...skipping 10 matching lines...) Expand all
67 void RemoteDeviceLifeCycleImpl::AddObserver(Observer* observer) { 66 void RemoteDeviceLifeCycleImpl::AddObserver(Observer* observer) {
68 observers_.AddObserver(observer); 67 observers_.AddObserver(observer);
69 } 68 }
70 69
71 void RemoteDeviceLifeCycleImpl::RemoveObserver(Observer* observer) { 70 void RemoteDeviceLifeCycleImpl::RemoveObserver(Observer* observer) {
72 observers_.RemoveObserver(observer); 71 observers_.RemoveObserver(observer);
73 } 72 }
74 73
75 scoped_ptr<ConnectionFinder> 74 scoped_ptr<ConnectionFinder>
76 RemoteDeviceLifeCycleImpl::CreateConnectionFinder() { 75 RemoteDeviceLifeCycleImpl::CreateConnectionFinder() {
77 if (remote_device_.bluetooth_type == RemoteDevice::BLUETOOTH_LE) { 76 // TODO(tengs): We should not rely on the assumption that an empty Bluetooth
77 // address means that the device is BLE.
78 if (remote_device_.bluetooth_address.empty()) {
78 return make_scoped_ptr(new BluetoothLowEnergyConnectionFinder( 79 return make_scoped_ptr(new BluetoothLowEnergyConnectionFinder(
79 remote_device_, kBLESmartLockServiceUUID, 80 remote_device_, kBLESmartLockServiceUUID,
80 BluetoothLowEnergyConnectionFinder::FinderStrategy::FIND_PAIRED_DEVICE, 81 BluetoothLowEnergyConnectionFinder::FinderStrategy::FIND_PAIRED_DEVICE,
81 nullptr, bluetooth_throttler_.get(), 3)); 82 nullptr, bluetooth_throttler_.get(), 3));
82 } else { 83 } else {
83 return make_scoped_ptr(new BluetoothConnectionFinder( 84 return make_scoped_ptr(new BluetoothConnectionFinder(
84 remote_device_, device::BluetoothUUID(kClassicBluetoothServiceUUID), 85 remote_device_, device::BluetoothUUID(kClassicBluetoothServiceUUID),
85 base::TimeDelta::FromSeconds(3))); 86 base::TimeDelta::FromSeconds(3)));
86 } 87 }
87 } 88 }
(...skipping 30 matching lines...) Expand all
118 authenticator_->Authenticate( 119 authenticator_->Authenticate(
119 base::Bind(&RemoteDeviceLifeCycleImpl::OnAuthenticationResult, 120 base::Bind(&RemoteDeviceLifeCycleImpl::OnAuthenticationResult,
120 weak_ptr_factory_.GetWeakPtr())); 121 weak_ptr_factory_.GetWeakPtr()));
121 TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATING); 122 TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATING);
122 } 123 }
123 124
124 void RemoteDeviceLifeCycleImpl::OnAuthenticationResult( 125 void RemoteDeviceLifeCycleImpl::OnAuthenticationResult(
125 Authenticator::Result result, 126 Authenticator::Result result,
126 scoped_ptr<SecureContext> secure_context) { 127 scoped_ptr<SecureContext> secure_context) {
127 DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING); 128 DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING);
128 authenticator_.reset();
129 if (result != Authenticator::Result::SUCCESS) { 129 if (result != Authenticator::Result::SUCCESS) {
130 PA_LOG(WARNING) << "Waiting " << kAuthenticationRecoveryTimeSeconds 130 PA_LOG(WARNING) << "Waiting " << kAuthenticationRecoveryTimeSeconds
131 << " seconds to retry after authentication failure."; 131 << " seconds to retry after authentication failure.";
132 connection_->Disconnect(); 132 connection_->Disconnect();
133 authentication_recovery_timer_.Start( 133 authentication_recovery_timer_.Start(
134 FROM_HERE, 134 FROM_HERE,
135 base::TimeDelta::FromSeconds(kAuthenticationRecoveryTimeSeconds), this, 135 base::TimeDelta::FromSeconds(kAuthenticationRecoveryTimeSeconds), this,
136 &RemoteDeviceLifeCycleImpl::FindConnection); 136 &RemoteDeviceLifeCycleImpl::FindConnection);
137 TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED); 137 TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED);
138 return; 138 return;
139 } 139 }
140 140
141 // Create the MessengerImpl asynchronously. |messenger_| registers itself as 141 // Create the MessengerImpl asynchronously. |messenger_| registers itself as
142 // an observer of |connection_|, so creating it synchronously would trigger 142 // an
143 // |OnSendCompleted()| as an observer call for |messenger_|. 143 // observer of |connection_|, so creating it synchronously would
144 // trigger |OnSendComplete()| as an observer call for |messenger_|.
144 secure_context_ = secure_context.Pass(); 145 secure_context_ = secure_context.Pass();
145 base::ThreadTaskRunnerHandle::Get()->PostTask( 146 base::ThreadTaskRunnerHandle::Get()->PostTask(
146 FROM_HERE, base::Bind(&RemoteDeviceLifeCycleImpl::CreateMessenger, 147 FROM_HERE, base::Bind(&RemoteDeviceLifeCycleImpl::CreateMessenger,
147 weak_ptr_factory_.GetWeakPtr())); 148 weak_ptr_factory_.GetWeakPtr()));
148 } 149 }
149 150
150 void RemoteDeviceLifeCycleImpl::CreateMessenger() { 151 void RemoteDeviceLifeCycleImpl::CreateMessenger() {
151 DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING); 152 DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING);
152 DCHECK(secure_context_); 153 DCHECK(secure_context_);
153 messenger_.reset( 154 messenger_.reset(
154 new MessengerImpl(connection_.Pass(), secure_context_.Pass())); 155 new MessengerImpl(connection_.Pass(), secure_context_.Pass()));
155 messenger_->AddObserver(this); 156 messenger_->AddObserver(this);
156 157
157 TransitionToState(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); 158 TransitionToState(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
158 } 159 }
159 160
160 void RemoteDeviceLifeCycleImpl::OnDisconnected() { 161 void RemoteDeviceLifeCycleImpl::OnDisconnected() {
161 DCHECK(state_ == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); 162 DCHECK(state_ == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
162 messenger_.reset();
163 FindConnection(); 163 FindConnection();
164 } 164 }
165 165
166 } // namespace proximity_auth 166 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698