| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/base64url.h" | 9 #include "base/base64url.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_challenge_wrappe
r.h" | 18 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_challenge_wrappe
r.h" |
| 19 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | 19 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| 20 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.
h" | 20 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.
h" |
| 21 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_
factory.h" | 21 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_
factory.h" |
| 22 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 22 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| 23 #include "chrome/browser/signin/easy_unlock_app_manager.h" | 23 #include "chrome/browser/signin/easy_unlock_app_manager.h" |
| 24 #include "chrome/browser/signin/easy_unlock_metrics.h" | 24 #include "chrome/browser/signin/easy_unlock_metrics.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 277 } |
| 278 | 278 |
| 279 void EasyUnlockServiceSignin::ShutdownInternal() { | 279 void EasyUnlockServiceSignin::ShutdownInternal() { |
| 280 if (!service_active_) | 280 if (!service_active_) |
| 281 return; | 281 return; |
| 282 service_active_ = false; | 282 service_active_ = false; |
| 283 | 283 |
| 284 weak_ptr_factory_.InvalidateWeakPtrs(); | 284 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 285 proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this); | 285 proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this); |
| 286 chromeos::LoginState::Get()->RemoveObserver(this); | 286 chromeos::LoginState::Get()->RemoveObserver(this); |
| 287 base::STLDeleteContainerPairSecondPointers(user_data_.begin(), | |
| 288 user_data_.end()); | |
| 289 user_data_.clear(); | 287 user_data_.clear(); |
| 290 } | 288 } |
| 291 | 289 |
| 292 bool EasyUnlockServiceSignin::IsAllowedInternal() const { | 290 bool EasyUnlockServiceSignin::IsAllowedInternal() const { |
| 293 return service_active_ && account_id_.is_valid() && | 291 return service_active_ && account_id_.is_valid() && |
| 294 !chromeos::LoginState::Get()->IsUserLoggedIn(); | 292 !chromeos::LoginState::Get()->IsUserLoggedIn(); |
| 295 } | 293 } |
| 296 | 294 |
| 297 void EasyUnlockServiceSignin::OnWillFinalizeUnlock(bool success) { | 295 void EasyUnlockServiceSignin::OnWillFinalizeUnlock(bool success) { |
| 298 // This code path should only be exercised for the lock screen, not for the | 296 // This code path should only be exercised for the lock screen, not for the |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { | 371 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { |
| 374 // TODO(xiyuan): Revisit this when adding tests. | 372 // TODO(xiyuan): Revisit this when adding tests. |
| 375 if (!base::SysInfo::IsRunningOnChromeOS()) | 373 if (!base::SysInfo::IsRunningOnChromeOS()) |
| 376 return; | 374 return; |
| 377 | 375 |
| 378 if (!account_id_.is_valid() || !service_active_) | 376 if (!account_id_.is_valid() || !service_active_) |
| 379 return; | 377 return; |
| 380 | 378 |
| 381 const auto it = user_data_.find(account_id_); | 379 const auto it = user_data_.find(account_id_); |
| 382 if (it == user_data_.end()) | 380 if (it == user_data_.end()) |
| 383 user_data_.insert(std::make_pair(account_id_, new UserData())); | 381 user_data_.insert( |
| 382 std::make_pair(account_id_, base::MakeUnique<UserData>())); |
| 384 | 383 |
| 385 UserData* data = user_data_[account_id_]; | 384 UserData* data = user_data_[account_id_].get(); |
| 386 | 385 |
| 387 if (data->state != USER_DATA_STATE_INITIAL) | 386 if (data->state != USER_DATA_STATE_INITIAL) |
| 388 return; | 387 return; |
| 389 data->state = USER_DATA_STATE_LOADING; | 388 data->state = USER_DATA_STATE_LOADING; |
| 390 | 389 |
| 391 LoadDataForUser( | 390 LoadDataForUser( |
| 392 account_id_, | 391 account_id_, |
| 393 allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs, | 392 allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs, |
| 394 base::Bind(&EasyUnlockServiceSignin::OnUserDataLoaded, | 393 base::Bind(&EasyUnlockServiceSignin::OnUserDataLoaded, |
| 395 weak_ptr_factory_.GetWeakPtr(), account_id_)); | 394 weak_ptr_factory_.GetWeakPtr(), account_id_)); |
| 396 } | 395 } |
| 397 | 396 |
| 398 void EasyUnlockServiceSignin::OnUserDataLoaded( | 397 void EasyUnlockServiceSignin::OnUserDataLoaded( |
| 399 const AccountId& account_id, | 398 const AccountId& account_id, |
| 400 bool success, | 399 bool success, |
| 401 const chromeos::EasyUnlockDeviceKeyDataList& devices) { | 400 const chromeos::EasyUnlockDeviceKeyDataList& devices) { |
| 402 allow_cryptohome_backoff_ = false; | 401 allow_cryptohome_backoff_ = false; |
| 403 | 402 |
| 404 UserData* data = user_data_[account_id]; | 403 UserData* data = user_data_[account_id].get(); |
| 405 data->state = USER_DATA_STATE_LOADED; | 404 data->state = USER_DATA_STATE_LOADED; |
| 406 if (success) { | 405 if (success) { |
| 407 data->devices = devices; | 406 data->devices = devices; |
| 408 chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( | 407 chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( |
| 409 account_id, devices, &data->remote_devices_value); | 408 account_id, devices, &data->remote_devices_value); |
| 410 | 409 |
| 411 // User could have a NO_HARDLOCK state but has no remote devices if | 410 // User could have a NO_HARDLOCK state but has no remote devices if |
| 412 // previous user session shuts down before | 411 // previous user session shuts down before |
| 413 // CheckCryptohomeKeysAndMaybeHardlock finishes. Set NO_PAIRING state | 412 // CheckCryptohomeKeysAndMaybeHardlock finishes. Set NO_PAIRING state |
| 414 // and update UI to remove the confusing spinner in this case. | 413 // and update UI to remove the confusing spinner in this case. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 const EasyUnlockServiceSignin::UserData* | 467 const EasyUnlockServiceSignin::UserData* |
| 469 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { | 468 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { |
| 470 if (!account_id_.is_valid()) | 469 if (!account_id_.is_valid()) |
| 471 return nullptr; | 470 return nullptr; |
| 472 | 471 |
| 473 const auto it = user_data_.find(account_id_); | 472 const auto it = user_data_.find(account_id_); |
| 474 if (it == user_data_.end()) | 473 if (it == user_data_.end()) |
| 475 return nullptr; | 474 return nullptr; |
| 476 if (it->second->state != USER_DATA_STATE_LOADED) | 475 if (it->second->state != USER_DATA_STATE_LOADED) |
| 477 return nullptr; | 476 return nullptr; |
| 478 return it->second; | 477 return it->second.get(); |
| 479 } | 478 } |
| OLD | NEW |