| Index: chrome/browser/signin/easy_unlock_service_signin_chromeos.cc
|
| diff --git a/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc b/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc
|
| index 862bc56f3719b6d461d6d45e38670be5b6ff7746..18aa774d393ec86f5de73335da1476c0b5a825a0 100644
|
| --- a/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc
|
| +++ b/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc
|
| @@ -45,7 +45,7 @@ uint32 GetNextBackoffInterval(uint32 backoff) {
|
| }
|
|
|
| void LoadDataForUser(
|
| - const std::string& user_id,
|
| + const AccountId& account_id,
|
| uint32 backoff_ms,
|
| const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback);
|
|
|
| @@ -56,7 +56,7 @@ void LoadDataForUser(
|
| // |LoadDataForUser| call with some backoff. If no further retires are allowed,
|
| // it invokes |callback| with the |LoadDataForUser| results.
|
| void RetryDataLoadOnError(
|
| - const std::string& user_id,
|
| + const AccountId& account_id,
|
| uint32 backoff_ms,
|
| const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback,
|
| bool success,
|
| @@ -74,13 +74,13 @@ void RetryDataLoadOnError(
|
|
|
| base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
|
| FROM_HERE,
|
| - base::Bind(&LoadDataForUser, user_id, next_backoff_ms, callback),
|
| + base::Bind(&LoadDataForUser, account_id, next_backoff_ms, callback),
|
| base::TimeDelta::FromMilliseconds(next_backoff_ms));
|
| }
|
|
|
| // Loads device data list associated with the user's Easy unlock keys.
|
| void LoadDataForUser(
|
| - const std::string& user_id,
|
| + const AccountId& account_id,
|
| uint32 backoff_ms,
|
| const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback) {
|
| chromeos::EasyUnlockKeyManager* key_manager =
|
| @@ -88,8 +88,8 @@ void LoadDataForUser(
|
| DCHECK(key_manager);
|
|
|
| key_manager->GetDeviceDataList(
|
| - chromeos::UserContext(AccountId::FromUserEmail(user_id)),
|
| - base::Bind(&RetryDataLoadOnError, user_id, backoff_ms, callback));
|
| + chromeos::UserContext(account_id),
|
| + base::Bind(&RetryDataLoadOnError, account_id, backoff_ms, callback));
|
| }
|
|
|
| } // namespace
|
| @@ -102,28 +102,25 @@ EasyUnlockServiceSignin::UserData::~UserData() {}
|
|
|
| EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile)
|
| : EasyUnlockService(profile),
|
| - allow_cryptohome_backoff_(true),
|
| - service_active_(false),
|
| + account_id_(EmptyAccountId()),
|
| user_pod_last_focused_timestamp_(base::TimeTicks::Now()),
|
| - weak_ptr_factory_(this) {
|
| -}
|
| + weak_ptr_factory_(this) {}
|
|
|
| EasyUnlockServiceSignin::~EasyUnlockServiceSignin() {
|
| }
|
|
|
| -void EasyUnlockServiceSignin::SetCurrentUser(const std::string& user_id) {
|
| - OnFocusedUserChanged(user_id);
|
| +void EasyUnlockServiceSignin::SetCurrentUser(const AccountId& account_id) {
|
| + OnFocusedUserChanged(account_id);
|
| }
|
|
|
| void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice(
|
| - const std::string& user_id,
|
| + const AccountId& account_id,
|
| const std::string& device_public_key,
|
| const std::string& channel_binding_data,
|
| base::Callback<void(const std::string& wraped_challenge)> callback) {
|
| - std::map<std::string, UserData*>::const_iterator it =
|
| - user_data_.find(user_id);
|
| + auto it = user_data_.find(account_id);
|
| if (it == user_data_.end() || it->second->state != USER_DATA_STATE_LOADED) {
|
| - PA_LOG(ERROR) << "TPM data not loaded for " << user_id;
|
| + PA_LOG(ERROR) << "TPM data not loaded for " << account_id.Serialize();
|
| callback.Run(std::string());
|
| return;
|
| }
|
| @@ -134,16 +131,18 @@ void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice(
|
| &device_public_key_base64);
|
| for (const auto& device_data : it->second->devices) {
|
| if (device_data.public_key == device_public_key_base64) {
|
| - PA_LOG(INFO) << "Wrapping challenge for " << user_id << "...";
|
| + PA_LOG(INFO) << "Wrapping challenge for " << account_id.Serialize()
|
| + << "...";
|
| challenge_wrapper_.reset(new chromeos::EasyUnlockChallengeWrapper(
|
| - device_data.challenge, channel_binding_data, user_id,
|
| + device_data.challenge, channel_binding_data, account_id,
|
| EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile())));
|
| challenge_wrapper_->WrapChallenge(callback);
|
| return;
|
| }
|
| }
|
|
|
| - PA_LOG(ERROR) << "Unable to find device record for " << user_id;
|
| + PA_LOG(ERROR) << "Unable to find device record for "
|
| + << account_id.Serialize();
|
| callback.Run(std::string());
|
| }
|
|
|
| @@ -151,8 +150,8 @@ EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const {
|
| return EasyUnlockService::TYPE_SIGNIN;
|
| }
|
|
|
| -std::string EasyUnlockServiceSignin::GetUserEmail() const {
|
| - return user_id_;
|
| +AccountId EasyUnlockServiceSignin::GetAccountId() const {
|
| + return account_id_;
|
| }
|
|
|
| void EasyUnlockServiceSignin::LaunchSetup() {
|
| @@ -160,7 +159,7 @@ void EasyUnlockServiceSignin::LaunchSetup() {
|
| }
|
|
|
| const base::DictionaryValue* EasyUnlockServiceSignin::GetPermitAccess() const {
|
| - return NULL;
|
| + return nullptr;
|
| }
|
|
|
| void EasyUnlockServiceSignin::SetPermitAccess(
|
| @@ -175,7 +174,7 @@ void EasyUnlockServiceSignin::ClearPermitAccess() {
|
| const base::ListValue* EasyUnlockServiceSignin::GetRemoteDevices() const {
|
| const UserData* data = FindLoadedDataForCurrentUser();
|
| if (!data)
|
| - return NULL;
|
| + return nullptr;
|
| return &data->remote_devices_value;
|
| }
|
|
|
| @@ -221,9 +220,11 @@ std::string EasyUnlockServiceSignin::GetWrappedSecret() const {
|
| }
|
|
|
| void EasyUnlockServiceSignin::RecordEasySignInOutcome(
|
| - const std::string& user_id,
|
| + const AccountId& account_id,
|
| bool success) const {
|
| - DCHECK_EQ(GetUserEmail(), user_id);
|
| + DCHECK(GetAccountId() == account_id)
|
| + << "GetAccountId()=" << GetAccountId().Serialize()
|
| + << " != account_id=" << account_id.Serialize();
|
|
|
| RecordEasyUnlockSigninEvent(
|
| success ? EASY_UNLOCK_SUCCESS : EASY_UNLOCK_FAILURE);
|
| @@ -235,10 +236,10 @@ void EasyUnlockServiceSignin::RecordEasySignInOutcome(
|
| }
|
|
|
| void EasyUnlockServiceSignin::RecordPasswordLoginEvent(
|
| - const std::string& user_id) const {
|
| + const AccountId& account_id) const {
|
| // This happens during tests, where a user could log in without the user pod
|
| // being focused.
|
| - if (GetUserEmail() != user_id)
|
| + if (GetAccountId() != account_id)
|
| return;
|
|
|
| if (!IsEnabled())
|
| @@ -270,8 +271,8 @@ void EasyUnlockServiceSignin::InitializeInternal() {
|
| proximity_auth::ScreenlockBridge* screenlock_bridge =
|
| proximity_auth::ScreenlockBridge::Get();
|
| screenlock_bridge->AddObserver(this);
|
| - if (!screenlock_bridge->focused_user_id().empty())
|
| - OnFocusedUserChanged(screenlock_bridge->focused_user_id());
|
| + if (screenlock_bridge->focused_account_id().is_valid())
|
| + OnFocusedUserChanged(screenlock_bridge->focused_account_id());
|
| }
|
|
|
| void EasyUnlockServiceSignin::ShutdownInternal() {
|
| @@ -287,8 +288,7 @@ void EasyUnlockServiceSignin::ShutdownInternal() {
|
| }
|
|
|
| bool EasyUnlockServiceSignin::IsAllowedInternal() const {
|
| - return service_active_ &&
|
| - !user_id_.empty() &&
|
| + return service_active_ && account_id_.is_valid() &&
|
| !chromeos::LoginState::Get()->IsUserLoggedIn();
|
| }
|
|
|
| @@ -328,15 +328,18 @@ void EasyUnlockServiceSignin::OnScreenDidUnlock(
|
| Shutdown();
|
| }
|
|
|
| -void EasyUnlockServiceSignin::OnFocusedUserChanged(const std::string& user_id) {
|
| - if (user_id_ == user_id)
|
| +void EasyUnlockServiceSignin::OnFocusedUserChanged(
|
| + const AccountId& account_id) {
|
| + if (account_id_ == account_id)
|
| return;
|
|
|
| - // Setting or clearing the user_id may changed |IsAllowed| value, so in these
|
| + // Setting or clearing the account_id may changed |IsAllowed| value, so in
|
| + // these
|
| // cases update the app state. Otherwise, it's enough to notify the app the
|
| // user data has been updated.
|
| - bool should_update_app_state = user_id_.empty() != user_id.empty();
|
| - user_id_ = user_id;
|
| + const bool should_update_app_state =
|
| + account_id_.is_valid() != account_id.is_valid();
|
| + account_id_ = account_id;
|
| user_pod_last_focused_timestamp_ = base::TimeTicks::Now();
|
|
|
| ResetScreenlockState();
|
| @@ -371,39 +374,38 @@ void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() {
|
| if (!base::SysInfo::IsRunningOnChromeOS())
|
| return;
|
|
|
| - if (user_id_.empty() || !service_active_)
|
| + if (account_id_.is_valid() || !service_active_)
|
| return;
|
|
|
| - std::map<std::string, UserData*>::iterator it = user_data_.find(user_id_);
|
| + const auto it = user_data_.find(account_id_);
|
| if (it == user_data_.end())
|
| - user_data_.insert(std::make_pair(user_id_, new UserData()));
|
| + user_data_.insert(std::make_pair(account_id_, new UserData()));
|
|
|
| - UserData* data = user_data_[user_id_];
|
| + UserData* data = user_data_[account_id_];
|
|
|
| if (data->state != USER_DATA_STATE_INITIAL)
|
| return;
|
| data->state = USER_DATA_STATE_LOADING;
|
|
|
| LoadDataForUser(
|
| - user_id_,
|
| + account_id_,
|
| allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs,
|
| base::Bind(&EasyUnlockServiceSignin::OnUserDataLoaded,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - user_id_));
|
| + weak_ptr_factory_.GetWeakPtr(), account_id_));
|
| }
|
|
|
| void EasyUnlockServiceSignin::OnUserDataLoaded(
|
| - const std::string& user_id,
|
| + const AccountId& account_id,
|
| bool success,
|
| const chromeos::EasyUnlockDeviceKeyDataList& devices) {
|
| allow_cryptohome_backoff_ = false;
|
|
|
| - UserData* data = user_data_[user_id];
|
| + UserData* data = user_data_[account_id];
|
| data->state = USER_DATA_STATE_LOADED;
|
| if (success) {
|
| data->devices = devices;
|
| chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList(
|
| - user_id, devices, &data->remote_devices_value);
|
| + account_id, devices, &data->remote_devices_value);
|
|
|
| // User could have a NO_HARDLOCK state but has no remote devices if
|
| // previous user session shuts down before
|
| @@ -413,17 +415,17 @@ void EasyUnlockServiceSignin::OnUserDataLoaded(
|
| if (devices.empty() &&
|
| GetPersistedHardlockState(&hardlock_state) &&
|
| hardlock_state == EasyUnlockScreenlockStateHandler::NO_HARDLOCK) {
|
| - SetHardlockStateForUser(user_id,
|
| + SetHardlockStateForUser(account_id,
|
| EasyUnlockScreenlockStateHandler::NO_PAIRING);
|
| }
|
| }
|
|
|
| // If the fetched data belongs to the currently focused user, notify the app
|
| // that it has to refresh it's user data.
|
| - if (user_id == user_id_)
|
| + if (account_id == account_id_)
|
| NotifyUserUpdated();
|
|
|
| - if (user_id != user_id || devices.empty())
|
| + if (devices.empty())
|
| return;
|
|
|
| proximity_auth::RemoteDeviceList remote_devices;
|
| @@ -447,8 +449,9 @@ void EasyUnlockServiceSignin::OnUserDataLoaded(
|
| ? proximity_auth::RemoteDevice::BLUETOOTH_LE
|
| : proximity_auth::RemoteDevice::BLUETOOTH_CLASSIC;
|
| proximity_auth::RemoteDevice remote_device(
|
| - user_id, std::string(), decoded_public_key, bluetooth_type,
|
| - device.bluetooth_address, decoded_psk, decoded_challenge);
|
| + account_id.GetUserEmail(), std::string(), decoded_public_key,
|
| + bluetooth_type, device.bluetooth_address, decoded_psk,
|
| + decoded_challenge);
|
| remote_devices.push_back(remote_device);
|
| PA_LOG(INFO) << "Loaded Remote Device:\n"
|
| << " user id: " << remote_device.user_id << "\n"
|
| @@ -458,19 +461,18 @@ void EasyUnlockServiceSignin::OnUserDataLoaded(
|
| << " type:" << static_cast<int>(remote_device.bluetooth_type);
|
| }
|
|
|
| - SetProximityAuthDevices(user_id, remote_devices);
|
| + SetProximityAuthDevices(account_id, remote_devices);
|
| }
|
|
|
| const EasyUnlockServiceSignin::UserData*
|
| EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const {
|
| - if (user_id_.empty())
|
| - return NULL;
|
| + if (account_id_.is_valid())
|
| + return nullptr;
|
|
|
| - std::map<std::string, UserData*>::const_iterator it =
|
| - user_data_.find(user_id_);
|
| + const auto it = user_data_.find(account_id_);
|
| if (it == user_data_.end())
|
| - return NULL;
|
| + return nullptr;
|
| if (it->second->state != USER_DATA_STATE_LOADED)
|
| - return NULL;
|
| + return nullptr;
|
| return it->second;
|
| }
|
|
|