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

Side by Side Diff: chrome/browser/chromeos/login/login_utils.cc

Issue 10446033: Retry fetching OAuth1 request token on failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: change log level for token fetch fail. Created 8 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 #include "ui/compositor/compositor_switches.h" 88 #include "ui/compositor/compositor_switches.h"
89 #include "ui/gl/gl_switches.h" 89 #include "ui/gl/gl_switches.h"
90 #include "webkit/plugins/plugin_switches.h" 90 #include "webkit/plugins/plugin_switches.h"
91 91
92 using content::BrowserThread; 92 using content::BrowserThread;
93 93
94 namespace chromeos { 94 namespace chromeos {
95 95
96 namespace { 96 namespace {
97 97
98 // OAuth token verification retry count. 98 // OAuth token verification max retry count.
99 const int kMaxOAuthTokenVerificationAttemptCount = 5; 99 const int kMaxOAuthTokenVerificationAttemptCount = 5;
100 // OAuth token verification retry delay. 100 // OAuth token verification retry delay in milliseconds.
101 const int kOAuthVerificationRestartDelay = 10000; // ms 101 const int kOAuthVerificationRestartDelay = 10000;
102
103 // OAuth token request max retry count.
104 const int kMaxOAuth1TokenRequestAttemptCount = 5;
105 // OAuth token request retry delay in milliseconds.
106 const int kOAuth1TokenRequestRestartDelay = 3000;
102 107
103 // Affixes for Auth token received from ClientLogin request. 108 // Affixes for Auth token received from ClientLogin request.
104 const char kAuthPrefix[] = "Auth="; 109 const char kAuthPrefix[] = "Auth=";
105 const char kAuthSuffix[] = "\n"; 110 const char kAuthSuffix[] = "\n";
106 111
107 // Increase logging level for Guest mode to avoid LOG(INFO) messages in logs. 112 // Increase logging level for Guest mode to avoid LOG(INFO) messages in logs.
108 const char kGuestModeLoggingLevel[] = "1"; 113 const char kGuestModeLoggingLevel[] = "1";
109 114
110 // Format of command line switch. 115 // Format of command line switch.
111 const char kSwitchFormatString[] = " --%s=\"%s\""; 116 const char kSwitchFormatString[] = " --%s=\"%s\"";
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 333
329 virtual void OnOAuthLoginFailure( 334 virtual void OnOAuthLoginFailure(
330 const GoogleServiceAuthError& error) OVERRIDE { 335 const GoogleServiceAuthError& error) OVERRIDE {
331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
332 LOG(WARNING) << "Failed to verify OAuth1 access tokens," 337 LOG(WARNING) << "Failed to verify OAuth1 access tokens,"
333 << " error.state=" << error.state(); 338 << " error.state=" << error.state();
334 if (!RetryOnError(error)) 339 if (!RetryOnError(error))
335 delegate_->OnOAuthVerificationFailed(username_); 340 delegate_->OnOAuthVerificationFailed(username_);
336 } 341 }
337 342
338 void OnCookueFetchFailed(const GoogleServiceAuthError& error) { 343 void OnCookieFetchFailed(const GoogleServiceAuthError& error) {
339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
340 if (!RetryOnError(error)) 345 if (!RetryOnError(error))
341 delegate_->OnUserCookiesFetchFailed(username_); 346 delegate_->OnUserCookiesFetchFailed(username_);
342 } 347 }
343 348
344 // GaiaAuthConsumer overrides. 349 // GaiaAuthConsumer overrides.
345 virtual void OnIssueAuthTokenSuccess(const std::string& service, 350 virtual void OnIssueAuthTokenSuccess(const std::string& service,
346 const std::string& auth_token) OVERRIDE { 351 const std::string& auth_token) OVERRIDE {
347 gaia_fetcher_.StartMergeSession(auth_token); 352 gaia_fetcher_.StartMergeSession(auth_token);
348 } 353 }
349 354
350 virtual void OnIssueAuthTokenFailure(const std::string& service, 355 virtual void OnIssueAuthTokenFailure(const std::string& service,
351 const GoogleServiceAuthError& error) OVERRIDE { 356 const GoogleServiceAuthError& error) OVERRIDE {
352 DVLOG(1) << "Failed IssueAuthToken request," 357 DVLOG(1) << "Failed IssueAuthToken request,"
353 << " error.state=" << error.state(); 358 << " error.state=" << error.state();
354 OnCookueFetchFailed(error); 359 OnCookieFetchFailed(error);
355 } 360 }
356 361
357 virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE { 362 virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE {
358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
359 DVLOG(1) << "MergeSession successful."; 364 DVLOG(1) << "MergeSession successful.";
360 step_ = VERIFICATION_STEP_COOKIES_FETCHED; 365 step_ = VERIFICATION_STEP_COOKIES_FETCHED;
361 delegate_->OnUserCookiesFetchSucceeded(username_); 366 delegate_->OnUserCookiesFetchSucceeded(username_);
362 } 367 }
363 368
364 virtual void OnMergeSessionFailure( 369 virtual void OnMergeSessionFailure(
365 const GoogleServiceAuthError& error) OVERRIDE { 370 const GoogleServiceAuthError& error) OVERRIDE {
366 DVLOG(1) << "Failed MergeSession request," 371 DVLOG(1) << "Failed MergeSession request,"
367 << " error.state=" << error.state(); 372 << " error.state=" << error.state();
368 OnCookueFetchFailed(error); 373 OnCookieFetchFailed(error);
369 } 374 }
370 375
371 OAuthLoginVerifier::Delegate* delegate_; 376 OAuthLoginVerifier::Delegate* delegate_;
372 GaiaOAuthFetcher oauth_fetcher_; 377 GaiaOAuthFetcher oauth_fetcher_;
373 GaiaAuthFetcher gaia_fetcher_; 378 GaiaAuthFetcher gaia_fetcher_;
374 std::string oauth1_token_; 379 std::string oauth1_token_;
375 std::string oauth1_secret_; 380 std::string oauth1_secret_;
376 std::string sid_; 381 std::string sid_;
377 std::string lsid_; 382 std::string lsid_;
378 std::string username_; 383 std::string username_;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 MessageLoop::current()->AssertIdle(); 534 MessageLoop::current()->AssertIdle();
530 } 535 }
531 } 536 }
532 537
533 int pid_; 538 int pid_;
534 std::string command_line_; 539 std::string command_line_;
535 PrefService* local_state_; 540 PrefService* local_state_;
536 base::OneShotTimer<JobRestartRequest> timer_; 541 base::OneShotTimer<JobRestartRequest> timer_;
537 }; 542 };
538 543
544 // Given the authenticated credentials from the cookie jar, try to exchange
545 // fetch OAuth1 token and secret. Automatically retries until max retry count is
546 // reached.
547 class OAuth1TokenFetcher
zel 2012/05/29 15:30:47 we should move all these OAuthSoemthing classes to
kochi 2012/05/29 16:48:43 Done for OAuthLoginVerifier, PolicyOAuthFetcher, O
548 : public GaiaOAuthConsumer,
549 public net::NetworkChangeNotifier::ConnectionTypeObserver {
550 public:
551 class Delegate {
552 public:
553 virtual ~Delegate() {}
554 virtual void OnOAuth1AccessTokenAvailable(const std::string& token,
555 const std::string& secret) = 0;
556 virtual void OnOAuth1AccessTokenFetchFailed() = 0;
557 };
558
559 OAuth1TokenFetcher(OAuth1TokenFetcher::Delegate* delegate,
560 Profile* auth_profile)
561 : delegate_(delegate),
562 auth_profile_(auth_profile),
563 oauth_fetcher_(this,
564 auth_profile_->GetRequestContext(),
565 auth_profile_,
566 kServiceScopeChromeOS),
567 retry_count_(0),
568 is_suspended_(false) {
569 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
zel 2012/05/29 15:30:47 DCHECK(delegate)
kochi 2012/05/29 16:48:43 Done.
570 }
571 virtual ~OAuth1TokenFetcher() {
572 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
573 }
574
575 void Start() {
576 if (net::NetworkChangeNotifier::IsOffline()) {
577 // If network is offline, defer the token fetching until online.
578 VLOG(1) << "Network is offline. Deferring OAuth1 token fetch.";
579 is_suspended_ = true;
580 return;
581 }
582 oauth_fetcher_.SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN);
583 oauth_fetcher_.StartGetOAuthTokenRequest();
584 }
585
586 private:
587 // Decides how to proceed on GAIA response and other errors. If the error
588 // looks temporary, retries token fetching until max retry count is reached.
589 // If retry count runs out, or error condition is unrecoverable, returns
590 // false.
591 bool RetryOnError(const GoogleServiceAuthError& error) {
592 if ((error.state() == GoogleServiceAuthError::CONNECTION_FAILED ||
zel 2012/05/29 15:30:47 if network is disconnected, it does not make sense
kochi 2012/05/29 16:48:43 Changed the logic. We check the GAIA server reach
593 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE ||
594 error.state() == GoogleServiceAuthError::REQUEST_CANCELED) &&
595 retry_count_++ < kMaxOAuth1TokenRequestAttemptCount) {
zel 2012/05/29 15:30:47 align
kochi 2012/05/29 16:48:43 Already aligned (see enclosing parentheses around
596 BrowserThread::PostDelayedTask(
597 BrowserThread::UI, FROM_HERE,
598 base::Bind(&OAuth1TokenFetcher::Start, base::Unretained(this)),
zel 2012/05/29 15:30:47 base::Unretained(this) could be a source of troubl
kochi 2012/05/29 16:48:43 Done.
599 base::TimeDelta::FromMilliseconds(kOAuth1TokenRequestRestartDelay));
600 return true;
601 }
602 LOG(WARNING) << "Unrecoverable error or retry count max reached.";
603 return false;
604 }
605
606 // GaiaOAuthConsumer implementation:
607 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE {
608 VLOG(1) << "Got OAuth request token!";
609 }
610
611 virtual void OnGetOAuthTokenFailure(
612 const GoogleServiceAuthError& error) OVERRIDE {
613 LOG(WARNING) << "Failed to get OAuth1 request token, error: "
614 << error.state();
615 if (!RetryOnError(error))
616 delegate_->OnOAuth1AccessTokenFetchFailed();
617 }
618
619 virtual void OnOAuthGetAccessTokenSuccess(
620 const std::string& token,
621 const std::string& secret) OVERRIDE {
622 VLOG(1) << "Got OAuth v1 token!";
623 retry_count_ = 0;
624 delegate_->OnOAuth1AccessTokenAvailable(token, secret);
625 }
626
627 virtual void OnOAuthGetAccessTokenFailure(
628 const GoogleServiceAuthError& error) OVERRIDE {
629 LOG(WARNING) << "Failed fetching OAuth1 access token, error: "
630 << error.state();
631 if (!RetryOnError(error))
632 delegate_->OnOAuth1AccessTokenFetchFailed();
633 }
634
635 // NetworkChangeNotifier::ConnectionTypeObserver implementation:
636 void OnConnectionTypeChanged(
637 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE {
638 if (type != net::NetworkChangeNotifier::CONNECTION_NONE &&
zel 2012/05/29 15:30:47 what about captive portal? do we check that case a
639 is_suspended_) {
640 // Restart the process when network gets reacheable.
641 VLOG(1) << "Network is reacheable now. Retrying OAuth1 token fetch.";
642 is_suspended_ = false;
643 Start();
644 }
645 }
646
647 OAuth1TokenFetcher::Delegate* delegate_;
648 Profile* auth_profile_;
649 GaiaOAuthFetcher oauth_fetcher_;
650
651 // The retry counter. Increment this only when failure happened.
652 int retry_count_;
653 // Is the process suspended for network unavailability?
654 bool is_suspended_;
655
656 DISALLOW_COPY_AND_ASSIGN(OAuth1TokenFetcher);
657 };
658
539 class LoginUtilsImpl 659 class LoginUtilsImpl
540 : public LoginUtils, 660 : public LoginUtils,
541 public GaiaOAuthConsumer, 661 public OAuth1TokenFetcher::Delegate,
542 public OAuthLoginVerifier::Delegate, 662 public OAuthLoginVerifier::Delegate,
543 public net::NetworkChangeNotifier::ConnectionTypeObserver, 663 public net::NetworkChangeNotifier::ConnectionTypeObserver,
544 public base::SupportsWeakPtr<LoginUtilsImpl> { 664 public base::SupportsWeakPtr<LoginUtilsImpl> {
545 public: 665 public:
546 LoginUtilsImpl() 666 LoginUtilsImpl()
547 : pending_requests_(false), 667 : pending_requests_(false),
548 using_oauth_(false), 668 using_oauth_(false),
549 has_cookies_(false), 669 has_cookies_(false),
550 delegate_(NULL), 670 delegate_(NULL),
551 job_restart_request_(NULL), 671 job_restart_request_(NULL),
(...skipping 26 matching lines...) Expand all
578 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; 698 virtual void StartTokenServices(Profile* user_profile) OVERRIDE;
579 virtual void StartSignedInServices( 699 virtual void StartSignedInServices(
580 Profile* profile, 700 Profile* profile,
581 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; 701 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE;
582 virtual void TransferDefaultCookies(Profile* default_profile, 702 virtual void TransferDefaultCookies(Profile* default_profile,
583 Profile* new_profile) OVERRIDE; 703 Profile* new_profile) OVERRIDE;
584 virtual void TransferDefaultAuthCache(Profile* default_profile, 704 virtual void TransferDefaultAuthCache(Profile* default_profile,
585 Profile* new_profile) OVERRIDE; 705 Profile* new_profile) OVERRIDE;
586 virtual void StopBackgroundFetchers() OVERRIDE; 706 virtual void StopBackgroundFetchers() OVERRIDE;
587 707
588 // GaiaOAuthConsumer overrides. 708 // OAuth1TokenFetcher::Delegate overrides.
589 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; 709 void OnOAuth1AccessTokenAvailable(const std::string& token,
590 virtual void OnGetOAuthTokenFailure( 710 const std::string& secret) OVERRIDE;
591 const GoogleServiceAuthError& error) OVERRIDE; 711 void OnOAuth1AccessTokenFetchFailed() OVERRIDE;
592 virtual void OnOAuthGetAccessTokenSuccess(const std::string& token,
593 const std::string& secret) OVERRIDE;
594 virtual void OnOAuthGetAccessTokenFailure(
595 const GoogleServiceAuthError& error) OVERRIDE;
596 712
597 // OAuthLoginVerifier::Delegate overrides. 713 // OAuthLoginVerifier::Delegate overrides.
598 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, 714 virtual void OnOAuthVerificationSucceeded(const std::string& user_name,
599 const std::string& sid, 715 const std::string& sid,
600 const std::string& lsid, 716 const std::string& lsid,
601 const std::string& auth) OVERRIDE; 717 const std::string& auth) OVERRIDE;
602 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE; 718 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE;
603 719
604 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. 720 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides.
605 virtual void OnConnectionTypeChanged( 721 virtual void OnConnectionTypeChanged(
606 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 722 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
607 723
608 // Given the authenticated credentials from the cookie jar, try to exchange
609 // fetch OAuth request, v1 and v2 tokens.
610 void FetchOAuth1AccessToken(Profile* auth_profile);
611
612 protected: 724 protected:
613 virtual std::string GetOffTheRecordCommandLine( 725 virtual std::string GetOffTheRecordCommandLine(
614 const GURL& start_url, 726 const GURL& start_url,
615 const CommandLine& base_command_line, 727 const CommandLine& base_command_line,
616 CommandLine *command_line); 728 CommandLine *command_line);
617 729
618 private: 730 private:
619 // Restarts OAuth session authentication check. 731 // Restarts OAuth session authentication check.
620 void KickStartAuthentication(Profile* profile); 732 void KickStartAuthentication(Profile* profile);
621 733
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 // Callback for asynchronous profile creation. 768 // Callback for asynchronous profile creation.
657 void OnProfileCreated(Profile* profile, 769 void OnProfileCreated(Profile* profile,
658 Profile::CreateStatus status); 770 Profile::CreateStatus status);
659 771
660 std::string password_; 772 std::string password_;
661 bool pending_requests_; 773 bool pending_requests_;
662 bool using_oauth_; 774 bool using_oauth_;
663 bool has_cookies_; 775 bool has_cookies_;
664 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). 776 // Has to be scoped_refptr, see comment for CreateAuthenticator(...).
665 scoped_refptr<Authenticator> authenticator_; 777 scoped_refptr<Authenticator> authenticator_;
666 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_;
667 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; 778 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_;
779 scoped_ptr<OAuth1TokenFetcher> oauth1_token_fetcher_;
668 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; 780 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_;
669 781
670 // Delegate to be fired when the profile will be prepared. 782 // Delegate to be fired when the profile will be prepared.
671 LoginUtils::Delegate* delegate_; 783 LoginUtils::Delegate* delegate_;
672 784
673 // Used to restart Chrome to switch to the guest mode. 785 // Used to restart Chrome to switch to the guest mode.
674 JobRestartRequest* job_restart_request_; 786 JobRestartRequest* job_restart_request_;
675 787
676 // True if should restore authentication session when notified about 788 // True if should restore authentication session when notified about
677 // online state change. 789 // online state change.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 std::string oauth1_secret; 991 std::string oauth1_secret;
880 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret) || 992 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret) ||
881 !has_cookies_) { 993 !has_cookies_) {
882 // Verify OAuth access token when we find it in the profile and always if 994 // Verify OAuth access token when we find it in the profile and always if
883 // if we don't have cookies. 995 // if we don't have cookies.
884 // TODO(xiyuan): Change back to use authenticator to verify token when 996 // TODO(xiyuan): Change back to use authenticator to verify token when
885 // we support Gaia in lock screen. 997 // we support Gaia in lock screen.
886 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); 998 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret);
887 } else { 999 } else {
888 // If we don't have it, fetch OAuth1 access token. 1000 // If we don't have it, fetch OAuth1 access token.
1001 // Once we get that, we will kick off individual requests for OAuth2
1002 // tokens for all our services.
889 // Use off-the-record profile that was used for this step. It should 1003 // Use off-the-record profile that was used for this step. It should
890 // already contain all needed cookies that will let us skip GAIA's user 1004 // already contain all needed cookies that will let us skip GAIA's user
891 // authentication UI. 1005 // authentication UI.
892 // 1006 //
893 // TODO(rickcam) We should use an isolated App here. 1007 // TODO(rickcam) We should use an isolated App here.
894 FetchOAuth1AccessToken(authenticator_->authentication_profile()); 1008 oauth1_token_fetcher_.reset(
1009 new OAuth1TokenFetcher(this,
1010 authenticator_->authentication_profile()));
1011 oauth1_token_fetcher_->Start();
895 } 1012 }
896 } 1013 }
897 1014
898 // Own TPM device if, for any reason, it has not been done in EULA 1015 // Own TPM device if, for any reason, it has not been done in EULA
899 // wizard screen. 1016 // wizard screen.
900 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); 1017 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary();
901 btl->AddLoginTimeMarker("TPMOwn-Start", false); 1018 btl->AddLoginTimeMarker("TPMOwn-Start", false);
902 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { 1019 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) {
903 if (cryptohome->TpmIsOwned()) { 1020 if (cryptohome->TpmIsOwned()) {
904 cryptohome->TpmClearStoredPassword(); 1021 cryptohome->TpmClearStoredPassword();
(...skipping 15 matching lines...) Expand all
920 // TODO(altimofeev): This pointer should probably never be NULL, but it looks 1037 // TODO(altimofeev): This pointer should probably never be NULL, but it looks
921 // like LoginUtilsImpl::OnProfileCreated() may be getting called before 1038 // like LoginUtilsImpl::OnProfileCreated() may be getting called before
922 // LoginUtilsImpl::PrepareProfile() has set |delegate_| when Chrome is killed 1039 // LoginUtilsImpl::PrepareProfile() has set |delegate_| when Chrome is killed
923 // during shutdown in tests -- see http://crosbug.com/18269. Replace this 1040 // during shutdown in tests -- see http://crosbug.com/18269. Replace this
924 // 'if' statement with a CHECK(delegate_) once the underlying issue is 1041 // 'if' statement with a CHECK(delegate_) once the underlying issue is
925 // resolved. 1042 // resolved.
926 if (delegate_) 1043 if (delegate_)
927 delegate_->OnProfilePrepared(user_profile); 1044 delegate_->OnProfilePrepared(user_profile);
928 } 1045 }
929 1046
930 void LoginUtilsImpl::FetchOAuth1AccessToken(Profile* auth_profile) {
931 oauth_fetcher_.reset(new GaiaOAuthFetcher(this,
932 auth_profile->GetRequestContext(),
933 auth_profile,
934 kServiceScopeChromeOS));
935 // Let's first get the Oauth request token and OAuth1 token+secret.
936 // Once we get that, we will kick off individual requests for OAuth2 tokens
937 // for all our services.
938 oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN);
939 oauth_fetcher_->StartGetOAuthTokenRequest();
940 }
941
942 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { 1047 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) {
943 std::string oauth1_token; 1048 std::string oauth1_token;
944 std::string oauth1_secret; 1049 std::string oauth1_secret;
945 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) 1050 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret))
946 return; 1051 return;
947 1052
948 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), 1053 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(),
949 oauth1_token, oauth1_secret); 1054 oauth1_token, oauth1_secret);
950 } 1055 }
951 1056
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 void LoginUtilsImpl::TransferDefaultAuthCache(Profile* default_profile, 1368 void LoginUtilsImpl::TransferDefaultAuthCache(Profile* default_profile,
1264 Profile* profile) { 1369 Profile* profile) {
1265 BrowserThread::PostTask( 1370 BrowserThread::PostTask(
1266 BrowserThread::IO, FROM_HERE, 1371 BrowserThread::IO, FROM_HERE,
1267 base::Bind(&TransferDefaultAuthCacheOnIOThread, 1372 base::Bind(&TransferDefaultAuthCacheOnIOThread,
1268 make_scoped_refptr(default_profile->GetRequestContext()), 1373 make_scoped_refptr(default_profile->GetRequestContext()),
1269 make_scoped_refptr(profile->GetRequestContext()))); 1374 make_scoped_refptr(profile->GetRequestContext())));
1270 } 1375 }
1271 1376
1272 void LoginUtilsImpl::StopBackgroundFetchers() { 1377 void LoginUtilsImpl::StopBackgroundFetchers() {
1273 oauth_fetcher_.reset();
1274 policy_oauth_fetcher_.reset(); 1378 policy_oauth_fetcher_.reset();
1379 oauth1_token_fetcher_.reset();
1275 oauth_login_verifier_.reset(); 1380 oauth_login_verifier_.reset();
1276 } 1381 }
1277 1382
1278 void LoginUtilsImpl::OnGetOAuthTokenSuccess(const std::string& oauth_token) {
1279 VLOG(1) << "Got OAuth request token!";
1280 }
1281
1282 void LoginUtilsImpl::OnGetOAuthTokenFailure(
1283 const GoogleServiceAuthError& error) {
1284 // TODO(zelidrag): Pop up sync setup UI here?
1285 LOG(WARNING) << "Failed fetching OAuth request token, error: "
1286 << error.state();
1287 }
1288
1289 void LoginUtilsImpl::OnOAuthGetAccessTokenSuccess(const std::string& token,
1290 const std::string& secret) {
1291 VLOG(1) << "Got OAuth v1 token!";
1292 Profile* user_profile = ProfileManager::GetDefaultProfile();
1293 StoreOAuth1AccessToken(user_profile, token, secret);
1294
1295 // Verify OAuth1 token by doing OAuthLogin and fetching credentials.
1296 VerifyOAuth1AccessToken(user_profile, token, secret);
1297 }
1298
1299 void LoginUtilsImpl::OnOAuthGetAccessTokenFailure(
1300 const GoogleServiceAuthError& error) {
1301 // TODO(zelidrag): Pop up sync setup UI here?
1302 LOG(WARNING) << "Failed fetching OAuth request token, error: "
1303 << error.state();
1304 }
1305
1306 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile, 1383 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile,
1307 const std::string& token, 1384 const std::string& token,
1308 const std::string& secret) { 1385 const std::string& secret) {
1309 FetchPolicyToken(offrecord_profile, token, secret); 1386 FetchPolicyToken(offrecord_profile, token, secret);
1310 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes 1387 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes
1311 // capable of handling OAuth1 tokens directly. 1388 // capable of handling OAuth1 tokens directly.
1312 } 1389 }
1313 1390
1314 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, 1391 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile,
1315 std::string* token, 1392 std::string* token,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 // TODO(nkostylev): There's a potential race if SL would be created before 1487 // TODO(nkostylev): There's a potential race if SL would be created before
1411 // OAuth tokens are fetched. It would use incorrect Authenticator instance. 1488 // OAuth tokens are fetched. It would use incorrect Authenticator instance.
1412 authenticator_ = NULL; 1489 authenticator_ = NULL;
1413 } 1490 }
1414 1491
1415 void LoginUtilsImpl::OnOAuthVerificationFailed(const std::string& user_name) { 1492 void LoginUtilsImpl::OnOAuthVerificationFailed(const std::string& user_name) {
1416 UserManager::Get()->SaveUserOAuthStatus(user_name, 1493 UserManager::Get()->SaveUserOAuthStatus(user_name,
1417 User::OAUTH_TOKEN_STATUS_INVALID); 1494 User::OAUTH_TOKEN_STATUS_INVALID);
1418 } 1495 }
1419 1496
1497 void LoginUtilsImpl::OnOAuth1AccessTokenAvailable(const std::string& token,
1498 const std::string& secret) {
1499 Profile* user_profile = ProfileManager::GetDefaultProfile();
1500 StoreOAuth1AccessToken(user_profile, token, secret);
1501
1502 // Verify OAuth1 token by doing OAuthLogin and fetching credentials.
1503 VerifyOAuth1AccessToken(user_profile, token, secret);
1504 }
1505
1506 void LoginUtilsImpl::OnOAuth1AccessTokenFetchFailed() {
1507 // TODO(kochi): Show failure notification UI here?
1508 LOG(ERROR) << "Failed to fetch OAuth1 access token.";
1509 }
1510
1420 void LoginUtilsImpl::OnOAuthVerificationSucceeded( 1511 void LoginUtilsImpl::OnOAuthVerificationSucceeded(
1421 const std::string& user_name, const std::string& sid, 1512 const std::string& user_name, const std::string& sid,
1422 const std::string& lsid, const std::string& auth) { 1513 const std::string& lsid, const std::string& auth) {
1423 // Kick off sync engine. 1514 // Kick off sync engine.
1424 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, 1515 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth,
1425 std::string()); 1516 std::string());
1426 StartSignedInServices(ProfileManager::GetDefaultProfile(), credentials); 1517 StartSignedInServices(ProfileManager::GetDefaultProfile(), credentials);
1427 } 1518 }
1428 1519
1429 1520
1430 void LoginUtilsImpl::OnConnectionTypeChanged( 1521 void LoginUtilsImpl::OnConnectionTypeChanged(
1431 net::NetworkChangeNotifier::ConnectionType type) { 1522 net::NetworkChangeNotifier::ConnectionType type) {
1432 if (type != net::NetworkChangeNotifier::CONNECTION_NONE && 1523 if (type != net::NetworkChangeNotifier::CONNECTION_NONE &&
1433 UserManager::Get()->IsUserLoggedIn()) { 1524 UserManager::Get()->IsUserLoggedIn()) {
1434 if (oauth_login_verifier_.get() && 1525 if (oauth_login_verifier_.get() &&
1435 !oauth_login_verifier_->is_done()) { 1526 !oauth_login_verifier_->is_done()) {
1436 // If we come online for the first time after successful offline login, 1527 // If we come online for the first time after successful offline login,
1437 // we need to kick of OAuth token verification process again. 1528 // we need to kick off OAuth token verification process again.
1438 oauth_login_verifier_->ContinueVerification(); 1529 oauth_login_verifier_->ContinueVerification();
1439 } else if (should_restore_auth_session_) { 1530 } else if (should_restore_auth_session_) {
1440 should_restore_auth_session_ = false; 1531 should_restore_auth_session_ = false;
1441 Profile* user_profile = ProfileManager::GetDefaultProfile(); 1532 Profile* user_profile = ProfileManager::GetDefaultProfile();
1442 KickStartAuthentication(user_profile); 1533 KickStartAuthentication(user_profile);
1443 } 1534 }
1444 } 1535 }
1445 } 1536 }
1446 1537
1447 // static 1538 // static
(...skipping 10 matching lines...) Expand all
1458 bool LoginUtils::IsWhitelisted(const std::string& username) { 1549 bool LoginUtils::IsWhitelisted(const std::string& username) {
1459 CrosSettings* cros_settings = CrosSettings::Get(); 1550 CrosSettings* cros_settings = CrosSettings::Get();
1460 bool allow_new_user = false; 1551 bool allow_new_user = false;
1461 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); 1552 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
1462 if (allow_new_user) 1553 if (allow_new_user)
1463 return true; 1554 return true;
1464 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); 1555 return cros_settings->FindEmailInList(kAccountsPrefUsers, username);
1465 } 1556 }
1466 1557
1467 } // namespace chromeos 1558 } // 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