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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/login/login_utils.h" 5 #include "chrome/browser/chromeos/login/login_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "chrome/browser/net/preconnect.h" 43 #include "chrome/browser/net/preconnect.h"
44 #include "chrome/browser/policy/browser_policy_connector.h" 44 #include "chrome/browser/policy/browser_policy_connector.h"
45 #include "chrome/browser/prefs/pref_member.h" 45 #include "chrome/browser/prefs/pref_member.h"
46 #include "chrome/browser/profiles/profile.h" 46 #include "chrome/browser/profiles/profile.h"
47 #include "chrome/browser/profiles/profile_manager.h" 47 #include "chrome/browser/profiles/profile_manager.h"
48 #include "chrome/browser/sync/profile_sync_service.h" 48 #include "chrome/browser/sync/profile_sync_service.h"
49 #include "chrome/browser/ui/browser_init.h" 49 #include "chrome/browser/ui/browser_init.h"
50 #include "chrome/common/chrome_paths.h" 50 #include "chrome/common/chrome_paths.h"
51 #include "chrome/common/chrome_switches.h" 51 #include "chrome/common/chrome_switches.h"
52 #include "chrome/common/logging_chrome.h" 52 #include "chrome/common/logging_chrome.h"
53 #include "chrome/common/net/gaia/gaia_auth_consumer.h"
54 #include "chrome/common/net/gaia/gaia_auth_fetcher.h"
53 #include "chrome/common/net/gaia/gaia_constants.h" 55 #include "chrome/common/net/gaia/gaia_constants.h"
54 #include "chrome/common/net/gaia/gaia_urls.h" 56 #include "chrome/common/net/gaia/gaia_urls.h"
55 #include "chrome/common/pref_names.h" 57 #include "chrome/common/pref_names.h"
56 #include "chrome/common/url_constants.h" 58 #include "chrome/common/url_constants.h"
57 #include "content/browser/browser_thread.h" 59 #include "content/browser/browser_thread.h"
58 #include "googleurl/src/gurl.h" 60 #include "googleurl/src/gurl.h"
59 #include "net/base/cookie_monster.h" 61 #include "net/base/cookie_monster.h"
60 #include "net/base/cookie_store.h" 62 #include "net/base/cookie_store.h"
61 #include "net/url_request/url_request_context.h" 63 #include "net/url_request/url_request_context.h"
62 #include "net/url_request/url_request_context_getter.h" 64 #include "net/url_request/url_request_context_getter.h"
(...skipping 30 matching lines...) Expand all
93 class StartSyncOnUIThreadTask : public Task { 95 class StartSyncOnUIThreadTask : public Task {
94 public: 96 public:
95 StartSyncOnUIThreadTask( 97 StartSyncOnUIThreadTask(
96 const GaiaAuthConsumer::ClientLoginResult& credentials) 98 const GaiaAuthConsumer::ClientLoginResult& credentials)
97 : credentials_(credentials) {} 99 : credentials_(credentials) {}
98 virtual ~StartSyncOnUIThreadTask() {} 100 virtual ~StartSyncOnUIThreadTask() {}
99 101
100 // Task override. 102 // Task override.
101 virtual void Run() { 103 virtual void Run() {
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
103 105 LoginUtils::Get()->FetchCookies(ProfileManager::GetDefaultProfile(),
106 credentials_);
104 LoginUtils::Get()->StartSync(ProfileManager::GetDefaultProfile(), 107 LoginUtils::Get()->StartSync(ProfileManager::GetDefaultProfile(),
105 credentials_); 108 credentials_);
106 } 109 }
107 110
108 private: 111 private:
109 Profile* user_profile_;
110 GaiaAuthConsumer::ClientLoginResult credentials_; 112 GaiaAuthConsumer::ClientLoginResult credentials_;
111 }; 113 };
112 114
113 // Transfers initial set of Profile cookies form the default profile. 115 // Transfers initial set of Profile cookies form the default profile.
114 class TransferDefaultCookiesOnIOThreadTask : public Task { 116 class TransferDefaultCookiesOnIOThreadTask : public Task {
115 public: 117 public:
116 TransferDefaultCookiesOnIOThreadTask( 118 TransferDefaultCookiesOnIOThreadTask(
117 net::URLRequestContextGetter* auth_context, Profile* new_profile, 119 net::URLRequestContextGetter* auth_context, Profile* new_profile,
118 net::URLRequestContextGetter* new_context) 120 net::URLRequestContextGetter* new_context)
119 : auth_context_(auth_context), 121 : auth_context_(auth_context),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 216
215 private: 217 private:
216 GaiaOAuthFetcher oauth_fetcher_; 218 GaiaOAuthFetcher oauth_fetcher_;
217 std::string oauth1_token_; 219 std::string oauth1_token_;
218 std::string oauth1_secret_; 220 std::string oauth1_secret_;
219 std::string username_; 221 std::string username_;
220 222
221 DISALLOW_COPY_AND_ASSIGN(OAuthLoginVerifier); 223 DISALLOW_COPY_AND_ASSIGN(OAuthLoginVerifier);
222 }; 224 };
223 225
226 // Verifies OAuth1 access token by performing OAuthLogin.
227 class UserSessionCookieFetcher : public GaiaAuthConsumer {
228 public:
229 explicit UserSessionCookieFetcher(Profile* user_profile)
230 : gaia_fetcher_(this,
231 std::string(GaiaConstants::kChromeOSSource),
232 user_profile->GetRequestContext()) {
233 }
234 virtual ~UserSessionCookieFetcher() {}
235
236 void Start(const GaiaAuthConsumer::ClientLoginResult& credentials) {
237 gaia_fetcher_.StartIssueAuthToken(credentials.sid, credentials.lsid,
238 GaiaConstants::kGaiaService);
239 }
240
241 // GaiaAuthConsumer overrides.
242 virtual void OnIssueAuthTokenSuccess(const std::string& service,
243 const std::string& auth_token) OVERRIDE {
244 gaia_fetcher_.StartMergeSession(auth_token);
245 }
246
247 virtual void OnIssueAuthTokenFailure(const std::string& service,
248 const GoogleServiceAuthError& error) OVERRIDE {
249 LOG(WARNING) << "Failed IssueAuthToken request,"
250 << " error.state=" << error.state();
251 HandlerGaiaAuthError(error);
252 delete this;
253 }
254
255 virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE {
256 VLOG(1) << "MergeSession successful.";
257 delete this;
258 }
259
260 virtual void OnMergeSessionFailure(
261 const GoogleServiceAuthError& error) OVERRIDE {
262 LOG(WARNING) << "Failed MergeSession request,"
263 << " error.state=" << error.state();
264 HandlerGaiaAuthError(error);
265 delete this;
266 }
267
268 private:
269 void HandlerGaiaAuthError(const GoogleServiceAuthError& error) {
270 // Mark this account's login state as offline if we encountered a network
271 // error. That will make us verify user OAuth token and try to fetch session
272 // cookies again once we detect that the machine comes online.
273 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED)
274 UserManager::Get()->set_offline_login(true);
275 }
276
277 GaiaAuthFetcher gaia_fetcher_;
278 DISALLOW_COPY_AND_ASSIGN(UserSessionCookieFetcher);
279 };
280
281
224 // Fetches an OAuth token and initializes user policy with it. 282 // Fetches an OAuth token and initializes user policy with it.
225 class PolicyOAuthFetcher : public GaiaOAuthConsumer { 283 class PolicyOAuthFetcher : public GaiaOAuthConsumer {
226 public: 284 public:
227 PolicyOAuthFetcher(Profile* profile, 285 PolicyOAuthFetcher(Profile* profile,
228 const std::string& oauth1_token, 286 const std::string& oauth1_token,
229 const std::string& oauth1_secret) 287 const std::string& oauth1_secret)
230 : oauth_fetcher_(this, 288 : oauth_fetcher_(this,
231 profile->GetRequestContext(), 289 profile->GetRequestContext(),
232 profile, 290 profile,
233 kServiceScopeChromeOSDeviceManagement), 291 kServiceScopeChromeOSDeviceManagement),
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 auth_profile->GetRequestContext(), 681 auth_profile->GetRequestContext(),
624 auth_profile, 682 auth_profile,
625 kServiceScopeChromeOS)); 683 kServiceScopeChromeOS));
626 // Let's first get the Oauth request token and OAuth1 token+secret. 684 // Let's first get the Oauth request token and OAuth1 token+secret.
627 // One we get that, we will kick off individial requests for OAuth2 tokens for 685 // One we get that, we will kick off individial requests for OAuth2 tokens for
628 // all our services. 686 // all our services.
629 oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); 687 oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN);
630 oauth_fetcher_->StartGetOAuthTokenRequest(); 688 oauth_fetcher_->StartGetOAuthTokenRequest();
631 } 689 }
632 690
633 void LoginUtilsImpl::FetchCookies( 691 void LoginUtilsImpl::FetchCookies(Profile* user_profile,
634 Profile* profile,
635 const GaiaAuthConsumer::ClientLoginResult& credentials) { 692 const GaiaAuthConsumer::ClientLoginResult& credentials) {
636 // Take the credentials passed in and try to exchange them for 693 if (!using_oauth_) {
637 // full-fledged Google authentication cookies. This is 694 // Take the credentials passed in and try to exchange them for
638 // best-effort; it's possible that we'll fail due to network 695 // full-fledged Google authentication cookies. This is
639 // troubles or some such. 696 // best-effort; it's possible that we'll fail due to network
640 // CookieFetcher will delete itself once done. 697 // troubles or some such.
641 CookieFetcher* cf = new CookieFetcher(profile); 698 // CookieFetcher will delete itself once done.
642 cf->AttemptFetch(credentials.data); 699 CookieFetcher* cf = new CookieFetcher(user_profile);
700 cf->AttemptFetch(credentials.data);
701 } else {
702 UserSessionCookieFetcher* cf =
703 new UserSessionCookieFetcher(user_profile);
704 cf->Start(credentials);
705 }
643 } 706 }
644 707
645 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { 708 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) {
646 std::string oauth1_token; 709 std::string oauth1_token;
647 std::string oauth1_secret; 710 std::string oauth1_secret;
648 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) 711 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret))
649 return; 712 return;
650 713
651 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), oauth1_token, 714 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), oauth1_token,
652 oauth1_secret); 715 oauth1_secret);
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 // Mark login host for deletion after browser starts. This 1135 // Mark login host for deletion after browser starts. This
1073 // guarantees that the message loop will be referenced by the 1136 // guarantees that the message loop will be referenced by the
1074 // browser before it is dereferenced by the login host. 1137 // browser before it is dereferenced by the login host.
1075 if (login_host) { 1138 if (login_host) {
1076 login_host->OnSessionStart(); 1139 login_host->OnSessionStart();
1077 login_host = NULL; 1140 login_host = NULL;
1078 } 1141 }
1079 } 1142 }
1080 1143
1081 } // namespace chromeos 1144 } // namespace chromeos
OLDNEW
« 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