Commit 3920c348 authored by antrim's avatar antrim Committed by Commit bot

Do not invalidate OAuth token status user when token handle is invalid.

BUG=484734

Review URL: https://codereview.chromium.org/1128923006

Cr-Commit-Position: refs/heads/master@{#329454}
parent 1c432b56
...@@ -1241,7 +1241,7 @@ void ExistingUserController::OnOAuth2TokensFetched( ...@@ -1241,7 +1241,7 @@ void ExistingUserController::OnOAuth2TokensFetched(
token_handle_util_.reset( token_handle_util_.reset(
new TokenHandleUtil(user_manager::UserManager::Get())); new TokenHandleUtil(user_manager::UserManager::Get()));
} }
if (!token_handle_util_->HasToken(user_context.GetUserID())) { if (token_handle_util_->ShouldObtainHandle(user_context.GetUserID())) {
token_handle_util_->GetTokenHandle( token_handle_util_->GetTokenHandle(
user_context.GetUserID(), user_context.GetAccessToken(), user_context.GetUserID(), user_context.GetAccessToken(),
base::Bind(&ExistingUserController::OnTokenHandleObtained, base::Bind(&ExistingUserController::OnTokenHandleObtained,
......
...@@ -433,9 +433,7 @@ void UserSelectionScreen::OnUserStatusChecked( ...@@ -433,9 +433,7 @@ void UserSelectionScreen::OnUserStatusChecked(
TokenHandleUtil::TokenHandleStatus status) { TokenHandleUtil::TokenHandleStatus status) {
if (status == TokenHandleUtil::INVALID) { if (status == TokenHandleUtil::INVALID) {
RecordReauthReason(user_id, ReauthReason::INVALID_TOKEN_HANDLE); RecordReauthReason(user_id, ReauthReason::INVALID_TOKEN_HANDLE);
user_manager::UserManager::Get()->SaveUserOAuthStatus( token_handle_util_->MarkHandleInvalid(user_id);
user_id, user_manager::User::OAUTH2_TOKEN_STATUS_INVALID);
token_handle_util_->DeleteToken(user_id);
SetAuthType(user_id, ONLINE_SIGN_IN, base::string16()); SetAuthType(user_id, ONLINE_SIGN_IN, base::string16());
} }
} }
......
...@@ -15,8 +15,15 @@ ...@@ -15,8 +15,15 @@
namespace { namespace {
const char kTokenHandlePref[] = "PasswordTokenHandle"; const char kTokenHandlePref[] = "PasswordTokenHandle";
const char kTokenHandleStatusPref[] = "TokenHandleStatus";
const char kHandleStatusValid[] = "valid";
const char kHandleStatusInvalid[] = "invalid";
const char* kDefaultHandleStatus = kHandleStatusValid;
static const int kMaxRetries = 3; static const int kMaxRetries = 3;
}
} // namespace
TokenHandleUtil::TokenHandleUtil(user_manager::UserManager* user_manager) TokenHandleUtil::TokenHandleUtil(user_manager::UserManager* user_manager)
: user_manager_(user_manager), weak_factory_(this) { : user_manager_(user_manager), weak_factory_(this) {
...@@ -37,17 +44,36 @@ bool TokenHandleUtil::HasToken(const user_manager::UserID& user_id) { ...@@ -37,17 +44,36 @@ bool TokenHandleUtil::HasToken(const user_manager::UserID& user_id) {
return !token.empty(); return !token.empty();
} }
void TokenHandleUtil::DeleteToken(const user_manager::UserID& user_id) { bool TokenHandleUtil::ShouldObtainHandle(const user_manager::UserID& user_id) {
const base::DictionaryValue* dict = nullptr;
std::string token;
if (!user_manager_->FindKnownUserPrefs(user_id, &dict))
return true;
if (!dict->GetString(kTokenHandlePref, &token))
return true;
if (token.empty())
return true;
std::string status(kDefaultHandleStatus);
dict->GetString(kTokenHandleStatusPref, &status);
return kHandleStatusInvalid == status;
}
void TokenHandleUtil::DeleteHandle(const user_manager::UserID& user_id) {
const base::DictionaryValue* dict = nullptr; const base::DictionaryValue* dict = nullptr;
if (!user_manager_->FindKnownUserPrefs(user_id, &dict)) if (!user_manager_->FindKnownUserPrefs(user_id, &dict))
return; return;
scoped_ptr<base::DictionaryValue> dict_copy(dict->DeepCopy()); scoped_ptr<base::DictionaryValue> dict_copy(dict->DeepCopy());
if (!dict_copy->Remove(kTokenHandlePref, nullptr)) dict_copy->Remove(kTokenHandlePref, nullptr);
return; dict_copy->Remove(kTokenHandleStatusPref, nullptr);
user_manager_->UpdateKnownUserPrefs(user_id, *dict_copy.get(), user_manager_->UpdateKnownUserPrefs(user_id, *dict_copy.get(),
/* replace values */ true); /* replace values */ true);
} }
void TokenHandleUtil::MarkHandleInvalid(const user_manager::UserID& user_id) {
user_manager_->SetKnownUserStringPref(user_id, kTokenHandleStatusPref,
kHandleStatusInvalid);
}
void TokenHandleUtil::CheckToken(const user_manager::UserID& user_id, void TokenHandleUtil::CheckToken(const user_manager::UserID& user_id,
const TokenValidationCallback& callback) { const TokenValidationCallback& callback) {
const base::DictionaryValue* dict = nullptr; const base::DictionaryValue* dict = nullptr;
...@@ -78,6 +104,8 @@ void TokenHandleUtil::CheckToken(const user_manager::UserID& user_id, ...@@ -78,6 +104,8 @@ void TokenHandleUtil::CheckToken(const user_manager::UserID& user_id,
void TokenHandleUtil::StoreTokenHandle(const user_manager::UserID& user_id, void TokenHandleUtil::StoreTokenHandle(const user_manager::UserID& user_id,
const std::string& handle) { const std::string& handle) {
user_manager_->SetKnownUserStringPref(user_id, kTokenHandlePref, handle); user_manager_->SetKnownUserStringPref(user_id, kTokenHandlePref, handle);
user_manager_->SetKnownUserStringPref(user_id, kTokenHandleStatusPref,
kHandleStatusValid);
} }
void TokenHandleUtil::OnValidationComplete(const std::string& token) { void TokenHandleUtil::OnValidationComplete(const std::string& token) {
......
...@@ -40,7 +40,14 @@ class TokenHandleUtil { ...@@ -40,7 +40,14 @@ class TokenHandleUtil {
bool HasToken(const user_manager::UserID& user_id); bool HasToken(const user_manager::UserID& user_id);
// Removes token handle for |user_id| from UserManager storage. // Removes token handle for |user_id| from UserManager storage.
void DeleteToken(const user_manager::UserID& user_id); void DeleteHandle(const user_manager::UserID& user_id);
// Marks current handle as invalid, new one should be obtained at next sign
// in.
void MarkHandleInvalid(const user_manager::UserID& user_id);
// Indicates if token handle for |user_id| is missing or marked as invalid.
bool ShouldObtainHandle(const user_manager::UserID& user_id);
// Performs token handle check for |user_id|. Will call |callback| with // Performs token handle check for |user_id|. Will call |callback| with
// corresponding result. // corresponding result.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment