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

Side by Side Diff: chrome/browser/signin/easy_unlock_service_signin_chromeos.cc

Issue 1494153002: This CL replaces e-mail with AccountId in easy signin code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 5 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/signin/easy_unlock_service_signin_chromeos.h" 5 #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h"
6 6
7 #include "base/base64url.h" 7 #include "base/base64url.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 27 matching lines...) Expand all
38 38
39 // Calculates the backoff interval that should be used next. 39 // Calculates the backoff interval that should be used next.
40 // |backoff| The last backoff interval used. 40 // |backoff| The last backoff interval used.
41 uint32 GetNextBackoffInterval(uint32 backoff) { 41 uint32 GetNextBackoffInterval(uint32 backoff) {
42 if (backoff == 0u) 42 if (backoff == 0u)
43 return kInitialCryptohomeBackoffIntervalMs; 43 return kInitialCryptohomeBackoffIntervalMs;
44 return backoff * 2; 44 return backoff * 2;
45 } 45 }
46 46
47 void LoadDataForUser( 47 void LoadDataForUser(
48 const std::string& user_id, 48 const AccountId& account_id,
49 uint32 backoff_ms, 49 uint32 backoff_ms,
50 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback); 50 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback);
51 51
52 // Callback passed to |LoadDataForUser()|. 52 // Callback passed to |LoadDataForUser()|.
53 // If |LoadDataForUser| function succeeded, it invokes |callback| with the 53 // If |LoadDataForUser| function succeeded, it invokes |callback| with the
54 // results. 54 // results.
55 // If |LoadDataForUser| failed and further retries are allowed, schedules new 55 // If |LoadDataForUser| failed and further retries are allowed, schedules new
56 // |LoadDataForUser| call with some backoff. If no further retires are allowed, 56 // |LoadDataForUser| call with some backoff. If no further retires are allowed,
57 // it invokes |callback| with the |LoadDataForUser| results. 57 // it invokes |callback| with the |LoadDataForUser| results.
58 void RetryDataLoadOnError( 58 void RetryDataLoadOnError(
59 const std::string& user_id, 59 const AccountId& account_id,
60 uint32 backoff_ms, 60 uint32 backoff_ms,
61 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback, 61 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback,
62 bool success, 62 bool success,
63 const chromeos::EasyUnlockDeviceKeyDataList& data_list) { 63 const chromeos::EasyUnlockDeviceKeyDataList& data_list) {
64 if (success) { 64 if (success) {
65 callback.Run(success, data_list); 65 callback.Run(success, data_list);
66 return; 66 return;
67 } 67 }
68 68
69 uint32 next_backoff_ms = GetNextBackoffInterval(backoff_ms); 69 uint32 next_backoff_ms = GetNextBackoffInterval(backoff_ms);
70 if (next_backoff_ms > kMaxCryptohomeBackoffIntervalMs) { 70 if (next_backoff_ms > kMaxCryptohomeBackoffIntervalMs) {
71 callback.Run(false, data_list); 71 callback.Run(false, data_list);
72 return; 72 return;
73 } 73 }
74 74
75 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 75 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
76 FROM_HERE, 76 FROM_HERE,
77 base::Bind(&LoadDataForUser, user_id, next_backoff_ms, callback), 77 base::Bind(&LoadDataForUser, account_id, next_backoff_ms, callback),
78 base::TimeDelta::FromMilliseconds(next_backoff_ms)); 78 base::TimeDelta::FromMilliseconds(next_backoff_ms));
79 } 79 }
80 80
81 // Loads device data list associated with the user's Easy unlock keys. 81 // Loads device data list associated with the user's Easy unlock keys.
82 void LoadDataForUser( 82 void LoadDataForUser(
83 const std::string& user_id, 83 const AccountId& account_id,
84 uint32 backoff_ms, 84 uint32 backoff_ms,
85 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback) { 85 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback) {
86 chromeos::EasyUnlockKeyManager* key_manager = 86 chromeos::EasyUnlockKeyManager* key_manager =
87 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); 87 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
88 DCHECK(key_manager); 88 DCHECK(key_manager);
89 89
90 key_manager->GetDeviceDataList( 90 key_manager->GetDeviceDataList(
91 chromeos::UserContext(AccountId::FromUserEmail(user_id)), 91 chromeos::UserContext(account_id),
92 base::Bind(&RetryDataLoadOnError, user_id, backoff_ms, callback)); 92 base::Bind(&RetryDataLoadOnError, account_id, backoff_ms, callback));
93 } 93 }
94 94
95 } // namespace 95 } // namespace
96 96
97 EasyUnlockServiceSignin::UserData::UserData() 97 EasyUnlockServiceSignin::UserData::UserData()
98 : state(EasyUnlockServiceSignin::USER_DATA_STATE_INITIAL) { 98 : state(EasyUnlockServiceSignin::USER_DATA_STATE_INITIAL) {
99 } 99 }
100 100
101 EasyUnlockServiceSignin::UserData::~UserData() {} 101 EasyUnlockServiceSignin::UserData::~UserData() {}
102 102
103 EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile) 103 EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile)
104 : EasyUnlockService(profile), 104 : EasyUnlockService(profile),
105 allow_cryptohome_backoff_(true), 105 account_id_(EmptyAccountId()),
106 service_active_(false),
107 user_pod_last_focused_timestamp_(base::TimeTicks::Now()), 106 user_pod_last_focused_timestamp_(base::TimeTicks::Now()),
108 weak_ptr_factory_(this) { 107 weak_ptr_factory_(this) {}
109 }
110 108
111 EasyUnlockServiceSignin::~EasyUnlockServiceSignin() { 109 EasyUnlockServiceSignin::~EasyUnlockServiceSignin() {
112 } 110 }
113 111
114 void EasyUnlockServiceSignin::SetCurrentUser(const std::string& user_id) { 112 void EasyUnlockServiceSignin::SetCurrentUser(const AccountId& account_id) {
115 OnFocusedUserChanged(user_id); 113 OnFocusedUserChanged(account_id);
116 } 114 }
117 115
118 void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice( 116 void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice(
119 const std::string& user_id, 117 const AccountId& account_id,
120 const std::string& device_public_key, 118 const std::string& device_public_key,
121 const std::string& channel_binding_data, 119 const std::string& channel_binding_data,
122 base::Callback<void(const std::string& wraped_challenge)> callback) { 120 base::Callback<void(const std::string& wraped_challenge)> callback) {
123 std::map<std::string, UserData*>::const_iterator it = 121 std::map<AccountId, UserData*>::const_iterator it =
124 user_data_.find(user_id); 122 user_data_.find(account_id);
125 if (it == user_data_.end() || it->second->state != USER_DATA_STATE_LOADED) { 123 if (it == user_data_.end() || it->second->state != USER_DATA_STATE_LOADED) {
126 PA_LOG(ERROR) << "TPM data not loaded for " << user_id; 124 PA_LOG(ERROR) << "TPM data not loaded for " << account_id.Serialize();
127 callback.Run(std::string()); 125 callback.Run(std::string());
128 return; 126 return;
129 } 127 }
130 128
131 std::string device_public_key_base64; 129 std::string device_public_key_base64;
132 base::Base64UrlEncode(device_public_key, 130 base::Base64UrlEncode(device_public_key,
133 base::Base64UrlEncodePolicy::INCLUDE_PADDING, 131 base::Base64UrlEncodePolicy::INCLUDE_PADDING,
134 &device_public_key_base64); 132 &device_public_key_base64);
135 for (const auto& device_data : it->second->devices) { 133 for (const auto& device_data : it->second->devices) {
136 if (device_data.public_key == device_public_key_base64) { 134 if (device_data.public_key == device_public_key_base64) {
137 PA_LOG(INFO) << "Wrapping challenge for " << user_id << "..."; 135 PA_LOG(INFO) << "Wrapping challenge for " << account_id.Serialize()
136 << "...";
138 challenge_wrapper_.reset(new chromeos::EasyUnlockChallengeWrapper( 137 challenge_wrapper_.reset(new chromeos::EasyUnlockChallengeWrapper(
139 device_data.challenge, channel_binding_data, user_id, 138 device_data.challenge, channel_binding_data, account_id,
140 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile()))); 139 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile())));
141 challenge_wrapper_->WrapChallenge(callback); 140 challenge_wrapper_->WrapChallenge(callback);
142 return; 141 return;
143 } 142 }
144 } 143 }
145 144
146 PA_LOG(ERROR) << "Unable to find device record for " << user_id; 145 PA_LOG(ERROR) << "Unable to find device record for "
146 << account_id.Serialize();
147 callback.Run(std::string()); 147 callback.Run(std::string());
148 } 148 }
149 149
150 EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const { 150 EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const {
151 return EasyUnlockService::TYPE_SIGNIN; 151 return EasyUnlockService::TYPE_SIGNIN;
152 } 152 }
153 153
154 std::string EasyUnlockServiceSignin::GetUserEmail() const { 154 AccountId EasyUnlockServiceSignin::GetAccountId() const {
155 return user_id_; 155 return account_id_;
156 } 156 }
157 157
158 void EasyUnlockServiceSignin::LaunchSetup() { 158 void EasyUnlockServiceSignin::LaunchSetup() {
159 NOTREACHED(); 159 NOTREACHED();
160 } 160 }
161 161
162 const base::DictionaryValue* EasyUnlockServiceSignin::GetPermitAccess() const { 162 const base::DictionaryValue* EasyUnlockServiceSignin::GetPermitAccess() const {
163 return NULL; 163 return nullptr;
164 } 164 }
165 165
166 void EasyUnlockServiceSignin::SetPermitAccess( 166 void EasyUnlockServiceSignin::SetPermitAccess(
167 const base::DictionaryValue& permit) { 167 const base::DictionaryValue& permit) {
168 NOTREACHED(); 168 NOTREACHED();
169 } 169 }
170 170
171 void EasyUnlockServiceSignin::ClearPermitAccess() { 171 void EasyUnlockServiceSignin::ClearPermitAccess() {
172 NOTREACHED(); 172 NOTREACHED();
173 } 173 }
174 174
175 const base::ListValue* EasyUnlockServiceSignin::GetRemoteDevices() const { 175 const base::ListValue* EasyUnlockServiceSignin::GetRemoteDevices() const {
176 const UserData* data = FindLoadedDataForCurrentUser(); 176 const UserData* data = FindLoadedDataForCurrentUser();
177 if (!data) 177 if (!data)
178 return NULL; 178 return nullptr;
179 return &data->remote_devices_value; 179 return &data->remote_devices_value;
180 } 180 }
181 181
182 void EasyUnlockServiceSignin::SetRemoteDevices( 182 void EasyUnlockServiceSignin::SetRemoteDevices(
183 const base::ListValue& devices) { 183 const base::ListValue& devices) {
184 NOTREACHED(); 184 NOTREACHED();
185 } 185 }
186 186
187 void EasyUnlockServiceSignin::SetRemoteBleDevices( 187 void EasyUnlockServiceSignin::SetRemoteBleDevices(
188 const base::ListValue& devices) { 188 const base::ListValue& devices) {
(...skipping 25 matching lines...) Expand all
214 std::string EasyUnlockServiceSignin::GetWrappedSecret() const { 214 std::string EasyUnlockServiceSignin::GetWrappedSecret() const {
215 const UserData* data = FindLoadedDataForCurrentUser(); 215 const UserData* data = FindLoadedDataForCurrentUser();
216 // TODO(xiyuan): Use correct remote device instead of hard coded first one. 216 // TODO(xiyuan): Use correct remote device instead of hard coded first one.
217 uint32 device_index = 0; 217 uint32 device_index = 0;
218 if (!data || data->devices.size() <= device_index) 218 if (!data || data->devices.size() <= device_index)
219 return std::string(); 219 return std::string();
220 return data->devices[device_index].wrapped_secret; 220 return data->devices[device_index].wrapped_secret;
221 } 221 }
222 222
223 void EasyUnlockServiceSignin::RecordEasySignInOutcome( 223 void EasyUnlockServiceSignin::RecordEasySignInOutcome(
224 const std::string& user_id, 224 const AccountId& account_id,
225 bool success) const { 225 bool success) const {
226 DCHECK_EQ(GetUserEmail(), user_id); 226 DCHECK(GetAccountId() == account_id)
227 << "GetAccountId()=" << GetAccountId().Serialize()
228 << " != account_id=" << account_id.Serialize();
227 229
228 RecordEasyUnlockSigninEvent( 230 RecordEasyUnlockSigninEvent(
229 success ? EASY_UNLOCK_SUCCESS : EASY_UNLOCK_FAILURE); 231 success ? EASY_UNLOCK_SUCCESS : EASY_UNLOCK_FAILURE);
230 if (success) { 232 if (success) {
231 RecordEasyUnlockSigninDuration( 233 RecordEasyUnlockSigninDuration(
232 base::TimeTicks::Now() - user_pod_last_focused_timestamp_); 234 base::TimeTicks::Now() - user_pod_last_focused_timestamp_);
233 } 235 }
234 DVLOG(1) << "Easy sign-in " << (success ? "success" : "failure"); 236 DVLOG(1) << "Easy sign-in " << (success ? "success" : "failure");
235 } 237 }
236 238
237 void EasyUnlockServiceSignin::RecordPasswordLoginEvent( 239 void EasyUnlockServiceSignin::RecordPasswordLoginEvent(
238 const std::string& user_id) const { 240 const AccountId& account_id) const {
239 // This happens during tests, where a user could log in without the user pod 241 // This happens during tests, where a user could log in without the user pod
240 // being focused. 242 // being focused.
241 if (GetUserEmail() != user_id) 243 if (GetAccountId() != account_id)
242 return; 244 return;
243 245
244 if (!IsEnabled()) 246 if (!IsEnabled())
245 return; 247 return;
246 248
247 EasyUnlockAuthEvent event = GetPasswordAuthEvent(); 249 EasyUnlockAuthEvent event = GetPasswordAuthEvent();
248 RecordEasyUnlockSigninEvent(event); 250 RecordEasyUnlockSigninEvent(event);
249 DVLOG(1) << "Easy Sign-in password login event, event=" << event; 251 DVLOG(1) << "Easy Sign-in password login event, event=" << event;
250 } 252 }
251 253
(...skipping 11 matching lines...) Expand all
263 void EasyUnlockServiceSignin::InitializeInternal() { 265 void EasyUnlockServiceSignin::InitializeInternal() {
264 if (chromeos::LoginState::Get()->IsUserLoggedIn()) 266 if (chromeos::LoginState::Get()->IsUserLoggedIn())
265 return; 267 return;
266 268
267 service_active_ = true; 269 service_active_ = true;
268 270
269 chromeos::LoginState::Get()->AddObserver(this); 271 chromeos::LoginState::Get()->AddObserver(this);
270 proximity_auth::ScreenlockBridge* screenlock_bridge = 272 proximity_auth::ScreenlockBridge* screenlock_bridge =
271 proximity_auth::ScreenlockBridge::Get(); 273 proximity_auth::ScreenlockBridge::Get();
272 screenlock_bridge->AddObserver(this); 274 screenlock_bridge->AddObserver(this);
273 if (!screenlock_bridge->focused_user_id().empty()) 275 if (screenlock_bridge->focused_account_id().is_valid())
274 OnFocusedUserChanged(screenlock_bridge->focused_user_id()); 276 OnFocusedUserChanged(screenlock_bridge->focused_account_id());
275 } 277 }
276 278
277 void EasyUnlockServiceSignin::ShutdownInternal() { 279 void EasyUnlockServiceSignin::ShutdownInternal() {
278 if (!service_active_) 280 if (!service_active_)
279 return; 281 return;
280 service_active_ = false; 282 service_active_ = false;
281 283
282 weak_ptr_factory_.InvalidateWeakPtrs(); 284 weak_ptr_factory_.InvalidateWeakPtrs();
283 proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this); 285 proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this);
284 chromeos::LoginState::Get()->RemoveObserver(this); 286 chromeos::LoginState::Get()->RemoveObserver(this);
285 STLDeleteContainerPairSecondPointers(user_data_.begin(), user_data_.end()); 287 STLDeleteContainerPairSecondPointers(user_data_.begin(), user_data_.end());
286 user_data_.clear(); 288 user_data_.clear();
287 } 289 }
288 290
289 bool EasyUnlockServiceSignin::IsAllowedInternal() const { 291 bool EasyUnlockServiceSignin::IsAllowedInternal() const {
290 return service_active_ && 292 return service_active_ && account_id_.is_valid() &&
291 !user_id_.empty() &&
292 !chromeos::LoginState::Get()->IsUserLoggedIn(); 293 !chromeos::LoginState::Get()->IsUserLoggedIn();
293 } 294 }
294 295
295 void EasyUnlockServiceSignin::OnWillFinalizeUnlock(bool success) { 296 void EasyUnlockServiceSignin::OnWillFinalizeUnlock(bool success) {
296 // This code path should only be exercised for the lock screen, not for the 297 // This code path should only be exercised for the lock screen, not for the
297 // sign-in screen. 298 // sign-in screen.
298 NOTREACHED(); 299 NOTREACHED();
299 } 300 }
300 301
301 void EasyUnlockServiceSignin::OnSuspendDoneInternal() { 302 void EasyUnlockServiceSignin::OnSuspendDoneInternal() {
(...skipping 19 matching lines...) Expand all
321 // in tests, the screen type might be different. 322 // in tests, the screen type might be different.
322 if (screen_type != 323 if (screen_type !=
323 proximity_auth::ScreenlockBridge::LockHandler::SIGNIN_SCREEN) 324 proximity_auth::ScreenlockBridge::LockHandler::SIGNIN_SCREEN)
324 return; 325 return;
325 326
326 DisableAppWithoutResettingScreenlockState(); 327 DisableAppWithoutResettingScreenlockState();
327 328
328 Shutdown(); 329 Shutdown();
329 } 330 }
330 331
331 void EasyUnlockServiceSignin::OnFocusedUserChanged(const std::string& user_id) { 332 void EasyUnlockServiceSignin::OnFocusedUserChanged(
332 if (user_id_ == user_id) 333 const AccountId& account_id) {
334 if (account_id_ == account_id)
333 return; 335 return;
334 336
335 // Setting or clearing the user_id may changed |IsAllowed| value, so in these 337 // Setting or clearing the account_id may changed |IsAllowed| value, so in
338 // these
336 // cases update the app state. Otherwise, it's enough to notify the app the 339 // cases update the app state. Otherwise, it's enough to notify the app the
337 // user data has been updated. 340 // user data has been updated.
338 bool should_update_app_state = user_id_.empty() != user_id.empty(); 341 const bool should_update_app_state =
339 user_id_ = user_id; 342 account_id_.is_valid() != account_id.is_valid();
343 account_id_ = account_id;
340 user_pod_last_focused_timestamp_ = base::TimeTicks::Now(); 344 user_pod_last_focused_timestamp_ = base::TimeTicks::Now();
341 345
342 ResetScreenlockState(); 346 ResetScreenlockState();
343 ShowInitialUserState(); 347 ShowInitialUserState();
344 348
345 if (should_update_app_state) { 349 if (should_update_app_state) {
346 UpdateAppState(); 350 UpdateAppState();
347 } else { 351 } else {
348 NotifyUserUpdated(); 352 NotifyUserUpdated();
349 } 353 }
(...skipping 14 matching lines...) Expand all
364 if (!chromeos::LoginState::Get()->IsUserLoggedIn()) 368 if (!chromeos::LoginState::Get()->IsUserLoggedIn())
365 return; 369 return;
366 DisableAppWithoutResettingScreenlockState(); 370 DisableAppWithoutResettingScreenlockState();
367 } 371 }
368 372
369 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { 373 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() {
370 // TODO(xiyuan): Revisit this when adding tests. 374 // TODO(xiyuan): Revisit this when adding tests.
371 if (!base::SysInfo::IsRunningOnChromeOS()) 375 if (!base::SysInfo::IsRunningOnChromeOS())
372 return; 376 return;
373 377
374 if (user_id_.empty() || !service_active_) 378 if (account_id_.is_valid() || !service_active_)
375 return; 379 return;
376 380
377 std::map<std::string, UserData*>::iterator it = user_data_.find(user_id_); 381 const std::map<AccountId, UserData*>::const_iterator it =
382 user_data_.find(account_id_);
378 if (it == user_data_.end()) 383 if (it == user_data_.end())
379 user_data_.insert(std::make_pair(user_id_, new UserData())); 384 user_data_.insert(std::make_pair(account_id_, new UserData()));
380 385
381 UserData* data = user_data_[user_id_]; 386 UserData* data = user_data_[account_id_];
382 387
383 if (data->state != USER_DATA_STATE_INITIAL) 388 if (data->state != USER_DATA_STATE_INITIAL)
384 return; 389 return;
385 data->state = USER_DATA_STATE_LOADING; 390 data->state = USER_DATA_STATE_LOADING;
386 391
387 LoadDataForUser( 392 LoadDataForUser(
388 user_id_, 393 account_id_,
389 allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs, 394 allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs,
390 base::Bind(&EasyUnlockServiceSignin::OnUserDataLoaded, 395 base::Bind(&EasyUnlockServiceSignin::OnUserDataLoaded,
391 weak_ptr_factory_.GetWeakPtr(), 396 weak_ptr_factory_.GetWeakPtr(), account_id_));
392 user_id_));
393 } 397 }
394 398
395 void EasyUnlockServiceSignin::OnUserDataLoaded( 399 void EasyUnlockServiceSignin::OnUserDataLoaded(
396 const std::string& user_id, 400 const AccountId& account_id,
397 bool success, 401 bool success,
398 const chromeos::EasyUnlockDeviceKeyDataList& devices) { 402 const chromeos::EasyUnlockDeviceKeyDataList& devices) {
399 allow_cryptohome_backoff_ = false; 403 allow_cryptohome_backoff_ = false;
400 404
401 UserData* data = user_data_[user_id]; 405 UserData* data = user_data_[account_id];
402 data->state = USER_DATA_STATE_LOADED; 406 data->state = USER_DATA_STATE_LOADED;
403 if (success) { 407 if (success) {
404 data->devices = devices; 408 data->devices = devices;
405 chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( 409 chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList(
406 user_id, devices, &data->remote_devices_value); 410 account_id, devices, &data->remote_devices_value);
407 411
408 // User could have a NO_HARDLOCK state but has no remote devices if 412 // User could have a NO_HARDLOCK state but has no remote devices if
409 // previous user session shuts down before 413 // previous user session shuts down before
410 // CheckCryptohomeKeysAndMaybeHardlock finishes. Set NO_PAIRING state 414 // CheckCryptohomeKeysAndMaybeHardlock finishes. Set NO_PAIRING state
411 // and update UI to remove the confusing spinner in this case. 415 // and update UI to remove the confusing spinner in this case.
412 EasyUnlockScreenlockStateHandler::HardlockState hardlock_state; 416 EasyUnlockScreenlockStateHandler::HardlockState hardlock_state;
413 if (devices.empty() && 417 if (devices.empty() &&
414 GetPersistedHardlockState(&hardlock_state) && 418 GetPersistedHardlockState(&hardlock_state) &&
415 hardlock_state == EasyUnlockScreenlockStateHandler::NO_HARDLOCK) { 419 hardlock_state == EasyUnlockScreenlockStateHandler::NO_HARDLOCK) {
416 SetHardlockStateForUser(user_id, 420 SetHardlockStateForUser(account_id,
417 EasyUnlockScreenlockStateHandler::NO_PAIRING); 421 EasyUnlockScreenlockStateHandler::NO_PAIRING);
418 } 422 }
419 } 423 }
420 424
421 // If the fetched data belongs to the currently focused user, notify the app 425 // If the fetched data belongs to the currently focused user, notify the app
422 // that it has to refresh it's user data. 426 // that it has to refresh it's user data.
423 if (user_id == user_id_) 427 if (account_id == account_id_)
424 NotifyUserUpdated(); 428 NotifyUserUpdated();
425 429
426 if (user_id != user_id || devices.empty()) 430 if (account_id != account_id || devices.empty())
427 return; 431 return;
428 432
429 // TODO(tengs): Currently, ProximityAuthSystem only supports one device. Once 433 // TODO(tengs): Currently, ProximityAuthSystem only supports one device. Once
430 // multiple devices are supported, we need to load all devices. 434 // multiple devices are supported, we need to load all devices.
431 std::string decoded_public_key, decoded_psk, decoded_challenge; 435 std::string decoded_public_key, decoded_psk, decoded_challenge;
432 if (!base::Base64UrlDecode(devices[0].public_key, 436 if (!base::Base64UrlDecode(devices[0].public_key,
433 base::Base64UrlDecodePolicy::REQUIRE_PADDING, 437 base::Base64UrlDecodePolicy::REQUIRE_PADDING,
434 &decoded_public_key) || 438 &decoded_public_key) ||
435 !base::Base64UrlDecode(devices[0].psk, 439 !base::Base64UrlDecode(devices[0].psk,
436 base::Base64UrlDecodePolicy::REQUIRE_PADDING, 440 base::Base64UrlDecodePolicy::REQUIRE_PADDING,
437 &decoded_psk) || 441 &decoded_psk) ||
438 !base::Base64UrlDecode(devices[0].challenge, 442 !base::Base64UrlDecode(devices[0].challenge,
439 base::Base64UrlDecodePolicy::REQUIRE_PADDING, 443 base::Base64UrlDecodePolicy::REQUIRE_PADDING,
440 &decoded_challenge)) { 444 &decoded_challenge)) {
441 PA_LOG(ERROR) << "Unable to base64url decode the input data."; 445 PA_LOG(ERROR) << "Unable to base64url decode the input data.";
442 return; 446 return;
443 } 447 }
444 448
445 proximity_auth::RemoteDevice::BluetoothType bluetooth_type = 449 proximity_auth::RemoteDevice::BluetoothType bluetooth_type =
446 devices[0].bluetooth_type == 450 devices[0].bluetooth_type ==
447 chromeos::EasyUnlockDeviceKeyData::BLUETOOTH_LE 451 chromeos::EasyUnlockDeviceKeyData::BLUETOOTH_LE
448 ? proximity_auth::RemoteDevice::BLUETOOTH_LE 452 ? proximity_auth::RemoteDevice::BLUETOOTH_LE
449 : proximity_auth::RemoteDevice::BLUETOOTH_CLASSIC; 453 : proximity_auth::RemoteDevice::BLUETOOTH_CLASSIC;
450 454
451 proximity_auth::RemoteDevice remote_device( 455 proximity_auth::RemoteDevice remote_device(
452 user_id, std::string(), decoded_public_key, bluetooth_type, 456 account_id.GetUserEmail(), std::string(), decoded_public_key,
453 devices[0].bluetooth_address, decoded_psk, decoded_challenge); 457 bluetooth_type, devices[0].bluetooth_address, decoded_psk,
458 decoded_challenge);
454 PA_LOG(INFO) << "Loaded Remote Device:\n" 459 PA_LOG(INFO) << "Loaded Remote Device:\n"
455 << " user id: " << remote_device.user_id << "\n" 460 << " user id: " << remote_device.user_id << "\n"
456 << " name: " << remote_device.name << "\n" 461 << " name: " << remote_device.name << "\n"
457 << " public key" << devices[0].public_key << "\n" 462 << " public key" << devices[0].public_key << "\n"
458 << " bt_addr:" << remote_device.bluetooth_address; 463 << " bt_addr:" << remote_device.bluetooth_address;
459 OnRemoteDeviceChanged(&remote_device); 464 OnRemoteDeviceChanged(&remote_device);
460 } 465 }
461 466
462 const EasyUnlockServiceSignin::UserData* 467 const EasyUnlockServiceSignin::UserData*
463 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { 468 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const {
464 if (user_id_.empty()) 469 if (account_id_.is_valid())
465 return NULL; 470 return nullptr;
466 471
467 std::map<std::string, UserData*>::const_iterator it = 472 const std::map<AccountId, UserData*>::const_iterator it =
468 user_data_.find(user_id_); 473 user_data_.find(account_id_);
469 if (it == user_data_.end()) 474 if (it == user_data_.end())
470 return NULL; 475 return nullptr;
471 if (it->second->state != USER_DATA_STATE_LOADED) 476 if (it->second->state != USER_DATA_STATE_LOADED)
472 return NULL; 477 return nullptr;
473 return it->second; 478 return it->second;
474 } 479 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698