Index: chrome/browser/chromeos/login/login_utils.cc |
=================================================================== |
--- chrome/browser/chromeos/login/login_utils.cc (revision 112243) |
+++ chrome/browser/chromeos/login/login_utils.cc (working copy) |
@@ -25,6 +25,7 @@ |
#include "chrome/browser/browser_shutdown.h" |
#include "chrome/browser/chromeos/boot_times_loader.h" |
#include "chrome/browser/chromeos/cros/network_library.h" |
+#include "chrome/browser/chromeos/cros/cert_library.h" |
Nikita (slow)
2011/12/01 14:34:13
nit: Move one line up.
zel
2011/12/02 02:35:23
Done.
|
#include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
#include "chrome/browser/chromeos/dbus/session_manager_client.h" |
#include "chrome/browser/chromeos/input_method/input_method_manager.h" |
@@ -104,6 +105,11 @@ |
const char kServiceScopeChromeOSDeviceManagement[] = |
"https://www.googleapis.com/auth/chromeosdevicemanagement"; |
+const char kServiceScopeChromeOSDocuments[] = |
+ "https://docs.google.com/feeds/ " |
+ "https://spreadsheets.google.com/feeds/ " |
+ "https://docs.googleusercontent.com/"; |
+ |
class InitializeCookieMonsterHelper { |
public: |
explicit InitializeCookieMonsterHelper( |
@@ -177,6 +183,9 @@ |
virtual void OnOAuthVerificationFailed(const std::string& user_name) {} |
virtual void OnUserCookiesFetchSucceeded(const std::string& user_name) {} |
virtual void OnUserCookiesFetchFailed(const std::string& user_name) {} |
+ virtual void OnDocumentsTokenFetchSucceeded(const std::string& username, |
+ const std::string& oauth2_token) {} |
+ virtual void OnDocumentsTokenFetchFailed(const std::string& username) {} |
}; |
OAuthLoginVerifier(OAuthLoginVerifier::Delegate* delegate, |
@@ -272,6 +281,16 @@ |
gaia_fetcher_.StartIssueAuthToken(sid_, lsid_, GaiaConstants::kGaiaService); |
} |
+ void StartDocsTokenRetreival() { |
+ DCHECK(!oauth1_token_.empty()); |
+ DCHECK(!oauth1_secret_.empty()); |
+ oauth_fetcher_.SetAutoFetchLimit( |
+ GaiaOAuthFetcher::OAUTH2_SERVICE_ACCESS_TOKEN); |
+ oauth_fetcher_.StartOAuthWrapBridge( |
+ oauth1_token_, oauth1_secret_, GaiaConstants::kGaiaOAuthDuration, |
+ std::string(kServiceScopeChromeOSDocuments)); |
+ } |
+ |
// Decides how to proceed on GAIA response and other errors. It can schedule |
// to rerun the verification process if detects transient network or service |
// errors. |
@@ -301,6 +320,7 @@ |
sid_ = sid; |
lsid_ = lsid; |
delegate_->OnOAuthVerificationSucceeded(username_, sid, lsid, auth); |
+ StartDocsTokenRetreival(); |
Nikita (slow)
2011/12/01 14:34:13
Could this be initiated from FetchSecondaryTokens(
zel
2011/12/02 02:35:23
All docs token retrieval related changes in this c
|
StartCookiesRetreival(); |
} |
@@ -346,6 +366,23 @@ |
OnCookueFetchFailed(error); |
} |
+ virtual void OnOAuthWrapBridgeSuccess( |
+ const std::string& service_name, |
+ const std::string& token, |
+ const std::string& expires_in) OVERRIDE { |
+ VLOG(1) << "Got OAuth access token for " << service_name; |
+ delegate_->OnDocumentsTokenFetchSucceeded(username_, token); |
+ } |
+ |
+ virtual void OnOAuthWrapBridgeFailure( |
+ const std::string& service_name, |
+ const GoogleServiceAuthError& error) OVERRIDE { |
+ LOG(WARNING) << "Failed to get OAuth access token for " << service_name |
+ << ", error: " << error.state(); |
+ if (!RetryOnError(error)) |
+ delegate_->OnDocumentsTokenFetchFailed(username_); |
+ } |
+ |
OAuthLoginVerifier::Delegate* delegate_; |
GaiaOAuthFetcher oauth_fetcher_; |
GaiaAuthFetcher gaia_fetcher_; |
@@ -1111,14 +1148,10 @@ |
} |
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) { |
@@ -1198,9 +1231,10 @@ |
if (!encoded_token.length() || !encoded_secret.length()) |
return false; |
- DCHECK(authenticator_.get()); |
- std::string decoded_token = authenticator_->DecryptToken(encoded_token); |
- std::string decoded_secret = authenticator_->DecryptToken(encoded_secret); |
+ std::string decoded_token = |
+ CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_token); |
+ std::string decoded_secret = |
+ CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_secret); |
if (!decoded_token.length() || !decoded_secret.length()) |
return false; |
@@ -1215,9 +1249,9 @@ |
// First store OAuth1 token + service for the current user profile... |
PrefService* pref_service = user_profile->GetPrefs(); |
pref_service->SetString(prefs::kOAuth1Token, |
- authenticator_->EncryptToken(token)); |
+ CrosLibrary::Get()->GetCertLibrary()->EncryptToken(token)); |
pref_service->SetString(prefs::kOAuth1Secret, |
- authenticator_->EncryptToken(secret)); |
+ CrosLibrary::Get()->GetCertLibrary()->EncryptToken(secret)); |
// ...then record the presence of valid OAuth token for this account in local |
// state as well. |