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

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

Issue 8773046: [cros] Display emails of users are stored in a separate dictionary in Local State. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/login/login_utils.h" 5 #include "chrome/browser/chromeos/login/login_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 net::NetworkChangeNotifier::AddOnlineStateObserver(this); 536 net::NetworkChangeNotifier::AddOnlineStateObserver(this);
537 } 537 }
538 538
539 virtual ~LoginUtilsImpl() { 539 virtual ~LoginUtilsImpl() {
540 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); 540 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
541 } 541 }
542 542
543 // LoginUtils implementation: 543 // LoginUtils implementation:
544 virtual void PrepareProfile( 544 virtual void PrepareProfile(
545 const std::string& username, 545 const std::string& username,
546 const std::string& display_email,
546 const std::string& password, 547 const std::string& password,
547 const GaiaAuthConsumer::ClientLoginResult& credentials, 548 const GaiaAuthConsumer::ClientLoginResult& credentials,
548 bool pending_requests, 549 bool pending_requests,
549 bool using_oauth, 550 bool using_oauth,
550 bool has_cookies, 551 bool has_cookies,
551 LoginUtils::Delegate* delegate) OVERRIDE; 552 LoginUtils::Delegate* delegate) OVERRIDE;
552 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; 553 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE;
553 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; 554 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE;
554 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; 555 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE;
555 virtual scoped_refptr<Authenticator> CreateAuthenticator( 556 virtual scoped_refptr<Authenticator> CreateAuthenticator(
556 LoginStatusConsumer* consumer) OVERRIDE; 557 LoginStatusConsumer* consumer) OVERRIDE;
557 virtual void PrewarmAuthentication() OVERRIDE; 558 virtual void PrewarmAuthentication() OVERRIDE;
558 virtual void RestoreAuthenticationSession(const std::string& user_name, 559 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE;
559 Profile* profile) OVERRIDE;
560 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; 560 virtual void StartTokenServices(Profile* user_profile) OVERRIDE;
561 virtual void StartSync( 561 virtual void StartSync(
562 Profile* profile, 562 Profile* profile,
563 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; 563 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE;
564 virtual void SetBackgroundView( 564 virtual void SetBackgroundView(
565 chromeos::BackgroundView* background_view) OVERRIDE; 565 chromeos::BackgroundView* background_view) OVERRIDE;
566 virtual chromeos::BackgroundView* GetBackgroundView() OVERRIDE; 566 virtual chromeos::BackgroundView* GetBackgroundView() OVERRIDE;
567 virtual void TransferDefaultCookies(Profile* default_profile, 567 virtual void TransferDefaultCookies(Profile* default_profile,
568 Profile* new_profile) OVERRIDE; 568 Profile* new_profile) OVERRIDE;
569 virtual void TransferDefaultAuthCache(Profile* default_profile, 569 virtual void TransferDefaultAuthCache(Profile* default_profile,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 void FetchPolicyToken(Profile* offrecord_profile, 635 void FetchPolicyToken(Profile* offrecord_profile,
636 const std::string& token, 636 const std::string& token,
637 const std::string& secret); 637 const std::string& secret);
638 638
639 // Check user's profile for kApplicationLocale setting. 639 // Check user's profile for kApplicationLocale setting.
640 void RespectLocalePreference(Profile* pref); 640 void RespectLocalePreference(Profile* pref);
641 641
642 // The current background view. 642 // The current background view.
643 chromeos::BackgroundView* background_view_; 643 chromeos::BackgroundView* background_view_;
644 644
645 std::string username_;
646 std::string password_; 645 std::string password_;
647 GaiaAuthConsumer::ClientLoginResult credentials_; 646 GaiaAuthConsumer::ClientLoginResult credentials_;
648 bool pending_requests_; 647 bool pending_requests_;
649 bool using_oauth_; 648 bool using_oauth_;
650 bool has_cookies_; 649 bool has_cookies_;
651 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). 650 // Has to be scoped_refptr, see comment for CreateAuthenticator(...).
652 scoped_refptr<Authenticator> authenticator_; 651 scoped_refptr<Authenticator> authenticator_;
653 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_; 652 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_;
654 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; 653 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_;
655 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; 654 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_;
(...skipping 30 matching lines...) Expand all
686 LoginUtilsWrapper() {} 685 LoginUtilsWrapper() {}
687 686
688 base::Lock create_lock_; 687 base::Lock create_lock_;
689 scoped_ptr<LoginUtils> ptr_; 688 scoped_ptr<LoginUtils> ptr_;
690 689
691 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper); 690 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper);
692 }; 691 };
693 692
694 void LoginUtilsImpl::PrepareProfile( 693 void LoginUtilsImpl::PrepareProfile(
695 const std::string& username, 694 const std::string& username,
695 const std::string& display_email,
696 const std::string& password, 696 const std::string& password,
697 const GaiaAuthConsumer::ClientLoginResult& credentials, 697 const GaiaAuthConsumer::ClientLoginResult& credentials,
698 bool pending_requests, 698 bool pending_requests,
699 bool using_oauth, 699 bool using_oauth,
700 bool has_cookies, 700 bool has_cookies,
701 LoginUtils::Delegate* delegate) { 701 LoginUtils::Delegate* delegate) {
702 BootTimesLoader* btl = BootTimesLoader::Get(); 702 BootTimesLoader* btl = BootTimesLoader::Get();
703 703
704 VLOG(1) << "Completing login for " << username; 704 VLOG(1) << "Completing login for " << username;
705 705
706 btl->AddLoginTimeMarker("StartSession-Start", false); 706 btl->AddLoginTimeMarker("StartSession-Start", false);
707 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( 707 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession(
708 username); 708 username);
709 btl->AddLoginTimeMarker("StartSession-End", false); 709 btl->AddLoginTimeMarker("StartSession-End", false);
710 710
711 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); 711 btl->AddLoginTimeMarker("UserLoggedIn-Start", false);
712 UserManager::Get()->UserLoggedIn(username); 712 UserManager* user_manager = UserManager::Get();
713 user_manager->UserLoggedIn(username);
713 btl->AddLoginTimeMarker("UserLoggedIn-End", false); 714 btl->AddLoginTimeMarker("UserLoggedIn-End", false);
714 715
715 // Switch log file as soon as possible. 716 // Switch log file as soon as possible.
716 logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess())); 717 logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess()));
717 718
718 username_ = username; 719 // Update user's displayed email.
720 if (!display_email.empty())
721 user_manager->SaveUserDisplayEmail(username, display_email);
722
719 password_ = password; 723 password_ = password;
720 724
721 credentials_ = credentials; 725 credentials_ = credentials;
722 pending_requests_ = pending_requests; 726 pending_requests_ = pending_requests;
723 using_oauth_ = using_oauth; 727 using_oauth_ = using_oauth;
724 has_cookies_ = has_cookies; 728 has_cookies_ = has_cookies;
725 delegate_ = delegate; 729 delegate_ = delegate;
726 730
727 policy::BrowserPolicyConnector* connector = 731 policy::BrowserPolicyConnector* connector =
728 g_browser_process->browser_policy_connector(); 732 g_browser_process->browser_policy_connector();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 void LoginUtilsImpl::StartSync( 882 void LoginUtilsImpl::StartSync(
879 Profile* user_profile, 883 Profile* user_profile,
880 const GaiaAuthConsumer::ClientLoginResult& credentials) { 884 const GaiaAuthConsumer::ClientLoginResult& credentials) {
881 TokenService* token_service = user_profile->GetTokenService(); 885 TokenService* token_service = user_profile->GetTokenService();
882 static bool initialized = false; 886 static bool initialized = false;
883 if (!initialized) { 887 if (!initialized) {
884 initialized = true; 888 initialized = true;
885 889
886 // Set the CrOS user by getting this constructor run with the 890 // Set the CrOS user by getting this constructor run with the
887 // user's email on first retrieval. 891 // user's email on first retrieval.
892 std::string email = UserManager::Get()->logged_in_user().email();
888 // TODO(tim): Tidy this up once cros_user is gone (part of bug 93922). 893 // TODO(tim): Tidy this up once cros_user is gone (part of bug 93922).
889 user_profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 894 user_profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, email);
890 username_); 895 user_profile->GetProfileSyncService(email)->SetPassphrase(password_, false);
891 user_profile->GetProfileSyncService(username_)->SetPassphrase(
892 password_, false);
893 username_ = "";
894 password_ = ""; 896 password_ = "";
895 897
896 token_service->Initialize(GaiaConstants::kChromeOSSource, user_profile); 898 token_service->Initialize(GaiaConstants::kChromeOSSource, user_profile);
897 token_service->LoadTokensFromDB(); 899 token_service->LoadTokensFromDB();
898 } 900 }
899 token_service->UpdateCredentials(credentials); 901 token_service->UpdateCredentials(credentials);
900 if (token_service->AreCredentialsValid()) 902 if (token_service->AreCredentialsValid())
901 token_service->StartFetchingTokens(); 903 token_service->StartFetchingTokens();
902 } 904 }
903 905
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 const int kConnectionsNeeded = 1; 1108 const int kConnectionsNeeded = 1;
1107 chrome_browser_net::PreconnectOnUIThread( 1109 chrome_browser_net::PreconnectOnUIThread(
1108 GURL(GaiaUrls::GetInstance()->client_login_url()), 1110 GURL(GaiaUrls::GetInstance()->client_login_url()),
1109 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, 1111 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED,
1110 kConnectionsNeeded); 1112 kConnectionsNeeded);
1111 } else { 1113 } else {
1112 new WarmingObserver(); 1114 new WarmingObserver();
1113 } 1115 }
1114 } 1116 }
1115 1117
1116 void LoginUtilsImpl::RestoreAuthenticationSession(const std::string& username, 1118 void LoginUtilsImpl::RestoreAuthenticationSession(Profile* user_profile) {
1117 Profile* user_profile) {
1118 username_ = username;
1119 KickStartAuthentication(user_profile); 1119 KickStartAuthentication(user_profile);
1120 } 1120 }
1121 1121
1122 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { 1122 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) {
1123 std::string oauth1_token; 1123 std::string oauth1_token;
1124 std::string oauth1_secret; 1124 std::string oauth1_secret;
1125 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) 1125 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret))
1126 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); 1126 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret);
1127 } 1127 }
1128 1128
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 const std::string& secret) { 1185 const std::string& secret) {
1186 FetchPolicyToken(offrecord_profile, token, secret); 1186 FetchPolicyToken(offrecord_profile, token, secret);
1187 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes 1187 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes
1188 // capable of handling OAuth1 tokens directly. 1188 // capable of handling OAuth1 tokens directly.
1189 } 1189 }
1190 1190
1191 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, 1191 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile,
1192 std::string* token, 1192 std::string* token,
1193 std::string* secret) { 1193 std::string* secret) {
1194 // Skip reading oauth token if user does not have a valid status. 1194 // Skip reading oauth token if user does not have a valid status.
1195 if (UserManager::Get()->GetUserOAuthStatus(username_) != 1195 if (UserManager::Get()->logged_in_user().oauth_token_status() !=
1196 User::OAUTH_TOKEN_STATUS_VALID) { 1196 User::OAUTH_TOKEN_STATUS_VALID) {
1197 return false; 1197 return false;
1198 } 1198 }
1199 1199
1200 PrefService* pref_service = user_profile->GetPrefs(); 1200 PrefService* pref_service = user_profile->GetPrefs();
1201 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token); 1201 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token);
1202 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret); 1202 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret);
1203 if (!encoded_token.length() || !encoded_secret.length()) 1203 if (!encoded_token.length() || !encoded_secret.length())
1204 return false; 1204 return false;
1205 1205
(...skipping 14 matching lines...) Expand all
1220 const std::string& secret) { 1220 const std::string& secret) {
1221 // First store OAuth1 token + service for the current user profile... 1221 // First store OAuth1 token + service for the current user profile...
1222 PrefService* pref_service = user_profile->GetPrefs(); 1222 PrefService* pref_service = user_profile->GetPrefs();
1223 pref_service->SetString(prefs::kOAuth1Token, 1223 pref_service->SetString(prefs::kOAuth1Token,
1224 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(token)); 1224 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(token));
1225 pref_service->SetString(prefs::kOAuth1Secret, 1225 pref_service->SetString(prefs::kOAuth1Secret,
1226 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(secret)); 1226 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(secret));
1227 1227
1228 // ...then record the presence of valid OAuth token for this account in local 1228 // ...then record the presence of valid OAuth token for this account in local
1229 // state as well. 1229 // state as well.
1230 UserManager::Get()->SaveUserOAuthStatus(username_, 1230 UserManager::Get()->SaveUserOAuthStatus(
1231 User::OAUTH_TOKEN_STATUS_VALID); 1231 UserManager::Get()->logged_in_user().email(),
1232 User::OAUTH_TOKEN_STATUS_VALID);
1232 } 1233 }
1233 1234
1234 void LoginUtilsImpl::VerifyOAuth1AccessToken(Profile* user_profile, 1235 void LoginUtilsImpl::VerifyOAuth1AccessToken(Profile* user_profile,
1235 const std::string& token, 1236 const std::string& token,
1236 const std::string& secret) { 1237 const std::string& secret) {
1237 // Kick off verification of OAuth1 access token (via OAuthLogin), this should 1238 // Kick off verification of OAuth1 access token (via OAuthLogin), this should
1238 // let us fetch credentials that will be used to initialize sync engine. 1239 // let us fetch credentials that will be used to initialize sync engine.
1239 FetchCredentials(user_profile, token, secret); 1240 FetchCredentials(user_profile, token, secret);
1240 1241
1241 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), token, secret); 1242 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), token, secret);
1242 } 1243 }
1243 1244
1244 void LoginUtilsImpl::FetchCredentials(Profile* user_profile, 1245 void LoginUtilsImpl::FetchCredentials(Profile* user_profile,
1245 const std::string& token, 1246 const std::string& token,
1246 const std::string& secret) { 1247 const std::string& secret) {
1247 oauth_login_verifier_.reset(new OAuthLoginVerifier(this, 1248 oauth_login_verifier_.reset(new OAuthLoginVerifier(
1248 user_profile, 1249 this, user_profile, token, secret,
1249 token, 1250 UserManager::Get()->logged_in_user().email()));
1250 secret,
1251 username_));
1252 oauth_login_verifier_->StartOAuthVerification(); 1251 oauth_login_verifier_->StartOAuthVerification();
1253 } 1252 }
1254 1253
1255 1254
1256 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, 1255 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile,
1257 const std::string& token, 1256 const std::string& token,
1258 const std::string& secret) { 1257 const std::string& secret) {
1259 // Fetch dm service token now, if it hasn't been fetched yet. 1258 // Fetch dm service token now, if it hasn't been fetched yet.
1260 if (!policy_oauth_fetcher_.get() || policy_oauth_fetcher_->failed()) { 1259 if (!policy_oauth_fetcher_.get() || policy_oauth_fetcher_->failed()) {
1261 // Trigger oauth token fetch for user policy. 1260 // Trigger oauth token fetch for user policy.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 // Mark login host for deletion after browser starts. This 1332 // Mark login host for deletion after browser starts. This
1334 // guarantees that the message loop will be referenced by the 1333 // guarantees that the message loop will be referenced by the
1335 // browser before it is dereferenced by the login host. 1334 // browser before it is dereferenced by the login host.
1336 if (login_host) { 1335 if (login_host) {
1337 login_host->OnSessionStart(); 1336 login_host->OnSessionStart();
1338 login_host = NULL; 1337 login_host = NULL;
1339 } 1338 }
1340 } 1339 }
1341 1340
1342 } // namespace chromeos 1341 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_utils.h ('k') | chrome/browser/chromeos/login/login_utils_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698