OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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_; | 112 Profile* user_profile_; |
xiyuan
2011/09/12 22:21:05
nit: this seems no longer in use.
zel
2011/09/12 23:11:10
Done.
| |
110 GaiaAuthConsumer::ClientLoginResult credentials_; | 113 GaiaAuthConsumer::ClientLoginResult credentials_; |
111 }; | 114 }; |
112 | 115 |
113 // Transfers initial set of Profile cookies form the default profile. | 116 // Transfers initial set of Profile cookies form the default profile. |
114 class TransferDefaultCookiesOnIOThreadTask : public Task { | 117 class TransferDefaultCookiesOnIOThreadTask : public Task { |
115 public: | 118 public: |
116 TransferDefaultCookiesOnIOThreadTask( | 119 TransferDefaultCookiesOnIOThreadTask( |
117 net::URLRequestContextGetter* auth_context, Profile* new_profile, | 120 net::URLRequestContextGetter* auth_context, Profile* new_profile, |
118 net::URLRequestContextGetter* new_context) | 121 net::URLRequestContextGetter* new_context) |
119 : auth_context_(auth_context), | 122 : auth_context_(auth_context), |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 | 217 |
215 private: | 218 private: |
216 GaiaOAuthFetcher oauth_fetcher_; | 219 GaiaOAuthFetcher oauth_fetcher_; |
217 std::string oauth1_token_; | 220 std::string oauth1_token_; |
218 std::string oauth1_secret_; | 221 std::string oauth1_secret_; |
219 std::string username_; | 222 std::string username_; |
220 | 223 |
221 DISALLOW_COPY_AND_ASSIGN(OAuthLoginVerifier); | 224 DISALLOW_COPY_AND_ASSIGN(OAuthLoginVerifier); |
222 }; | 225 }; |
223 | 226 |
227 // Verifies OAuth1 access token by performing OAuthLogin. | |
228 class UserSessionCookieFetcher : public GaiaAuthConsumer { | |
229 public: | |
230 explicit UserSessionCookieFetcher(Profile* user_profile) | |
231 : user_profile_(user_profile), | |
232 gaia_fetcher_(this, | |
233 std::string(GaiaConstants::kChromeOSSource), | |
234 user_profile->GetRequestContext()) { | |
235 } | |
236 virtual ~UserSessionCookieFetcher() {} | |
237 | |
238 void Start(const GaiaAuthConsumer::ClientLoginResult& credentials) { | |
239 gaia_fetcher_.StartIssueAuthToken(credentials.sid, credentials.lsid, | |
240 GaiaConstants::kGaiaService); | |
241 } | |
242 | |
243 // GaiaAuthConsumer overrides. | |
244 virtual void OnIssueAuthTokenSuccess(const std::string& service, | |
245 const std::string& auth_token) OVERRIDE { | |
246 gaia_fetcher_.StartMergeSession(auth_token); | |
247 } | |
248 | |
249 virtual void OnIssueAuthTokenFailure(const std::string& service, | |
250 const GoogleServiceAuthError& error) OVERRIDE { | |
251 LOG(WARNING) << "Failed IssueAuthToken request," | |
252 << " error.state=" << error.state(); | |
253 HandlerGaiaAuthError(error); | |
254 delete this; | |
255 } | |
256 | |
257 virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE { | |
258 VLOG(1) << "MergeSession successful."; | |
259 delete this; | |
260 } | |
261 | |
262 virtual void OnMergeSessionFailure( | |
263 const GoogleServiceAuthError& error) OVERRIDE { | |
264 LOG(WARNING) << "Failed MergeSession request," | |
265 << " error.state=" << error.state(); | |
266 HandlerGaiaAuthError(error); | |
267 delete this; | |
268 } | |
269 | |
270 private: | |
271 void HandlerGaiaAuthError(const GoogleServiceAuthError& error) { | |
272 // Mark this account's login state as offline if we encountered a network | |
273 // error. That will make us verify user OAuth token and try to fetch session | |
274 // cookies again once we detect that the machine comes online. | |
275 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) | |
276 UserManager::Get()->set_offline_login(true); | |
277 } | |
278 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.
| |
279 GaiaAuthFetcher gaia_fetcher_; | |
280 | |
281 DISALLOW_COPY_AND_ASSIGN(UserSessionCookieFetcher); | |
282 }; | |
283 | |
284 | |
224 // Fetches an OAuth token and initializes user policy with it. | 285 // Fetches an OAuth token and initializes user policy with it. |
225 class PolicyOAuthFetcher : public GaiaOAuthConsumer { | 286 class PolicyOAuthFetcher : public GaiaOAuthConsumer { |
226 public: | 287 public: |
227 PolicyOAuthFetcher(Profile* profile, | 288 PolicyOAuthFetcher(Profile* profile, |
228 const std::string& oauth1_token, | 289 const std::string& oauth1_token, |
229 const std::string& oauth1_secret) | 290 const std::string& oauth1_secret) |
230 : oauth_fetcher_(this, | 291 : oauth_fetcher_(this, |
231 profile->GetRequestContext(), | 292 profile->GetRequestContext(), |
232 profile, | 293 profile, |
233 kServiceScopeChromeOSDeviceManagement), | 294 kServiceScopeChromeOSDeviceManagement), |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 auth_profile->GetRequestContext(), | 684 auth_profile->GetRequestContext(), |
624 auth_profile, | 685 auth_profile, |
625 kServiceScopeChromeOS)); | 686 kServiceScopeChromeOS)); |
626 // Let's first get the Oauth request token and OAuth1 token+secret. | 687 // 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 | 688 // One we get that, we will kick off individial requests for OAuth2 tokens for |
628 // all our services. | 689 // all our services. |
629 oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); | 690 oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); |
630 oauth_fetcher_->StartGetOAuthTokenRequest(); | 691 oauth_fetcher_->StartGetOAuthTokenRequest(); |
631 } | 692 } |
632 | 693 |
633 void LoginUtilsImpl::FetchCookies( | 694 void LoginUtilsImpl::FetchCookies(Profile* user_profile, |
634 Profile* profile, | |
635 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 695 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
636 // Take the credentials passed in and try to exchange them for | 696 if (!using_oauth_) { |
637 // full-fledged Google authentication cookies. This is | 697 // Take the credentials passed in and try to exchange them for |
638 // best-effort; it's possible that we'll fail due to network | 698 // full-fledged Google authentication cookies. This is |
639 // troubles or some such. | 699 // best-effort; it's possible that we'll fail due to network |
640 // CookieFetcher will delete itself once done. | 700 // troubles or some such. |
641 CookieFetcher* cf = new CookieFetcher(profile); | 701 // CookieFetcher will delete itself once done. |
642 cf->AttemptFetch(credentials.data); | 702 CookieFetcher* cf = new CookieFetcher(user_profile); |
703 cf->AttemptFetch(credentials.data); | |
704 } else { | |
705 UserSessionCookieFetcher* cf = | |
706 new UserSessionCookieFetcher(user_profile); | |
707 cf->Start(credentials); | |
708 } | |
643 } | 709 } |
644 | 710 |
645 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { | 711 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { |
646 std::string oauth1_token; | 712 std::string oauth1_token; |
647 std::string oauth1_secret; | 713 std::string oauth1_secret; |
648 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | 714 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
649 return; | 715 return; |
650 | 716 |
651 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), oauth1_token, | 717 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), oauth1_token, |
652 oauth1_secret); | 718 oauth1_secret); |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1072 // Mark login host for deletion after browser starts. This | 1138 // Mark login host for deletion after browser starts. This |
1073 // guarantees that the message loop will be referenced by the | 1139 // guarantees that the message loop will be referenced by the |
1074 // browser before it is dereferenced by the login host. | 1140 // browser before it is dereferenced by the login host. |
1075 if (login_host) { | 1141 if (login_host) { |
1076 login_host->OnSessionStart(); | 1142 login_host->OnSessionStart(); |
1077 login_host = NULL; | 1143 login_host = NULL; |
1078 } | 1144 } |
1079 } | 1145 } |
1080 | 1146 |
1081 } // namespace chromeos | 1147 } // namespace chromeos |
OLD | NEW |