Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 account_id_(EmptyAccountId()), | |
|
achuithb
2015/12/04 10:12:53
Doesn't the default ctor do the right thing?
Alexander Alekseev
2015/12/04 12:44:07
No.
| |
| 105 allow_cryptohome_backoff_(true), | 106 allow_cryptohome_backoff_(true), |
| 106 service_active_(false), | 107 service_active_(false), |
| 107 user_pod_last_focused_timestamp_(base::TimeTicks::Now()), | 108 user_pod_last_focused_timestamp_(base::TimeTicks::Now()), |
| 108 weak_ptr_factory_(this) { | 109 weak_ptr_factory_(this) {} |
| 109 } | |
| 110 | 110 |
| 111 EasyUnlockServiceSignin::~EasyUnlockServiceSignin() { | 111 EasyUnlockServiceSignin::~EasyUnlockServiceSignin() { |
| 112 } | 112 } |
| 113 | 113 |
| 114 void EasyUnlockServiceSignin::SetCurrentUser(const std::string& user_id) { | 114 void EasyUnlockServiceSignin::SetCurrentUser(const AccountId& account_id) { |
| 115 OnFocusedUserChanged(user_id); | 115 OnFocusedUserChanged(account_id); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice( | 118 void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice( |
| 119 const std::string& user_id, | 119 const AccountId& account_id, |
| 120 const std::string& device_public_key, | 120 const std::string& device_public_key, |
| 121 const std::string& channel_binding_data, | 121 const std::string& channel_binding_data, |
| 122 base::Callback<void(const std::string& wraped_challenge)> callback) { | 122 base::Callback<void(const std::string& wraped_challenge)> callback) { |
| 123 std::map<std::string, UserData*>::const_iterator it = | 123 std::map<AccountId, UserData*>::const_iterator it = |
|
achuithb
2015/12/04 10:12:53
auto?
Alexander Alekseev
2015/12/04 12:44:07
We know the exact type here, so we can use const_i
achuithb
2015/12/04 20:16:56
If you look at the style guide, I think the idea i
Alexander Alekseev
2015/12/05 05:20:07
Done.
| |
| 124 user_data_.find(user_id); | 124 user_data_.find(account_id); |
| 125 if (it == user_data_.end() || it->second->state != USER_DATA_STATE_LOADED) { | 125 if (it == user_data_.end() || it->second->state != USER_DATA_STATE_LOADED) { |
| 126 PA_LOG(ERROR) << "TPM data not loaded for " << user_id; | 126 PA_LOG(ERROR) << "TPM data not loaded for " << account_id.Serialize(); |
| 127 callback.Run(std::string()); | 127 callback.Run(std::string()); |
| 128 return; | 128 return; |
| 129 } | 129 } |
| 130 | 130 |
| 131 std::string device_public_key_base64; | 131 std::string device_public_key_base64; |
| 132 base::Base64UrlEncode(device_public_key, | 132 base::Base64UrlEncode(device_public_key, |
| 133 base::Base64UrlEncodePolicy::INCLUDE_PADDING, | 133 base::Base64UrlEncodePolicy::INCLUDE_PADDING, |
| 134 &device_public_key_base64); | 134 &device_public_key_base64); |
| 135 for (const auto& device_data : it->second->devices) { | 135 for (const auto& device_data : it->second->devices) { |
| 136 if (device_data.public_key == device_public_key_base64) { | 136 if (device_data.public_key == device_public_key_base64) { |
| 137 PA_LOG(INFO) << "Wrapping challenge for " << user_id << "..."; | 137 PA_LOG(INFO) << "Wrapping challenge for " << account_id.Serialize() |
| 138 << "..."; | |
| 138 challenge_wrapper_.reset(new chromeos::EasyUnlockChallengeWrapper( | 139 challenge_wrapper_.reset(new chromeos::EasyUnlockChallengeWrapper( |
| 139 device_data.challenge, channel_binding_data, user_id, | 140 device_data.challenge, channel_binding_data, account_id, |
| 140 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile()))); | 141 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile()))); |
| 141 challenge_wrapper_->WrapChallenge(callback); | 142 challenge_wrapper_->WrapChallenge(callback); |
| 142 return; | 143 return; |
| 143 } | 144 } |
| 144 } | 145 } |
| 145 | 146 |
| 146 PA_LOG(ERROR) << "Unable to find device record for " << user_id; | 147 PA_LOG(ERROR) << "Unable to find device record for " |
| 148 << account_id.Serialize(); | |
| 147 callback.Run(std::string()); | 149 callback.Run(std::string()); |
| 148 } | 150 } |
| 149 | 151 |
| 150 EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const { | 152 EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const { |
| 151 return EasyUnlockService::TYPE_SIGNIN; | 153 return EasyUnlockService::TYPE_SIGNIN; |
| 152 } | 154 } |
| 153 | 155 |
| 154 std::string EasyUnlockServiceSignin::GetUserEmail() const { | 156 const AccountId EasyUnlockServiceSignin::GetAccountId() const { |
| 155 return user_id_; | 157 return account_id_; |
| 156 } | 158 } |
| 157 | 159 |
| 158 void EasyUnlockServiceSignin::LaunchSetup() { | 160 void EasyUnlockServiceSignin::LaunchSetup() { |
| 159 NOTREACHED(); | 161 NOTREACHED(); |
| 160 } | 162 } |
| 161 | 163 |
| 162 const base::DictionaryValue* EasyUnlockServiceSignin::GetPermitAccess() const { | 164 const base::DictionaryValue* EasyUnlockServiceSignin::GetPermitAccess() const { |
| 163 return NULL; | 165 return NULL; |
| 164 } | 166 } |
| 165 | 167 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 std::string EasyUnlockServiceSignin::GetWrappedSecret() const { | 216 std::string EasyUnlockServiceSignin::GetWrappedSecret() const { |
| 215 const UserData* data = FindLoadedDataForCurrentUser(); | 217 const UserData* data = FindLoadedDataForCurrentUser(); |
| 216 // TODO(xiyuan): Use correct remote device instead of hard coded first one. | 218 // TODO(xiyuan): Use correct remote device instead of hard coded first one. |
| 217 uint32 device_index = 0; | 219 uint32 device_index = 0; |
| 218 if (!data || data->devices.size() <= device_index) | 220 if (!data || data->devices.size() <= device_index) |
| 219 return std::string(); | 221 return std::string(); |
| 220 return data->devices[device_index].wrapped_secret; | 222 return data->devices[device_index].wrapped_secret; |
| 221 } | 223 } |
| 222 | 224 |
| 223 void EasyUnlockServiceSignin::RecordEasySignInOutcome( | 225 void EasyUnlockServiceSignin::RecordEasySignInOutcome( |
| 224 const std::string& user_id, | 226 const AccountId& account_id, |
| 225 bool success) const { | 227 bool success) const { |
| 226 DCHECK_EQ(GetUserEmail(), user_id); | 228 DCHECK(GetAccountId() == account_id) |
| 229 << "GetAccountId()=" << GetAccountId().Serialize() | |
| 230 << " != account_id=" << account_id.Serialize(); | |
| 227 | 231 |
| 228 RecordEasyUnlockSigninEvent( | 232 RecordEasyUnlockSigninEvent( |
| 229 success ? EASY_UNLOCK_SUCCESS : EASY_UNLOCK_FAILURE); | 233 success ? EASY_UNLOCK_SUCCESS : EASY_UNLOCK_FAILURE); |
| 230 if (success) { | 234 if (success) { |
| 231 RecordEasyUnlockSigninDuration( | 235 RecordEasyUnlockSigninDuration( |
| 232 base::TimeTicks::Now() - user_pod_last_focused_timestamp_); | 236 base::TimeTicks::Now() - user_pod_last_focused_timestamp_); |
| 233 } | 237 } |
| 234 DVLOG(1) << "Easy sign-in " << (success ? "success" : "failure"); | 238 DVLOG(1) << "Easy sign-in " << (success ? "success" : "failure"); |
| 235 } | 239 } |
| 236 | 240 |
| 237 void EasyUnlockServiceSignin::RecordPasswordLoginEvent( | 241 void EasyUnlockServiceSignin::RecordPasswordLoginEvent( |
| 238 const std::string& user_id) const { | 242 const AccountId& account_id) const { |
| 239 // This happens during tests, where a user could log in without the user pod | 243 // This happens during tests, where a user could log in without the user pod |
| 240 // being focused. | 244 // being focused. |
| 241 if (GetUserEmail() != user_id) | 245 if (GetAccountId() != account_id) |
| 242 return; | 246 return; |
| 243 | 247 |
| 244 if (!IsEnabled()) | 248 if (!IsEnabled()) |
| 245 return; | 249 return; |
| 246 | 250 |
| 247 EasyUnlockAuthEvent event = GetPasswordAuthEvent(); | 251 EasyUnlockAuthEvent event = GetPasswordAuthEvent(); |
| 248 RecordEasyUnlockSigninEvent(event); | 252 RecordEasyUnlockSigninEvent(event); |
| 249 DVLOG(1) << "Easy Sign-in password login event, event=" << event; | 253 DVLOG(1) << "Easy Sign-in password login event, event=" << event; |
| 250 } | 254 } |
| 251 | 255 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 263 void EasyUnlockServiceSignin::InitializeInternal() { | 267 void EasyUnlockServiceSignin::InitializeInternal() { |
| 264 if (chromeos::LoginState::Get()->IsUserLoggedIn()) | 268 if (chromeos::LoginState::Get()->IsUserLoggedIn()) |
| 265 return; | 269 return; |
| 266 | 270 |
| 267 service_active_ = true; | 271 service_active_ = true; |
| 268 | 272 |
| 269 chromeos::LoginState::Get()->AddObserver(this); | 273 chromeos::LoginState::Get()->AddObserver(this); |
| 270 proximity_auth::ScreenlockBridge* screenlock_bridge = | 274 proximity_auth::ScreenlockBridge* screenlock_bridge = |
| 271 proximity_auth::ScreenlockBridge::Get(); | 275 proximity_auth::ScreenlockBridge::Get(); |
| 272 screenlock_bridge->AddObserver(this); | 276 screenlock_bridge->AddObserver(this); |
| 273 if (!screenlock_bridge->focused_user_id().empty()) | 277 if (screenlock_bridge->focused_account_id().is_valid()) |
| 274 OnFocusedUserChanged(screenlock_bridge->focused_user_id()); | 278 OnFocusedUserChanged(screenlock_bridge->focused_account_id()); |
| 275 } | 279 } |
| 276 | 280 |
| 277 void EasyUnlockServiceSignin::ShutdownInternal() { | 281 void EasyUnlockServiceSignin::ShutdownInternal() { |
| 278 if (!service_active_) | 282 if (!service_active_) |
| 279 return; | 283 return; |
| 280 service_active_ = false; | 284 service_active_ = false; |
| 281 | 285 |
| 282 weak_ptr_factory_.InvalidateWeakPtrs(); | 286 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 283 proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this); | 287 proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this); |
| 284 chromeos::LoginState::Get()->RemoveObserver(this); | 288 chromeos::LoginState::Get()->RemoveObserver(this); |
| 285 STLDeleteContainerPairSecondPointers(user_data_.begin(), user_data_.end()); | 289 STLDeleteContainerPairSecondPointers(user_data_.begin(), user_data_.end()); |
| 286 user_data_.clear(); | 290 user_data_.clear(); |
| 287 } | 291 } |
| 288 | 292 |
| 289 bool EasyUnlockServiceSignin::IsAllowedInternal() const { | 293 bool EasyUnlockServiceSignin::IsAllowedInternal() const { |
| 290 return service_active_ && | 294 return service_active_ && account_id_.is_valid() && |
| 291 !user_id_.empty() && | |
| 292 !chromeos::LoginState::Get()->IsUserLoggedIn(); | 295 !chromeos::LoginState::Get()->IsUserLoggedIn(); |
| 293 } | 296 } |
| 294 | 297 |
| 295 void EasyUnlockServiceSignin::OnWillFinalizeUnlock(bool success) { | 298 void EasyUnlockServiceSignin::OnWillFinalizeUnlock(bool success) { |
| 296 // This code path should only be exercised for the lock screen, not for the | 299 // This code path should only be exercised for the lock screen, not for the |
| 297 // sign-in screen. | 300 // sign-in screen. |
| 298 NOTREACHED(); | 301 NOTREACHED(); |
| 299 } | 302 } |
| 300 | 303 |
| 301 void EasyUnlockServiceSignin::OnSuspendDoneInternal() { | 304 void EasyUnlockServiceSignin::OnSuspendDoneInternal() { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 321 // in tests, the screen type might be different. | 324 // in tests, the screen type might be different. |
| 322 if (screen_type != | 325 if (screen_type != |
| 323 proximity_auth::ScreenlockBridge::LockHandler::SIGNIN_SCREEN) | 326 proximity_auth::ScreenlockBridge::LockHandler::SIGNIN_SCREEN) |
| 324 return; | 327 return; |
| 325 | 328 |
| 326 DisableAppWithoutResettingScreenlockState(); | 329 DisableAppWithoutResettingScreenlockState(); |
| 327 | 330 |
| 328 Shutdown(); | 331 Shutdown(); |
| 329 } | 332 } |
| 330 | 333 |
| 331 void EasyUnlockServiceSignin::OnFocusedUserChanged(const std::string& user_id) { | 334 void EasyUnlockServiceSignin::OnFocusedUserChanged( |
| 332 if (user_id_ == user_id) | 335 const AccountId& account_id) { |
| 336 if (account_id_ == account_id) | |
| 333 return; | 337 return; |
| 334 | 338 |
| 335 // Setting or clearing the user_id may changed |IsAllowed| value, so in these | 339 // Setting or clearing the account_id may changed |IsAllowed| value, so in |
| 340 // these | |
| 336 // cases update the app state. Otherwise, it's enough to notify the app the | 341 // cases update the app state. Otherwise, it's enough to notify the app the |
| 337 // user data has been updated. | 342 // user data has been updated. |
| 338 bool should_update_app_state = user_id_.empty() != user_id.empty(); | 343 bool should_update_app_state = |
|
achuithb
2015/12/04 10:12:53
const
Alexander Alekseev
2015/12/04 12:44:07
Done.
| |
| 339 user_id_ = user_id; | 344 account_id_.is_valid() != account_id.is_valid(); |
| 345 account_id_ = account_id; | |
| 340 user_pod_last_focused_timestamp_ = base::TimeTicks::Now(); | 346 user_pod_last_focused_timestamp_ = base::TimeTicks::Now(); |
| 341 | 347 |
| 342 ResetScreenlockState(); | 348 ResetScreenlockState(); |
| 343 ShowInitialUserState(); | 349 ShowInitialUserState(); |
| 344 | 350 |
| 345 if (should_update_app_state) { | 351 if (should_update_app_state) { |
| 346 UpdateAppState(); | 352 UpdateAppState(); |
| 347 } else { | 353 } else { |
| 348 NotifyUserUpdated(); | 354 NotifyUserUpdated(); |
| 349 } | 355 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 364 if (!chromeos::LoginState::Get()->IsUserLoggedIn()) | 370 if (!chromeos::LoginState::Get()->IsUserLoggedIn()) |
| 365 return; | 371 return; |
| 366 DisableAppWithoutResettingScreenlockState(); | 372 DisableAppWithoutResettingScreenlockState(); |
| 367 } | 373 } |
| 368 | 374 |
| 369 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { | 375 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { |
| 370 // TODO(xiyuan): Revisit this when adding tests. | 376 // TODO(xiyuan): Revisit this when adding tests. |
| 371 if (!base::SysInfo::IsRunningOnChromeOS()) | 377 if (!base::SysInfo::IsRunningOnChromeOS()) |
| 372 return; | 378 return; |
| 373 | 379 |
| 374 if (user_id_.empty() || !service_active_) | 380 if (account_id_.is_valid() || !service_active_) |
| 375 return; | 381 return; |
| 376 | 382 |
| 377 std::map<std::string, UserData*>::iterator it = user_data_.find(user_id_); | 383 std::map<AccountId, UserData*>::iterator it = user_data_.find(account_id_); |
|
achuithb
2015/12/04 10:12:53
auto?
Alexander Alekseev
2015/12/04 12:44:07
Let's add const here ;)
achuithb
2015/12/04 20:16:56
I really believe auto is recommended in this case.
Alexander Alekseev
2015/12/05 05:20:07
Done.
| |
| 378 if (it == user_data_.end()) | 384 if (it == user_data_.end()) |
| 379 user_data_.insert(std::make_pair(user_id_, new UserData())); | 385 user_data_.insert(std::make_pair(account_id_, new UserData())); |
| 380 | 386 |
| 381 UserData* data = user_data_[user_id_]; | 387 UserData* data = user_data_[account_id_]; |
| 382 | 388 |
| 383 if (data->state != USER_DATA_STATE_INITIAL) | 389 if (data->state != USER_DATA_STATE_INITIAL) |
| 384 return; | 390 return; |
| 385 data->state = USER_DATA_STATE_LOADING; | 391 data->state = USER_DATA_STATE_LOADING; |
| 386 | 392 |
| 387 LoadDataForUser( | 393 LoadDataForUser( |
| 388 user_id_, | 394 account_id_, |
| 389 allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs, | 395 allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs, |
| 390 base::Bind(&EasyUnlockServiceSignin::OnUserDataLoaded, | 396 base::Bind(&EasyUnlockServiceSignin::OnUserDataLoaded, |
| 391 weak_ptr_factory_.GetWeakPtr(), | 397 weak_ptr_factory_.GetWeakPtr(), account_id_)); |
| 392 user_id_)); | |
| 393 } | 398 } |
| 394 | 399 |
| 395 void EasyUnlockServiceSignin::OnUserDataLoaded( | 400 void EasyUnlockServiceSignin::OnUserDataLoaded( |
| 396 const std::string& user_id, | 401 const AccountId& account_id, |
| 397 bool success, | 402 bool success, |
| 398 const chromeos::EasyUnlockDeviceKeyDataList& devices) { | 403 const chromeos::EasyUnlockDeviceKeyDataList& devices) { |
| 399 allow_cryptohome_backoff_ = false; | 404 allow_cryptohome_backoff_ = false; |
| 400 | 405 |
| 401 UserData* data = user_data_[user_id]; | 406 UserData* data = user_data_[account_id]; |
| 402 data->state = USER_DATA_STATE_LOADED; | 407 data->state = USER_DATA_STATE_LOADED; |
| 403 if (success) { | 408 if (success) { |
| 404 data->devices = devices; | 409 data->devices = devices; |
| 405 chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( | 410 chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( |
| 406 user_id, devices, &data->remote_devices_value); | 411 account_id, devices, &data->remote_devices_value); |
| 407 | 412 |
| 408 // User could have a NO_HARDLOCK state but has no remote devices if | 413 // User could have a NO_HARDLOCK state but has no remote devices if |
| 409 // previous user session shuts down before | 414 // previous user session shuts down before |
| 410 // CheckCryptohomeKeysAndMaybeHardlock finishes. Set NO_PAIRING state | 415 // CheckCryptohomeKeysAndMaybeHardlock finishes. Set NO_PAIRING state |
| 411 // and update UI to remove the confusing spinner in this case. | 416 // and update UI to remove the confusing spinner in this case. |
| 412 EasyUnlockScreenlockStateHandler::HardlockState hardlock_state; | 417 EasyUnlockScreenlockStateHandler::HardlockState hardlock_state; |
| 413 if (devices.empty() && | 418 if (devices.empty() && |
| 414 GetPersistedHardlockState(&hardlock_state) && | 419 GetPersistedHardlockState(&hardlock_state) && |
| 415 hardlock_state == EasyUnlockScreenlockStateHandler::NO_HARDLOCK) { | 420 hardlock_state == EasyUnlockScreenlockStateHandler::NO_HARDLOCK) { |
| 416 SetHardlockStateForUser(user_id, | 421 SetHardlockStateForUser(account_id, |
| 417 EasyUnlockScreenlockStateHandler::NO_PAIRING); | 422 EasyUnlockScreenlockStateHandler::NO_PAIRING); |
| 418 } | 423 } |
| 419 } | 424 } |
| 420 | 425 |
| 421 // If the fetched data belongs to the currently focused user, notify the app | 426 // If the fetched data belongs to the currently focused user, notify the app |
| 422 // that it has to refresh it's user data. | 427 // that it has to refresh it's user data. |
| 423 if (user_id == user_id_) | 428 if (account_id == account_id_) |
| 424 NotifyUserUpdated(); | 429 NotifyUserUpdated(); |
| 425 | 430 |
| 426 if (user_id != user_id || devices.empty()) | 431 if (account_id != account_id || devices.empty()) |
| 427 return; | 432 return; |
| 428 | 433 |
| 429 // TODO(tengs): Currently, ProximityAuthSystem only supports one device. Once | 434 // TODO(tengs): Currently, ProximityAuthSystem only supports one device. Once |
| 430 // multiple devices are supported, we need to load all devices. | 435 // multiple devices are supported, we need to load all devices. |
| 431 std::string decoded_public_key, decoded_psk, decoded_challenge; | 436 std::string decoded_public_key, decoded_psk, decoded_challenge; |
| 432 if (!base::Base64UrlDecode(devices[0].public_key, | 437 if (!base::Base64UrlDecode(devices[0].public_key, |
| 433 base::Base64UrlDecodePolicy::REQUIRE_PADDING, | 438 base::Base64UrlDecodePolicy::REQUIRE_PADDING, |
| 434 &decoded_public_key) || | 439 &decoded_public_key) || |
| 435 !base::Base64UrlDecode(devices[0].psk, | 440 !base::Base64UrlDecode(devices[0].psk, |
| 436 base::Base64UrlDecodePolicy::REQUIRE_PADDING, | 441 base::Base64UrlDecodePolicy::REQUIRE_PADDING, |
| 437 &decoded_psk) || | 442 &decoded_psk) || |
| 438 !base::Base64UrlDecode(devices[0].challenge, | 443 !base::Base64UrlDecode(devices[0].challenge, |
| 439 base::Base64UrlDecodePolicy::REQUIRE_PADDING, | 444 base::Base64UrlDecodePolicy::REQUIRE_PADDING, |
| 440 &decoded_challenge)) { | 445 &decoded_challenge)) { |
| 441 PA_LOG(ERROR) << "Unable to base64url decode the input data."; | 446 PA_LOG(ERROR) << "Unable to base64url decode the input data."; |
| 442 return; | 447 return; |
| 443 } | 448 } |
| 444 | 449 |
| 445 proximity_auth::RemoteDevice::BluetoothType bluetooth_type = | 450 proximity_auth::RemoteDevice::BluetoothType bluetooth_type = |
| 446 devices[0].bluetooth_type == | 451 devices[0].bluetooth_type == |
| 447 chromeos::EasyUnlockDeviceKeyData::BLUETOOTH_LE | 452 chromeos::EasyUnlockDeviceKeyData::BLUETOOTH_LE |
| 448 ? proximity_auth::RemoteDevice::BLUETOOTH_LE | 453 ? proximity_auth::RemoteDevice::BLUETOOTH_LE |
| 449 : proximity_auth::RemoteDevice::BLUETOOTH_CLASSIC; | 454 : proximity_auth::RemoteDevice::BLUETOOTH_CLASSIC; |
| 450 | 455 |
| 451 proximity_auth::RemoteDevice remote_device( | 456 proximity_auth::RemoteDevice remote_device( |
| 452 user_id, std::string(), decoded_public_key, bluetooth_type, | 457 account_id.GetUserEmail(), std::string(), decoded_public_key, |
| 453 devices[0].bluetooth_address, decoded_psk, decoded_challenge); | 458 bluetooth_type, devices[0].bluetooth_address, decoded_psk, |
| 459 decoded_challenge); | |
| 454 PA_LOG(INFO) << "Loaded Remote Device:\n" | 460 PA_LOG(INFO) << "Loaded Remote Device:\n" |
| 455 << " user id: " << remote_device.user_id << "\n" | 461 << " user id: " << remote_device.user_id << "\n" |
| 456 << " name: " << remote_device.name << "\n" | 462 << " name: " << remote_device.name << "\n" |
| 457 << " public key" << devices[0].public_key << "\n" | 463 << " public key" << devices[0].public_key << "\n" |
| 458 << " bt_addr:" << remote_device.bluetooth_address; | 464 << " bt_addr:" << remote_device.bluetooth_address; |
| 459 OnRemoteDeviceChanged(&remote_device); | 465 OnRemoteDeviceChanged(&remote_device); |
| 460 } | 466 } |
| 461 | 467 |
| 462 const EasyUnlockServiceSignin::UserData* | 468 const EasyUnlockServiceSignin::UserData* |
| 463 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { | 469 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { |
| 464 if (user_id_.empty()) | 470 if (account_id_.is_valid()) |
| 465 return NULL; | 471 return NULL; |
|
achuithb
2015/12/04 10:12:53
nullptr
Alexander Alekseev
2015/12/04 12:44:07
Done.
| |
| 466 | 472 |
| 467 std::map<std::string, UserData*>::const_iterator it = | 473 std::map<AccountId, UserData*>::const_iterator it = |
|
achuithb
2015/12/04 10:12:53
auto?
Alexander Alekseev
2015/12/04 12:44:07
On 2015/12/04 10:12:53, achuithb wrote:
> auto?
Alexander Alekseev
2015/12/05 05:20:07
Done.
| |
| 468 user_data_.find(user_id_); | 474 user_data_.find(account_id_); |
| 469 if (it == user_data_.end()) | 475 if (it == user_data_.end()) |
| 470 return NULL; | 476 return NULL; |
|
achuithb
2015/12/04 10:12:53
nullptr. Could you please replace all instances in
Alexander Alekseev
2015/12/04 12:44:07
Done.
| |
| 471 if (it->second->state != USER_DATA_STATE_LOADED) | 477 if (it->second->state != USER_DATA_STATE_LOADED) |
| 472 return NULL; | 478 return NULL; |
| 473 return it->second; | 479 return it->second; |
| 474 } | 480 } |
| OLD | NEW |