Index: chrome/browser/signin/easy_unlock_service.cc |
diff --git a/chrome/browser/signin/easy_unlock_service.cc b/chrome/browser/signin/easy_unlock_service.cc |
index 1dd6a91be2a21a5ca28f66e4c0b83cb5ac99a016..5fa953599c985c02c98842f4f6e16d28b16caa9b 100644 |
--- a/chrome/browser/signin/easy_unlock_service.cc |
+++ b/chrome/browser/signin/easy_unlock_service.cc |
@@ -303,25 +303,25 @@ void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) { |
} |
// static |
-void EasyUnlockService::ResetLocalStateForUser(const std::string& user_id) { |
- DCHECK(!user_id.empty()); |
+void EasyUnlockService::ResetLocalStateForUser(const AccountId& account_id) { |
+ DCHECK(account_id.is_valid()); |
PrefService* local_state = GetLocalState(); |
if (!local_state) |
return; |
DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); |
- update->RemoveWithoutPathExpansion(user_id, NULL); |
+ update->RemoveWithoutPathExpansion(account_id.GetUserEmail(), NULL); |
#if defined(OS_CHROMEOS) |
- EasyUnlockTpmKeyManager::ResetLocalStateForUser(user_id); |
+ EasyUnlockTpmKeyManager::ResetLocalStateForUser(account_id); |
#endif |
} |
// static |
EasyUnlockService::UserSettings EasyUnlockService::GetUserSettings( |
- const std::string& user_id) { |
- DCHECK(!user_id.empty()); |
+ const AccountId& account_id) { |
+ DCHECK(account_id.is_valid()); |
UserSettings user_settings; |
PrefService* local_state = GetLocalState(); |
@@ -334,8 +334,8 @@ EasyUnlockService::UserSettings EasyUnlockService::GetUserSettings( |
return user_settings; |
const base::DictionaryValue* user_prefs_dict; |
- if (!all_user_prefs_dict->GetDictionaryWithoutPathExpansion(user_id, |
- &user_prefs_dict)) |
+ if (!all_user_prefs_dict->GetDictionaryWithoutPathExpansion( |
+ account_id.GetUserEmail(), &user_prefs_dict)) |
return user_settings; |
user_prefs_dict->GetBooleanWithoutPathExpansion( |
@@ -397,14 +397,14 @@ void EasyUnlockService::OpenSetupApp() { |
void EasyUnlockService::SetHardlockState( |
EasyUnlockScreenlockStateHandler::HardlockState state) { |
- const std::string user_id = GetUserEmail(); |
- if (user_id.empty()) |
+ const AccountId& account_id = GetAccountId(); |
+ if (!account_id.is_valid()) |
return; |
if (state == GetHardlockState()) |
return; |
- SetHardlockStateForUser(user_id, state); |
+ SetHardlockStateForUser(account_id, state); |
} |
EasyUnlockScreenlockStateHandler::HardlockState |
@@ -418,8 +418,8 @@ EasyUnlockService::GetHardlockState() const { |
bool EasyUnlockService::GetPersistedHardlockState( |
EasyUnlockScreenlockStateHandler::HardlockState* state) const { |
- std::string user_id = GetUserEmail(); |
- if (user_id.empty()) |
+ const AccountId& account_id = GetAccountId(); |
+ if (!account_id.is_valid()) |
return false; |
PrefService* local_state = GetLocalState(); |
@@ -429,7 +429,9 @@ bool EasyUnlockService::GetPersistedHardlockState( |
const base::DictionaryValue* dict = |
local_state->GetDictionary(prefs::kEasyUnlockHardlockState); |
int state_int; |
- if (dict && dict->GetIntegerWithoutPathExpansion(user_id, &state_int)) { |
+ if (dict && |
+ dict->GetIntegerWithoutPathExpansion(account_id.GetUserEmail(), |
+ &state_int)) { |
*state = |
static_cast<EasyUnlockScreenlockStateHandler::HardlockState>(state_int); |
return true; |
@@ -461,7 +463,7 @@ EasyUnlockScreenlockStateHandler* |
return NULL; |
if (!screenlock_state_handler_) { |
screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( |
- GetUserEmail(), GetHardlockState(), |
+ GetAccountId(), GetHardlockState(), |
proximity_auth::ScreenlockBridge::Get())); |
} |
return screenlock_state_handler_.get(); |
@@ -485,7 +487,7 @@ bool EasyUnlockService::UpdateScreenlockState(ScreenlockState state) { |
auth_attempt_.reset(); |
if (!handler->InStateValidOnRemoteAuthFailure()) |
- HandleAuthFailure(GetUserEmail()); |
+ HandleAuthFailure(GetAccountId()); |
} |
FOR_EACH_OBSERVER( |
@@ -501,29 +503,30 @@ ScreenlockState EasyUnlockService::GetScreenlockState() { |
return handler->state(); |
} |
-void EasyUnlockService::AttemptAuth(const std::string& user_id) { |
- AttemptAuth(user_id, AttemptAuthCallback()); |
+void EasyUnlockService::AttemptAuth(const AccountId& account_id) { |
+ AttemptAuth(account_id, AttemptAuthCallback()); |
} |
-void EasyUnlockService::AttemptAuth(const std::string& user_id, |
+void EasyUnlockService::AttemptAuth(const AccountId& account_id, |
const AttemptAuthCallback& callback) { |
const EasyUnlockAuthAttempt::Type auth_attempt_type = |
GetType() == TYPE_REGULAR ? EasyUnlockAuthAttempt::TYPE_UNLOCK |
: EasyUnlockAuthAttempt::TYPE_SIGNIN; |
- const std::string user_email = GetUserEmail(); |
- if (user_email.empty()) { |
- LOG(ERROR) << "Empty user email. Refresh token might go bad."; |
+ if (!GetAccountId().is_valid()) { |
+ LOG(ERROR) << "Empty user account. Refresh token might go bad."; |
if (!callback.is_null()) { |
const bool kFailure = false; |
- callback.Run(auth_attempt_type, kFailure, user_id, std::string(), |
+ callback.Run(auth_attempt_type, kFailure, account_id, std::string(), |
std::string()); |
} |
return; |
} |
- CHECK_EQ(GetUserEmail(), user_id); |
+ CHECK(GetAccountId() == account_id) |
+ << "Check failed: " << GetAccountId().Serialize() << " vs " |
+ << account_id.Serialize(); |
- auth_attempt_.reset(new EasyUnlockAuthAttempt(app_manager_.get(), user_id, |
+ auth_attempt_.reset(new EasyUnlockAuthAttempt(app_manager_.get(), account_id, |
auth_attempt_type, callback)); |
if (!auth_attempt_->Start()) |
auth_attempt_.reset(); |
@@ -534,7 +537,7 @@ void EasyUnlockService::AttemptAuth(const std::string& user_id, |
if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) && |
proximity_auth_system_) { |
- proximity_auth_system_->OnAuthAttempted(user_id); |
+ proximity_auth_system_->OnAuthAttempted(account_id); |
} |
} |
@@ -543,7 +546,7 @@ void EasyUnlockService::FinalizeUnlock(bool success) { |
return; |
this->OnWillFinalizeUnlock(success); |
- auth_attempt_->FinalizeUnlock(GetUserEmail(), success); |
+ auth_attempt_->FinalizeUnlock(GetAccountId(), success); |
auth_attempt_.reset(); |
// TODO(isherman): If observing screen unlock events, is there a race |
// condition in terms of reading the service's state vs. the app setting the |
@@ -552,7 +555,7 @@ void EasyUnlockService::FinalizeUnlock(bool success) { |
// Make sure that the lock screen is updated on failure. |
if (!success) { |
RecordEasyUnlockScreenUnlockEvent(EASY_UNLOCK_FAILURE); |
- HandleAuthFailure(GetUserEmail()); |
+ HandleAuthFailure(GetAccountId()); |
} |
} |
@@ -561,18 +564,18 @@ void EasyUnlockService::FinalizeSignin(const std::string& key) { |
return; |
std::string wrapped_secret = GetWrappedSecret(); |
if (!wrapped_secret.empty()) |
- auth_attempt_->FinalizeSignin(GetUserEmail(), wrapped_secret, key); |
+ auth_attempt_->FinalizeSignin(GetAccountId(), wrapped_secret, key); |
auth_attempt_.reset(); |
// Processing empty key is equivalent to auth cancellation. In this case the |
// signin request will not actually be processed by login stack, so the lock |
// screen state should be set from here. |
if (key.empty()) |
- HandleAuthFailure(GetUserEmail()); |
+ HandleAuthFailure(GetAccountId()); |
} |
-void EasyUnlockService::HandleAuthFailure(const std::string& user_id) { |
- if (user_id != GetUserEmail()) |
+void EasyUnlockService::HandleAuthFailure(const AccountId& account_id) { |
+ if (account_id != GetAccountId()) |
return; |
if (!screenlock_state_handler_.get()) |
@@ -584,8 +587,8 @@ void EasyUnlockService::HandleAuthFailure(const std::string& user_id) { |
void EasyUnlockService::CheckCryptohomeKeysAndMaybeHardlock() { |
#if defined(OS_CHROMEOS) |
- std::string user_id = GetUserEmail(); |
- if (user_id.empty()) |
+ const AccountId& account_id = GetAccountId(); |
+ if (!account_id.is_valid()) |
return; |
const base::ListValue* device_list = GetRemoteDevices(); |
@@ -613,9 +616,9 @@ void EasyUnlockService::CheckCryptohomeKeysAndMaybeHardlock() { |
DCHECK(key_manager); |
key_manager->GetDeviceDataList( |
- chromeos::UserContext(AccountId::FromUserEmail(user_id)), |
+ chromeos::UserContext(account_id), |
base::Bind(&EasyUnlockService::OnCryptohomeKeysFetchedForChecking, |
- weak_ptr_factory_.GetWeakPtr(), user_id, paired_devices)); |
+ weak_ptr_factory_.GetWeakPtr(), account_id, paired_devices)); |
#endif |
} |
@@ -704,14 +707,15 @@ void EasyUnlockService::DisableAppWithoutResettingScreenlockState() { |
} |
void EasyUnlockService::NotifyUserUpdated() { |
- std::string user_id = GetUserEmail(); |
- if (user_id.empty()) |
+ const AccountId& account_id = GetAccountId(); |
+ if (!account_id.is_valid()) |
return; |
// Notify the easy unlock app that the user info changed. |
bool logged_in = GetType() == TYPE_REGULAR; |
bool data_ready = logged_in || GetRemoteDevices() != NULL; |
- app_manager_->SendUserUpdatedEvent(user_id, logged_in, data_ready); |
+ app_manager_->SendUserUpdatedEvent(account_id.GetUserEmail(), logged_in, |
+ data_ready); |
} |
void EasyUnlockService::NotifyTurnOffOperationStatusChanged() { |
@@ -764,18 +768,19 @@ void EasyUnlockService::OnBluetoothAdapterPresentChanged() { |
} |
void EasyUnlockService::SetHardlockStateForUser( |
- const std::string& user_id, |
- EasyUnlockScreenlockStateHandler::HardlockState state) { |
- DCHECK(!user_id.empty()); |
+ const AccountId& account_id, |
+ EasyUnlockScreenlockStateHandler::HardlockState state) { |
+ DCHECK(account_id.is_valid()); |
PrefService* local_state = GetLocalState(); |
if (!local_state) |
return; |
DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); |
- update->SetIntegerWithoutPathExpansion(user_id, static_cast<int>(state)); |
+ update->SetIntegerWithoutPathExpansion(account_id.GetUserEmail(), |
+ static_cast<int>(state)); |
- if (GetUserEmail() == user_id) |
+ if (GetAccountId() == account_id) |
SetScreenlockHardlockedState(state); |
} |
@@ -834,7 +839,7 @@ EasyUnlockAuthEvent EasyUnlockService::GetPasswordAuthEvent() const { |
} |
void EasyUnlockService::SetProximityAuthDevices( |
- const std::string& user_id, |
+ const AccountId& account_id, |
const proximity_auth::RemoteDeviceList& remote_devices) { |
if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) |
@@ -849,20 +854,20 @@ void EasyUnlockService::SetProximityAuthDevices( |
proximity_auth_client())); |
} |
- proximity_auth_system_->SetRemoteDevicesForUser(user_id, remote_devices); |
+ proximity_auth_system_->SetRemoteDevicesForUser(account_id, remote_devices); |
proximity_auth_system_->Start(); |
} |
#if defined(OS_CHROMEOS) |
void EasyUnlockService::OnCryptohomeKeysFetchedForChecking( |
- const std::string& user_id, |
+ const AccountId& account_id, |
const std::set<std::string> paired_devices, |
bool success, |
const chromeos::EasyUnlockDeviceKeyDataList& key_data_list) { |
- DCHECK(!user_id.empty() && !paired_devices.empty()); |
+ DCHECK(account_id.is_valid() && !paired_devices.empty()); |
if (!success) { |
- SetHardlockStateForUser(user_id, |
+ SetHardlockStateForUser(account_id, |
EasyUnlockScreenlockStateHandler::NO_PAIRING); |
return; |
} |
@@ -874,10 +879,9 @@ void EasyUnlockService::OnCryptohomeKeysFetchedForChecking( |
if (paired_devices != devices_in_cryptohome || |
GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { |
SetHardlockStateForUser( |
- user_id, |
- devices_in_cryptohome.empty() |
- ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED |
- : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); |
+ account_id, devices_in_cryptohome.empty() |
+ ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED |
+ : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); |
} |
} |
#endif |
@@ -896,7 +900,7 @@ void EasyUnlockService::OnSuspendDone() { |
} |
void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() { |
- if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetUserEmail().empty() || |
+ if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetAccountId().empty() || |
GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { |
return; |
} |