OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 | |
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); | |
570 } | |
571 virtual ~OAuth1TokenFetcher() {} | |
572 | |
573 void Start() { | |
574 if (net::NetworkChangeNotifier::IsOffline()) { | |
575 // If network is offline, defer the token fetching until online. | |
576 VLOG(1) << "Network is offline. Deferring OAuth1 token fetch."; | |
577 is_suspended_ = true; | |
578 return; | |
579 } | |
580 oauth_fetcher_.SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); | |
581 oauth_fetcher_.StartGetOAuthTokenRequest(); | |
582 } | |
583 | |
584 private: | |
585 // Decides how to proceed on GAIA response and other errors. If the error | |
586 // looks temporary, retries token fetching until max retry count is reached. | |
587 // If retry count runs out, or error condition is unrecoverable, returns | |
588 // false. | |
589 bool RetryOnError(const GoogleServiceAuthError& error) { | |
590 if ((error.state() == GoogleServiceAuthError::CONNECTION_FAILED || | |
591 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE || | |
592 error.state() == GoogleServiceAuthError::REQUEST_CANCELED) && | |
593 retry_count_++ < kMaxOAuth1TokenRequestAttemptCount) { | |
594 BrowserThread::PostDelayedTask( | |
595 BrowserThread::UI, FROM_HERE, | |
596 base::Bind(&OAuth1TokenFetcher::Start, base::Unretained(this)), | |
597 base::TimeDelta::FromMilliseconds(kOAuth1TokenRequestRestartDelay)); | |
598 return true; | |
599 } | |
600 LOG(WARNING) << "Unrecoverable error or retry count max reached."; | |
601 return false; | |
602 } | |
603 | |
604 // GaiaOAuthConsumer implementation: | |
605 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE { | |
606 VLOG(1) << "Got OAuth request token!"; | |
607 } | |
608 | |
609 virtual void OnGetOAuthTokenFailure( | |
610 const GoogleServiceAuthError& error) OVERRIDE { | |
611 LOG(WARNING) << "Failed to get OAuth1 request token, error: " | |
612 << error.state(); | |
613 if (!RetryOnError(error)) | |
614 delegate_->OnOAuth1AccessTokenFetchFailed(); | |
615 } | |
616 | |
617 virtual void OnOAuthGetAccessTokenSuccess( | |
618 const std::string& token, | |
619 const std::string& secret) OVERRIDE { | |
620 VLOG(1) << "Got OAuth v1 token!"; | |
621 retry_count_ = 0; | |
622 delegate_->OnOAuth1AccessTokenAvailable(token, secret); | |
623 } | |
624 | |
625 virtual void OnOAuthGetAccessTokenFailure( | |
626 const GoogleServiceAuthError& error) OVERRIDE { | |
627 LOG(WARNING) << "Failed fetching OAuth1 access token, error: " | |
628 << error.state(); | |
629 if (!RetryOnError(error)) | |
630 delegate_->OnOAuth1AccessTokenFetchFailed(); | |
631 } | |
632 | |
633 // NetworkChangeNotifier::ConnectionTypeObserver implementation: | |
634 void OnConnectionTypeChanged( | |
635 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { | |
636 if (type != net::NetworkChangeNotifier::CONNECTION_NONE && | |
637 is_suspended_) { | |
638 // Restart the process when network gets reacheable. | |
639 VLOG(1) << "Network is reacheable now. Retrying OAuth1 token fetch."; | |
640 is_suspended_ = false; | |
641 Start(); | |
642 } | |
643 } | |
644 | |
645 OAuth1TokenFetcher::Delegate* delegate_; | |
646 Profile* auth_profile_; | |
647 GaiaOAuthFetcher oauth_fetcher_; | |
648 | |
649 // The retry counter. Increment this only when failure happened. | |
650 int retry_count_; | |
651 // Is the process suspended for network unavailability? | |
652 bool is_suspended_; | |
653 | |
654 DISALLOW_COPY_AND_ASSIGN(OAuth1TokenFetcher); | |
655 }; | |
656 | |
539 class LoginUtilsImpl | 657 class LoginUtilsImpl |
540 : public LoginUtils, | 658 : public LoginUtils, |
541 public GaiaOAuthConsumer, | 659 public OAuth1TokenFetcher::Delegate, |
542 public OAuthLoginVerifier::Delegate, | 660 public OAuthLoginVerifier::Delegate, |
543 public net::NetworkChangeNotifier::ConnectionTypeObserver, | 661 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
544 public base::SupportsWeakPtr<LoginUtilsImpl> { | 662 public base::SupportsWeakPtr<LoginUtilsImpl> { |
545 public: | 663 public: |
546 LoginUtilsImpl() | 664 LoginUtilsImpl() |
547 : pending_requests_(false), | 665 : pending_requests_(false), |
548 using_oauth_(false), | 666 using_oauth_(false), |
549 has_cookies_(false), | 667 has_cookies_(false), |
550 delegate_(NULL), | 668 delegate_(NULL), |
551 job_restart_request_(NULL), | 669 job_restart_request_(NULL), |
(...skipping 26 matching lines...) Expand all Loading... | |
578 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; | 696 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; |
579 virtual void StartSignedInServices( | 697 virtual void StartSignedInServices( |
580 Profile* profile, | 698 Profile* profile, |
581 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | 699 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; |
582 virtual void TransferDefaultCookies(Profile* default_profile, | 700 virtual void TransferDefaultCookies(Profile* default_profile, |
583 Profile* new_profile) OVERRIDE; | 701 Profile* new_profile) OVERRIDE; |
584 virtual void TransferDefaultAuthCache(Profile* default_profile, | 702 virtual void TransferDefaultAuthCache(Profile* default_profile, |
585 Profile* new_profile) OVERRIDE; | 703 Profile* new_profile) OVERRIDE; |
586 virtual void StopBackgroundFetchers() OVERRIDE; | 704 virtual void StopBackgroundFetchers() OVERRIDE; |
587 | 705 |
588 // GaiaOAuthConsumer overrides. | 706 // OAuth1TokenFetcher::Delegate overrides. |
589 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; | 707 void OnOAuth1AccessTokenAvailable(const std::string& token, |
590 virtual void OnGetOAuthTokenFailure( | 708 const std::string& secret) OVERRIDE; |
591 const GoogleServiceAuthError& error) OVERRIDE; | 709 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 | 710 |
597 // OAuthLoginVerifier::Delegate overrides. | 711 // OAuthLoginVerifier::Delegate overrides. |
598 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, | 712 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, |
599 const std::string& sid, | 713 const std::string& sid, |
600 const std::string& lsid, | 714 const std::string& lsid, |
601 const std::string& auth) OVERRIDE; | 715 const std::string& auth) OVERRIDE; |
602 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE; | 716 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE; |
603 | 717 |
604 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. | 718 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
605 virtual void OnConnectionTypeChanged( | 719 virtual void OnConnectionTypeChanged( |
606 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 720 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
607 | 721 |
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: | 722 protected: |
613 virtual std::string GetOffTheRecordCommandLine( | 723 virtual std::string GetOffTheRecordCommandLine( |
614 const GURL& start_url, | 724 const GURL& start_url, |
615 const CommandLine& base_command_line, | 725 const CommandLine& base_command_line, |
616 CommandLine *command_line); | 726 CommandLine *command_line); |
617 | 727 |
618 private: | 728 private: |
619 // Restarts OAuth session authentication check. | 729 // Restarts OAuth session authentication check. |
620 void KickStartAuthentication(Profile* profile); | 730 void KickStartAuthentication(Profile* profile); |
621 | 731 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 // Callback for asynchronous profile creation. | 766 // Callback for asynchronous profile creation. |
657 void OnProfileCreated(Profile* profile, | 767 void OnProfileCreated(Profile* profile, |
658 Profile::CreateStatus status); | 768 Profile::CreateStatus status); |
659 | 769 |
660 std::string password_; | 770 std::string password_; |
661 bool pending_requests_; | 771 bool pending_requests_; |
662 bool using_oauth_; | 772 bool using_oauth_; |
663 bool has_cookies_; | 773 bool has_cookies_; |
664 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). | 774 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). |
665 scoped_refptr<Authenticator> authenticator_; | 775 scoped_refptr<Authenticator> authenticator_; |
666 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_; | |
667 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; | 776 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; |
777 scoped_ptr<OAuth1TokenFetcher> oauth1_token_fetcher_; | |
668 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; | 778 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; |
669 | 779 |
670 // Delegate to be fired when the profile will be prepared. | 780 // Delegate to be fired when the profile will be prepared. |
671 LoginUtils::Delegate* delegate_; | 781 LoginUtils::Delegate* delegate_; |
672 | 782 |
673 // Used to restart Chrome to switch to the guest mode. | 783 // Used to restart Chrome to switch to the guest mode. |
674 JobRestartRequest* job_restart_request_; | 784 JobRestartRequest* job_restart_request_; |
675 | 785 |
676 // True if should restore authentication session when notified about | 786 // True if should restore authentication session when notified about |
677 // online state change. | 787 // online state change. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 std::string oauth1_secret; | 989 std::string oauth1_secret; |
880 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret) || | 990 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret) || |
881 !has_cookies_) { | 991 !has_cookies_) { |
882 // Verify OAuth access token when we find it in the profile and always if | 992 // Verify OAuth access token when we find it in the profile and always if |
883 // if we don't have cookies. | 993 // if we don't have cookies. |
884 // TODO(xiyuan): Change back to use authenticator to verify token when | 994 // TODO(xiyuan): Change back to use authenticator to verify token when |
885 // we support Gaia in lock screen. | 995 // we support Gaia in lock screen. |
886 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); | 996 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); |
887 } else { | 997 } else { |
888 // If we don't have it, fetch OAuth1 access token. | 998 // If we don't have it, fetch OAuth1 access token. |
999 // Once we get that, we will kick off individual requests for OAuth2 | |
1000 // tokens for all our services. | |
889 // Use off-the-record profile that was used for this step. It should | 1001 // 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 | 1002 // already contain all needed cookies that will let us skip GAIA's user |
891 // authentication UI. | 1003 // authentication UI. |
892 // | 1004 // |
893 // TODO(rickcam) We should use an isolated App here. | 1005 // TODO(rickcam) We should use an isolated App here. |
894 FetchOAuth1AccessToken(authenticator_->authentication_profile()); | 1006 oauth1_token_fetcher_.reset( |
1007 new OAuth1TokenFetcher(this, | |
1008 authenticator_->authentication_profile())); | |
1009 oauth1_token_fetcher_->Start(); | |
895 } | 1010 } |
896 } | 1011 } |
897 | 1012 |
898 // Own TPM device if, for any reason, it has not been done in EULA | 1013 // Own TPM device if, for any reason, it has not been done in EULA |
899 // wizard screen. | 1014 // wizard screen. |
900 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); | 1015 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); |
901 btl->AddLoginTimeMarker("TPMOwn-Start", false); | 1016 btl->AddLoginTimeMarker("TPMOwn-Start", false); |
902 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { | 1017 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { |
903 if (cryptohome->TpmIsOwned()) { | 1018 if (cryptohome->TpmIsOwned()) { |
904 cryptohome->TpmClearStoredPassword(); | 1019 cryptohome->TpmClearStoredPassword(); |
(...skipping 15 matching lines...) Expand all Loading... | |
920 // TODO(altimofeev): This pointer should probably never be NULL, but it looks | 1035 // TODO(altimofeev): This pointer should probably never be NULL, but it looks |
921 // like LoginUtilsImpl::OnProfileCreated() may be getting called before | 1036 // like LoginUtilsImpl::OnProfileCreated() may be getting called before |
922 // LoginUtilsImpl::PrepareProfile() has set |delegate_| when Chrome is killed | 1037 // LoginUtilsImpl::PrepareProfile() has set |delegate_| when Chrome is killed |
923 // during shutdown in tests -- see http://crosbug.com/18269. Replace this | 1038 // during shutdown in tests -- see http://crosbug.com/18269. Replace this |
924 // 'if' statement with a CHECK(delegate_) once the underlying issue is | 1039 // 'if' statement with a CHECK(delegate_) once the underlying issue is |
925 // resolved. | 1040 // resolved. |
926 if (delegate_) | 1041 if (delegate_) |
927 delegate_->OnProfilePrepared(user_profile); | 1042 delegate_->OnProfilePrepared(user_profile); |
928 } | 1043 } |
929 | 1044 |
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) { | 1045 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { |
943 std::string oauth1_token; | 1046 std::string oauth1_token; |
944 std::string oauth1_secret; | 1047 std::string oauth1_secret; |
945 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | 1048 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
946 return; | 1049 return; |
947 | 1050 |
948 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), | 1051 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), |
949 oauth1_token, oauth1_secret); | 1052 oauth1_token, oauth1_secret); |
950 } | 1053 } |
951 | 1054 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1263 void LoginUtilsImpl::TransferDefaultAuthCache(Profile* default_profile, | 1366 void LoginUtilsImpl::TransferDefaultAuthCache(Profile* default_profile, |
1264 Profile* profile) { | 1367 Profile* profile) { |
1265 BrowserThread::PostTask( | 1368 BrowserThread::PostTask( |
1266 BrowserThread::IO, FROM_HERE, | 1369 BrowserThread::IO, FROM_HERE, |
1267 base::Bind(&TransferDefaultAuthCacheOnIOThread, | 1370 base::Bind(&TransferDefaultAuthCacheOnIOThread, |
1268 make_scoped_refptr(default_profile->GetRequestContext()), | 1371 make_scoped_refptr(default_profile->GetRequestContext()), |
1269 make_scoped_refptr(profile->GetRequestContext()))); | 1372 make_scoped_refptr(profile->GetRequestContext()))); |
1270 } | 1373 } |
1271 | 1374 |
1272 void LoginUtilsImpl::StopBackgroundFetchers() { | 1375 void LoginUtilsImpl::StopBackgroundFetchers() { |
1273 oauth_fetcher_.reset(); | |
1274 policy_oauth_fetcher_.reset(); | 1376 policy_oauth_fetcher_.reset(); |
1377 oauth1_token_fetcher_.reset(); | |
1275 oauth_login_verifier_.reset(); | 1378 oauth_login_verifier_.reset(); |
1276 } | 1379 } |
1277 | 1380 |
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, | 1381 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile, |
1307 const std::string& token, | 1382 const std::string& token, |
1308 const std::string& secret) { | 1383 const std::string& secret) { |
1309 FetchPolicyToken(offrecord_profile, token, secret); | 1384 FetchPolicyToken(offrecord_profile, token, secret); |
1310 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes | 1385 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes |
1311 // capable of handling OAuth1 tokens directly. | 1386 // capable of handling OAuth1 tokens directly. |
1312 } | 1387 } |
1313 | 1388 |
1314 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, | 1389 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, |
1315 std::string* token, | 1390 std::string* token, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1410 // TODO(nkostylev): There's a potential race if SL would be created before | 1485 // TODO(nkostylev): There's a potential race if SL would be created before |
1411 // OAuth tokens are fetched. It would use incorrect Authenticator instance. | 1486 // OAuth tokens are fetched. It would use incorrect Authenticator instance. |
1412 authenticator_ = NULL; | 1487 authenticator_ = NULL; |
1413 } | 1488 } |
1414 | 1489 |
1415 void LoginUtilsImpl::OnOAuthVerificationFailed(const std::string& user_name) { | 1490 void LoginUtilsImpl::OnOAuthVerificationFailed(const std::string& user_name) { |
1416 UserManager::Get()->SaveUserOAuthStatus(user_name, | 1491 UserManager::Get()->SaveUserOAuthStatus(user_name, |
1417 User::OAUTH_TOKEN_STATUS_INVALID); | 1492 User::OAUTH_TOKEN_STATUS_INVALID); |
1418 } | 1493 } |
1419 | 1494 |
1495 void LoginUtilsImpl::OnOAuth1AccessTokenAvailable(const std::string& token, | |
1496 const std::string& secret) { | |
1497 Profile* user_profile = ProfileManager::GetDefaultProfile(); | |
1498 StoreOAuth1AccessToken(user_profile, token, secret); | |
1499 | |
1500 // Verify OAuth1 token by doing OAuthLogin and fetching credentials. | |
1501 VerifyOAuth1AccessToken(user_profile, token, secret); | |
1502 } | |
1503 | |
1504 void LoginUtilsImpl::OnOAuth1AccessTokenFetchFailed() { | |
1505 // TODO(kochi): Show failure notification UI here? | |
1506 LOG(WARNING) << "Failed to fetch OAuth1 access token."; | |
Nikita (slow)
2012/05/28 10:41:48
LOG(ERROR)?
kochi
2012/05/28 10:57:07
Done.
| |
1507 } | |
1508 | |
1420 void LoginUtilsImpl::OnOAuthVerificationSucceeded( | 1509 void LoginUtilsImpl::OnOAuthVerificationSucceeded( |
1421 const std::string& user_name, const std::string& sid, | 1510 const std::string& user_name, const std::string& sid, |
1422 const std::string& lsid, const std::string& auth) { | 1511 const std::string& lsid, const std::string& auth) { |
1423 // Kick off sync engine. | 1512 // Kick off sync engine. |
1424 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, | 1513 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, |
1425 std::string()); | 1514 std::string()); |
1426 StartSignedInServices(ProfileManager::GetDefaultProfile(), credentials); | 1515 StartSignedInServices(ProfileManager::GetDefaultProfile(), credentials); |
1427 } | 1516 } |
1428 | 1517 |
1429 | 1518 |
1430 void LoginUtilsImpl::OnConnectionTypeChanged( | 1519 void LoginUtilsImpl::OnConnectionTypeChanged( |
1431 net::NetworkChangeNotifier::ConnectionType type) { | 1520 net::NetworkChangeNotifier::ConnectionType type) { |
1432 if (type != net::NetworkChangeNotifier::CONNECTION_NONE && | 1521 if (type != net::NetworkChangeNotifier::CONNECTION_NONE && |
1433 UserManager::Get()->IsUserLoggedIn()) { | 1522 UserManager::Get()->IsUserLoggedIn()) { |
1434 if (oauth_login_verifier_.get() && | 1523 if (oauth_login_verifier_.get() && |
1435 !oauth_login_verifier_->is_done()) { | 1524 !oauth_login_verifier_->is_done()) { |
1436 // If we come online for the first time after successful offline login, | 1525 // If we come online for the first time after successful offline login, |
1437 // we need to kick of OAuth token verification process again. | 1526 // we need to kick off OAuth token verification process again. |
1438 oauth_login_verifier_->ContinueVerification(); | 1527 oauth_login_verifier_->ContinueVerification(); |
1439 } else if (should_restore_auth_session_) { | 1528 } else if (should_restore_auth_session_) { |
1440 should_restore_auth_session_ = false; | 1529 should_restore_auth_session_ = false; |
1441 Profile* user_profile = ProfileManager::GetDefaultProfile(); | 1530 Profile* user_profile = ProfileManager::GetDefaultProfile(); |
1442 KickStartAuthentication(user_profile); | 1531 KickStartAuthentication(user_profile); |
1443 } | 1532 } |
1444 } | 1533 } |
1445 } | 1534 } |
1446 | 1535 |
1447 // static | 1536 // static |
(...skipping 10 matching lines...) Expand all Loading... | |
1458 bool LoginUtils::IsWhitelisted(const std::string& username) { | 1547 bool LoginUtils::IsWhitelisted(const std::string& username) { |
1459 CrosSettings* cros_settings = CrosSettings::Get(); | 1548 CrosSettings* cros_settings = CrosSettings::Get(); |
1460 bool allow_new_user = false; | 1549 bool allow_new_user = false; |
1461 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 1550 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
1462 if (allow_new_user) | 1551 if (allow_new_user) |
1463 return true; | 1552 return true; |
1464 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); | 1553 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); |
1465 } | 1554 } |
1466 | 1555 |
1467 } // namespace chromeos | 1556 } // namespace chromeos |
OLD | NEW |