Commit fc29f183 authored by zelidrag@chromium.org's avatar zelidrag@chromium.org

Re-authenticate oauth tokens after crash and restart Sync.

BUG=chromium-os:19788
TEST=See issue

Review URL: http://codereview.chromium.org/8537002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109826 0039d316-1c4b-4281-b951-d872f2087c98
parent 6e285c12
......@@ -550,8 +550,8 @@ void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line,
} else {
// We did not log in (we crashed or are debugging), so we need to
// set the user name for sync.
profile->GetProfileSyncService(
chromeos::UserManager::Get()->logged_in_user().email());
chromeos::LoginUtils::Get()->RestoreAuthenticationSession(
chromeos::UserManager::Get()->logged_in_user().email(), profile);
}
}
......
......@@ -438,6 +438,8 @@ class LoginUtilsImpl : public LoginUtils,
virtual scoped_refptr<Authenticator> CreateAuthenticator(
LoginStatusConsumer* consumer) OVERRIDE;
virtual void PrewarmAuthentication() OVERRIDE;
virtual void RestoreAuthenticationSession(const std::string& user_name,
Profile* profile) OVERRIDE;
virtual void FetchCookies(
Profile* profile,
const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE;
......@@ -479,6 +481,9 @@ class LoginUtilsImpl : public LoginUtils,
CommandLine *command_line);
private:
// Restarts OAuth session authentication check.
void KickStartAuthentication(Profile* profile);
// Reads OAuth1 token from user profile's prefs.
bool ReadOAuth1AccessToken(Profile* user_profile,
std::string* token,
......@@ -1019,6 +1024,23 @@ void LoginUtilsImpl::PrewarmAuthentication() {
}
}
void LoginUtilsImpl::RestoreAuthenticationSession(const std::string& username,
Profile* user_profile) {
username_ = username;
KickStartAuthentication(user_profile);
}
void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) {
if (!authenticator_.get())
CreateAuthenticator(NULL);
std::string oauth1_token;
std::string oauth1_secret;
if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret))
VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret);
authenticator_ = NULL;
}
void LoginUtilsImpl::SetBackgroundView(BackgroundView* background_view) {
background_view_ = background_view;
}
......@@ -1165,14 +1187,7 @@ void LoginUtilsImpl::OnOnlineStateChanged(bool online) {
// we need to kick of OAuth token verification process again.
if (UserManager::Get()->user_is_logged_in() &&
UserManager::Get()->offline_login() && online) {
if (!authenticator_.get())
CreateAuthenticator(NULL);
std::string oauth1_token;
std::string oauth1_secret;
Profile* user_profile = ProfileManager::GetDefaultProfile();
if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret))
VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret);
authenticator_ = NULL;
KickStartAuthentication(ProfileManager::GetDefaultProfile());
}
}
......
......@@ -89,6 +89,10 @@ class LoginUtils {
// Prewarms the authentication network connection.
virtual void PrewarmAuthentication() = 0;
// Restores authentication session after crash.
virtual void RestoreAuthenticationSession(const std::string& user_name,
Profile* profile) = 0;
// Given the credentials try to exchange them for
// full-fledged Google authentication cookies.
virtual void FetchCookies(
......
......@@ -107,6 +107,9 @@ class MockLoginUtils : public LoginUtils {
virtual void PrewarmAuthentication() {}
virtual void RestoreAuthenticationSession(const std::string& user_name,
Profile* profile) {}
virtual void FetchCookies(
Profile* profile,
const GaiaAuthConsumer::ClientLoginResult& credentials) {}
......
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