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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 net::NetworkChangeNotifier::AddOnlineStateObserver(this); | 530 net::NetworkChangeNotifier::AddOnlineStateObserver(this); |
531 } | 531 } |
532 | 532 |
533 virtual ~LoginUtilsImpl() { | 533 virtual ~LoginUtilsImpl() { |
534 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); | 534 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); |
535 } | 535 } |
536 | 536 |
537 // LoginUtils implementation: | 537 // LoginUtils implementation: |
538 virtual void PrepareProfile( | 538 virtual void PrepareProfile( |
539 const std::string& username, | 539 const std::string& username, |
540 const std::string& display_email, | |
540 const std::string& password, | 541 const std::string& password, |
541 const GaiaAuthConsumer::ClientLoginResult& credentials, | 542 const GaiaAuthConsumer::ClientLoginResult& credentials, |
542 bool pending_requests, | 543 bool pending_requests, |
543 bool using_oauth, | 544 bool using_oauth, |
544 bool has_cookies, | 545 bool has_cookies, |
545 LoginUtils::Delegate* delegate) OVERRIDE; | 546 LoginUtils::Delegate* delegate) OVERRIDE; |
546 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; | 547 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; |
547 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; | 548 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; |
548 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; | 549 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; |
549 virtual scoped_refptr<Authenticator> CreateAuthenticator( | 550 virtual scoped_refptr<Authenticator> CreateAuthenticator( |
550 LoginStatusConsumer* consumer) OVERRIDE; | 551 LoginStatusConsumer* consumer) OVERRIDE; |
551 virtual void PrewarmAuthentication() OVERRIDE; | 552 virtual void PrewarmAuthentication() OVERRIDE; |
552 virtual void RestoreAuthenticationSession(const std::string& user_name, | 553 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; |
553 Profile* profile) OVERRIDE; | |
554 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; | 554 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; |
555 virtual void StartSync( | 555 virtual void StartSync( |
556 Profile* profile, | 556 Profile* profile, |
557 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | 557 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; |
558 virtual void SetBackgroundView( | 558 virtual void SetBackgroundView( |
559 chromeos::BackgroundView* background_view) OVERRIDE; | 559 chromeos::BackgroundView* background_view) OVERRIDE; |
560 virtual chromeos::BackgroundView* GetBackgroundView() OVERRIDE; | 560 virtual chromeos::BackgroundView* GetBackgroundView() OVERRIDE; |
561 virtual void TransferDefaultCookies(Profile* default_profile, | 561 virtual void TransferDefaultCookies(Profile* default_profile, |
562 Profile* new_profile) OVERRIDE; | 562 Profile* new_profile) OVERRIDE; |
563 virtual void TransferDefaultAuthCache(Profile* default_profile, | 563 virtual void TransferDefaultAuthCache(Profile* default_profile, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
629 void FetchPolicyToken(Profile* offrecord_profile, | 629 void FetchPolicyToken(Profile* offrecord_profile, |
630 const std::string& token, | 630 const std::string& token, |
631 const std::string& secret); | 631 const std::string& secret); |
632 | 632 |
633 // Check user's profile for kApplicationLocale setting. | 633 // Check user's profile for kApplicationLocale setting. |
634 void RespectLocalePreference(Profile* pref); | 634 void RespectLocalePreference(Profile* pref); |
635 | 635 |
636 // The current background view. | 636 // The current background view. |
637 chromeos::BackgroundView* background_view_; | 637 chromeos::BackgroundView* background_view_; |
638 | 638 |
639 std::string username_; | |
640 std::string password_; | 639 std::string password_; |
641 GaiaAuthConsumer::ClientLoginResult credentials_; | 640 GaiaAuthConsumer::ClientLoginResult credentials_; |
642 bool pending_requests_; | 641 bool pending_requests_; |
643 bool using_oauth_; | 642 bool using_oauth_; |
644 bool has_cookies_; | 643 bool has_cookies_; |
645 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). | 644 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). |
646 scoped_refptr<Authenticator> authenticator_; | 645 scoped_refptr<Authenticator> authenticator_; |
647 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_; | 646 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_; |
648 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; | 647 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; |
649 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; | 648 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; |
(...skipping 30 matching lines...) Expand all Loading... | |
680 LoginUtilsWrapper() {} | 679 LoginUtilsWrapper() {} |
681 | 680 |
682 base::Lock create_lock_; | 681 base::Lock create_lock_; |
683 scoped_ptr<LoginUtils> ptr_; | 682 scoped_ptr<LoginUtils> ptr_; |
684 | 683 |
685 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper); | 684 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper); |
686 }; | 685 }; |
687 | 686 |
688 void LoginUtilsImpl::PrepareProfile( | 687 void LoginUtilsImpl::PrepareProfile( |
689 const std::string& username, | 688 const std::string& username, |
689 const std::string& display_email, | |
690 const std::string& password, | 690 const std::string& password, |
691 const GaiaAuthConsumer::ClientLoginResult& credentials, | 691 const GaiaAuthConsumer::ClientLoginResult& credentials, |
692 bool pending_requests, | 692 bool pending_requests, |
693 bool using_oauth, | 693 bool using_oauth, |
694 bool has_cookies, | 694 bool has_cookies, |
695 LoginUtils::Delegate* delegate) { | 695 LoginUtils::Delegate* delegate) { |
696 BootTimesLoader* btl = BootTimesLoader::Get(); | 696 BootTimesLoader* btl = BootTimesLoader::Get(); |
697 | 697 |
698 VLOG(1) << "Completing login for " << username; | 698 VLOG(1) << "Completing login for " << username; |
699 | 699 |
700 btl->AddLoginTimeMarker("StartSession-Start", false); | 700 btl->AddLoginTimeMarker("StartSession-Start", false); |
701 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( | 701 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( |
702 username); | 702 username); |
703 btl->AddLoginTimeMarker("StartSession-End", false); | 703 btl->AddLoginTimeMarker("StartSession-End", false); |
704 | 704 |
705 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); | 705 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); |
706 UserManager::Get()->UserLoggedIn(username); | 706 UserManager* user_manager = UserManager::Get(); |
707 user_manager->UserLoggedIn(username); | |
707 btl->AddLoginTimeMarker("UserLoggedIn-End", false); | 708 btl->AddLoginTimeMarker("UserLoggedIn-End", false); |
708 | 709 |
709 // Switch log file as soon as possible. | 710 // Switch log file as soon as possible. |
710 logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess())); | 711 logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess())); |
711 | 712 |
712 username_ = username; | 713 // Update user's displayed email. |
714 if (!display_email.empty()) | |
715 user_manager->SaveUserDisplayEmail(username, display_email, true); | |
716 | |
713 password_ = password; | 717 password_ = password; |
714 | 718 |
715 credentials_ = credentials; | 719 credentials_ = credentials; |
716 pending_requests_ = pending_requests; | 720 pending_requests_ = pending_requests; |
717 using_oauth_ = using_oauth; | 721 using_oauth_ = using_oauth; |
718 has_cookies_ = has_cookies; | 722 has_cookies_ = has_cookies; |
719 delegate_ = delegate; | 723 delegate_ = delegate; |
720 | 724 |
721 policy::BrowserPolicyConnector* connector = | 725 policy::BrowserPolicyConnector* connector = |
722 g_browser_process->browser_policy_connector(); | 726 g_browser_process->browser_policy_connector(); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 void LoginUtilsImpl::StartSync( | 876 void LoginUtilsImpl::StartSync( |
873 Profile* user_profile, | 877 Profile* user_profile, |
874 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 878 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
875 TokenService* token_service = user_profile->GetTokenService(); | 879 TokenService* token_service = user_profile->GetTokenService(); |
876 static bool initialized = false; | 880 static bool initialized = false; |
877 if (!initialized) { | 881 if (!initialized) { |
878 initialized = true; | 882 initialized = true; |
879 | 883 |
880 // Set the CrOS user by getting this constructor run with the | 884 // Set the CrOS user by getting this constructor run with the |
881 // user's email on first retrieval. | 885 // user's email on first retrieval. |
886 std::string email = UserManager::Get()->logged_in_user().display_email(); | |
882 // TODO(tim): Tidy this up once cros_user is gone (part of bug 93922). | 887 // TODO(tim): Tidy this up once cros_user is gone (part of bug 93922). |
883 user_profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 888 user_profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, email); |
884 username_); | 889 user_profile->GetProfileSyncService(email)->SetPassphrase(password_, false); |
Nikita (slow)
2011/12/05 13:13:04
Please double check how email is used in Sync serv
Ivan Korotkov
2011/12/05 14:12:48
As discussed offline, removed from this CL.
| |
885 user_profile->GetProfileSyncService(username_)->SetPassphrase( | |
886 password_, false); | |
887 username_ = ""; | |
888 password_ = ""; | 890 password_ = ""; |
889 | 891 |
890 token_service->Initialize(GaiaConstants::kChromeOSSource, user_profile); | 892 token_service->Initialize(GaiaConstants::kChromeOSSource, user_profile); |
891 token_service->LoadTokensFromDB(); | 893 token_service->LoadTokensFromDB(); |
892 } | 894 } |
893 token_service->UpdateCredentials(credentials); | 895 token_service->UpdateCredentials(credentials); |
894 if (token_service->AreCredentialsValid()) | 896 if (token_service->AreCredentialsValid()) |
895 token_service->StartFetchingTokens(); | 897 token_service->StartFetchingTokens(); |
896 } | 898 } |
897 | 899 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1100 const int kConnectionsNeeded = 1; | 1102 const int kConnectionsNeeded = 1; |
1101 chrome_browser_net::PreconnectOnUIThread( | 1103 chrome_browser_net::PreconnectOnUIThread( |
1102 GURL(GaiaUrls::GetInstance()->client_login_url()), | 1104 GURL(GaiaUrls::GetInstance()->client_login_url()), |
1103 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, | 1105 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, |
1104 kConnectionsNeeded); | 1106 kConnectionsNeeded); |
1105 } else { | 1107 } else { |
1106 new WarmingObserver(); | 1108 new WarmingObserver(); |
1107 } | 1109 } |
1108 } | 1110 } |
1109 | 1111 |
1110 void LoginUtilsImpl::RestoreAuthenticationSession(const std::string& username, | 1112 void LoginUtilsImpl::RestoreAuthenticationSession(Profile* user_profile) { |
1111 Profile* user_profile) { | |
1112 username_ = username; | |
1113 KickStartAuthentication(user_profile); | 1113 KickStartAuthentication(user_profile); |
1114 } | 1114 } |
1115 | 1115 |
1116 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { | 1116 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { |
1117 if (!authenticator_.get()) | 1117 if (!authenticator_.get()) |
1118 CreateAuthenticator(NULL); | 1118 CreateAuthenticator(NULL); |
1119 std::string oauth1_token; | 1119 std::string oauth1_token; |
1120 std::string oauth1_secret; | 1120 std::string oauth1_secret; |
1121 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | 1121 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
1122 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); | 1122 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1183 const std::string& secret) { | 1183 const std::string& secret) { |
1184 FetchPolicyToken(offrecord_profile, token, secret); | 1184 FetchPolicyToken(offrecord_profile, token, secret); |
1185 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes | 1185 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes |
1186 // capable of handling OAuth1 tokens directly. | 1186 // capable of handling OAuth1 tokens directly. |
1187 } | 1187 } |
1188 | 1188 |
1189 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, | 1189 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, |
1190 std::string* token, | 1190 std::string* token, |
1191 std::string* secret) { | 1191 std::string* secret) { |
1192 // Skip reading oauth token if user does not have a valid status. | 1192 // Skip reading oauth token if user does not have a valid status. |
1193 if (UserManager::Get()->GetUserOAuthStatus(username_) != | 1193 if (UserManager::Get()->logged_in_user().oauth_token_status() != |
1194 User::OAUTH_TOKEN_STATUS_VALID) { | 1194 User::OAUTH_TOKEN_STATUS_VALID) { |
1195 return false; | 1195 return false; |
1196 } | 1196 } |
1197 | 1197 |
1198 PrefService* pref_service = user_profile->GetPrefs(); | 1198 PrefService* pref_service = user_profile->GetPrefs(); |
1199 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token); | 1199 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token); |
1200 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret); | 1200 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret); |
1201 if (!encoded_token.length() || !encoded_secret.length()) | 1201 if (!encoded_token.length() || !encoded_secret.length()) |
1202 return false; | 1202 return false; |
1203 | 1203 |
(...skipping 13 matching lines...) Expand all Loading... | |
1217 const std::string& secret) { | 1217 const std::string& secret) { |
1218 // First store OAuth1 token + service for the current user profile... | 1218 // First store OAuth1 token + service for the current user profile... |
1219 PrefService* pref_service = user_profile->GetPrefs(); | 1219 PrefService* pref_service = user_profile->GetPrefs(); |
1220 pref_service->SetString(prefs::kOAuth1Token, | 1220 pref_service->SetString(prefs::kOAuth1Token, |
1221 authenticator_->EncryptToken(token)); | 1221 authenticator_->EncryptToken(token)); |
1222 pref_service->SetString(prefs::kOAuth1Secret, | 1222 pref_service->SetString(prefs::kOAuth1Secret, |
1223 authenticator_->EncryptToken(secret)); | 1223 authenticator_->EncryptToken(secret)); |
1224 | 1224 |
1225 // ...then record the presence of valid OAuth token for this account in local | 1225 // ...then record the presence of valid OAuth token for this account in local |
1226 // state as well. | 1226 // state as well. |
1227 UserManager::Get()->SaveUserOAuthStatus(username_, | 1227 UserManager::Get()->SaveUserOAuthStatus( |
1228 User::OAUTH_TOKEN_STATUS_VALID); | 1228 UserManager::Get()->logged_in_user().email(), |
1229 User::OAUTH_TOKEN_STATUS_VALID); | |
1229 } | 1230 } |
1230 | 1231 |
1231 void LoginUtilsImpl::VerifyOAuth1AccessToken(Profile* user_profile, | 1232 void LoginUtilsImpl::VerifyOAuth1AccessToken(Profile* user_profile, |
1232 const std::string& token, | 1233 const std::string& token, |
1233 const std::string& secret) { | 1234 const std::string& secret) { |
1234 // Kick off verification of OAuth1 access token (via OAuthLogin), this should | 1235 // Kick off verification of OAuth1 access token (via OAuthLogin), this should |
1235 // let us fetch credentials that will be used to initialize sync engine. | 1236 // let us fetch credentials that will be used to initialize sync engine. |
1236 FetchCredentials(user_profile, token, secret); | 1237 FetchCredentials(user_profile, token, secret); |
1237 | 1238 |
1238 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), token, secret); | 1239 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), token, secret); |
1239 } | 1240 } |
1240 | 1241 |
1241 void LoginUtilsImpl::FetchCredentials(Profile* user_profile, | 1242 void LoginUtilsImpl::FetchCredentials(Profile* user_profile, |
1242 const std::string& token, | 1243 const std::string& token, |
1243 const std::string& secret) { | 1244 const std::string& secret) { |
1244 oauth_login_verifier_.reset(new OAuthLoginVerifier(this, | 1245 oauth_login_verifier_.reset(new OAuthLoginVerifier( |
1245 user_profile, | 1246 this, user_profile, token, secret, |
1246 token, | 1247 UserManager::Get()->logged_in_user().email())); |
1247 secret, | |
1248 username_)); | |
1249 oauth_login_verifier_->StartOAuthVerification(); | 1248 oauth_login_verifier_->StartOAuthVerification(); |
1250 } | 1249 } |
1251 | 1250 |
1252 | 1251 |
1253 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, | 1252 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, |
1254 const std::string& token, | 1253 const std::string& token, |
1255 const std::string& secret) { | 1254 const std::string& secret) { |
1256 // Fetch dm service token now, if it hasn't been fetched yet. | 1255 // Fetch dm service token now, if it hasn't been fetched yet. |
1257 if (!policy_oauth_fetcher_.get() || policy_oauth_fetcher_->failed()) { | 1256 if (!policy_oauth_fetcher_.get() || policy_oauth_fetcher_->failed()) { |
1258 // Trigger oauth token fetch for user policy. | 1257 // Trigger oauth token fetch for user policy. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1330 // Mark login host for deletion after browser starts. This | 1329 // Mark login host for deletion after browser starts. This |
1331 // guarantees that the message loop will be referenced by the | 1330 // guarantees that the message loop will be referenced by the |
1332 // browser before it is dereferenced by the login host. | 1331 // browser before it is dereferenced by the login host. |
1333 if (login_host) { | 1332 if (login_host) { |
1334 login_host->OnSessionStart(); | 1333 login_host->OnSessionStart(); |
1335 login_host = NULL; | 1334 login_host = NULL; |
1336 } | 1335 } |
1337 } | 1336 } |
1338 | 1337 |
1339 } // namespace chromeos | 1338 } // namespace chromeos |
OLD | NEW |