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