Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: chrome/browser/chromeos/login/login_utils.cc

Issue 7878002: Fixed GAIA session cookie fetching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/login/login_utils.cc
===================================================================
--- chrome/browser/chromeos/login/login_utils.cc (revision 100678)
+++ chrome/browser/chromeos/login/login_utils.cc (working copy)
@@ -50,6 +50,8 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/logging_chrome.h"
+#include "chrome/common/net/gaia/gaia_auth_consumer.h"
+#include "chrome/common/net/gaia/gaia_auth_fetcher.h"
#include "chrome/common/net/gaia/gaia_constants.h"
#include "chrome/common/net/gaia/gaia_urls.h"
#include "chrome/common/pref_names.h"
@@ -100,7 +102,8 @@
// Task override.
virtual void Run() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
+ LoginUtils::Get()->FetchCookies(ProfileManager::GetDefaultProfile(),
+ credentials_);
LoginUtils::Get()->StartSync(ProfileManager::GetDefaultProfile(),
credentials_);
}
@@ -221,6 +224,64 @@
DISALLOW_COPY_AND_ASSIGN(OAuthLoginVerifier);
};
+// Verifies OAuth1 access token by performing OAuthLogin.
+class UserSessionCookieFetcher : public GaiaAuthConsumer {
+ public:
+ explicit UserSessionCookieFetcher(Profile* user_profile)
+ : user_profile_(user_profile),
+ gaia_fetcher_(this,
+ std::string(GaiaConstants::kChromeOSSource),
+ user_profile->GetRequestContext()) {
+ }
+ virtual ~UserSessionCookieFetcher() {}
+
+ void Start(const GaiaAuthConsumer::ClientLoginResult& credentials) {
+ gaia_fetcher_.StartIssueAuthToken(credentials.sid, credentials.lsid,
+ GaiaConstants::kGaiaService);
+ }
+
+ // GaiaAuthConsumer overrides.
+ virtual void OnIssueAuthTokenSuccess(const std::string& service,
+ const std::string& auth_token) OVERRIDE {
+ gaia_fetcher_.StartMergeSession(auth_token);
+ }
+
+ virtual void OnIssueAuthTokenFailure(const std::string& service,
+ const GoogleServiceAuthError& error) OVERRIDE {
+ LOG(WARNING) << "Failed IssueAuthToken request,"
+ << " error.state=" << error.state();
+ HandlerGaiaAuthError(error);
+ delete this;
+ }
+
+ virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE {
+ VLOG(1) << "MergeSession successful.";
+ delete this;
+ }
+
+ virtual void OnMergeSessionFailure(
+ const GoogleServiceAuthError& error) OVERRIDE {
+ LOG(WARNING) << "Failed MergeSession request,"
+ << " error.state=" << error.state();
+ HandlerGaiaAuthError(error);
+ delete this;
+ }
+
+ private:
+ void HandlerGaiaAuthError(const GoogleServiceAuthError& error) {
+ // Mark this account's login state as offline if we encountered a network
+ // error. That will make us verify user OAuth token and try to fetch session
+ // cookies again once we detect that the machine comes online.
+ if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED)
+ UserManager::Get()->set_offline_login(true);
+ }
+ Profile* user_profile_;
xiyuan 2011/09/12 22:21:05 nit: seems no need to keep this as member variable
zel 2011/09/12 23:11:10 Done.
+ GaiaAuthFetcher gaia_fetcher_;
+
+ DISALLOW_COPY_AND_ASSIGN(UserSessionCookieFetcher);
+};
+
+
// Fetches an OAuth token and initializes user policy with it.
class PolicyOAuthFetcher : public GaiaOAuthConsumer {
public:
@@ -630,16 +691,21 @@
oauth_fetcher_->StartGetOAuthTokenRequest();
}
-void LoginUtilsImpl::FetchCookies(
- Profile* profile,
+void LoginUtilsImpl::FetchCookies(Profile* user_profile,
const GaiaAuthConsumer::ClientLoginResult& credentials) {
- // Take the credentials passed in and try to exchange them for
- // full-fledged Google authentication cookies. This is
- // best-effort; it's possible that we'll fail due to network
- // troubles or some such.
- // CookieFetcher will delete itself once done.
- CookieFetcher* cf = new CookieFetcher(profile);
- cf->AttemptFetch(credentials.data);
+ if (!using_oauth_) {
+ // Take the credentials passed in and try to exchange them for
+ // full-fledged Google authentication cookies. This is
+ // best-effort; it's possible that we'll fail due to network
+ // troubles or some such.
+ // CookieFetcher will delete itself once done.
+ CookieFetcher* cf = new CookieFetcher(user_profile);
+ cf->AttemptFetch(credentials.data);
+ } else {
+ UserSessionCookieFetcher* cf =
+ new UserSessionCookieFetcher(user_profile);
+ cf->Start(credentials);
+ }
}
void LoginUtilsImpl::StartTokenServices(Profile* user_profile) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698