| 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 "base/chromeos/chromeos_version.h" | 10 #include "base/chromeos/chromeos_version.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } // namespace | 95 } // namespace |
| 96 | 96 |
| 97 class LoginUtilsImpl | 97 class LoginUtilsImpl |
| 98 : public LoginUtils, | 98 : public LoginUtils, |
| 99 public OAuthLoginManager::Delegate, | 99 public OAuthLoginManager::Delegate, |
| 100 public net::NetworkChangeNotifier::ConnectionTypeObserver, | 100 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 101 public base::SupportsWeakPtr<LoginUtilsImpl> { | 101 public base::SupportsWeakPtr<LoginUtilsImpl> { |
| 102 public: | 102 public: |
| 103 LoginUtilsImpl() | 103 LoginUtilsImpl() |
| 104 : using_oauth_(false), | 104 : using_oauth_(false), |
| 105 should_finalize_profile_(false), |
| 105 has_web_auth_cookies_(false), | 106 has_web_auth_cookies_(false), |
| 106 login_manager_(OAuthLoginManager::Create(this)), | 107 login_manager_(OAuthLoginManager::Create(this)), |
| 107 delegate_(NULL), | 108 delegate_(NULL), |
| 108 should_restore_auth_session_(false), | 109 should_restore_auth_session_(false), |
| 109 session_restore_strategy_( | 110 session_restore_strategy_( |
| 110 OAuthLoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN) { | 111 OAuthLoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN) { |
| 111 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 112 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 112 } | 113 } |
| 113 | 114 |
| 114 virtual ~LoginUtilsImpl() { | 115 virtual ~LoginUtilsImpl() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 128 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; | 129 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; |
| 129 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; | 130 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; |
| 130 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; | 131 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; |
| 131 virtual scoped_refptr<Authenticator> CreateAuthenticator( | 132 virtual scoped_refptr<Authenticator> CreateAuthenticator( |
| 132 LoginStatusConsumer* consumer) OVERRIDE; | 133 LoginStatusConsumer* consumer) OVERRIDE; |
| 133 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; | 134 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; |
| 134 virtual void StopBackgroundFetchers() OVERRIDE; | 135 virtual void StopBackgroundFetchers() OVERRIDE; |
| 135 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; | 136 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; |
| 136 | 137 |
| 137 // OAuthLoginManager::Delegate overrides. | 138 // OAuthLoginManager::Delegate overrides. |
| 139 virtual void OnStartMergeSession(Profile* user_profile) OVERRIDE; |
| 138 virtual void OnCompletedMergeSession() OVERRIDE; | 140 virtual void OnCompletedMergeSession() OVERRIDE; |
| 139 virtual void OnCompletedAuthentication(Profile* user_profile) OVERRIDE; | 141 virtual void OnCompletedAuthentication(Profile* user_profile) OVERRIDE; |
| 140 virtual void OnFoundStoredTokens() OVERRIDE; | 142 virtual void OnFoundStoredTokens() OVERRIDE; |
| 141 | 143 |
| 142 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. | 144 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
| 143 virtual void OnConnectionTypeChanged( | 145 virtual void OnConnectionTypeChanged( |
| 144 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 146 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 145 | 147 |
| 146 private: | 148 private: |
| 147 // Restarts OAuth session authentication check. | 149 // Restarts OAuth session authentication check. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 bool restore_from_auth_cookies); | 182 bool restore_from_auth_cookies); |
| 181 | 183 |
| 182 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. | 184 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. |
| 183 void InitRlz(Profile* user_profile, bool disabled); | 185 void InitRlz(Profile* user_profile, bool disabled); |
| 184 | 186 |
| 185 // Starts signing related services. Initiates TokenService token retrieval. | 187 // Starts signing related services. Initiates TokenService token retrieval. |
| 186 void StartSignedInServices(Profile* profile); | 188 void StartSignedInServices(Profile* profile); |
| 187 | 189 |
| 188 UserContext user_context_; | 190 UserContext user_context_; |
| 189 bool using_oauth_; | 191 bool using_oauth_; |
| 192 bool should_finalize_profile_; |
| 193 |
| 190 // True if the authentication profile's cookie jar should contain | 194 // True if the authentication profile's cookie jar should contain |
| 191 // authentication cookies from the authentication extension log in flow. | 195 // authentication cookies from the authentication extension log in flow. |
| 192 bool has_web_auth_cookies_; | 196 bool has_web_auth_cookies_; |
| 193 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). | 197 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). |
| 194 scoped_refptr<Authenticator> authenticator_; | 198 scoped_refptr<Authenticator> authenticator_; |
| 195 scoped_ptr<OAuthLoginManager> login_manager_; | 199 scoped_ptr<OAuthLoginManager> login_manager_; |
| 196 | 200 |
| 197 // Delegate to be fired when the profile will be prepared. | 201 // Delegate to be fired when the profile will be prepared. |
| 198 LoginUtils::Delegate* delegate_; | 202 LoginUtils::Delegate* delegate_; |
| 199 | 203 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 &LoginUtilsImpl::CompleteProfileCreate, | 456 &LoginUtilsImpl::CompleteProfileCreate, |
| 453 AsWeakPtr(), | 457 AsWeakPtr(), |
| 454 user_profile)); | 458 user_profile)); |
| 455 return; | 459 return; |
| 456 } | 460 } |
| 457 | 461 |
| 458 FinalizePrepareProfile(user_profile); | 462 FinalizePrepareProfile(user_profile); |
| 459 } | 463 } |
| 460 | 464 |
| 461 void LoginUtilsImpl::CompleteProfileCreate(Profile* user_profile) { | 465 void LoginUtilsImpl::CompleteProfileCreate(Profile* user_profile) { |
| 466 should_finalize_profile_ = true; |
| 462 RestoreAuthSession(user_profile, has_web_auth_cookies_); | 467 RestoreAuthSession(user_profile, has_web_auth_cookies_); |
| 463 FinalizePrepareProfile(user_profile); | |
| 464 } | 468 } |
| 465 | 469 |
| 466 void LoginUtilsImpl::RestoreAuthSession(Profile* user_profile, | 470 void LoginUtilsImpl::RestoreAuthSession(Profile* user_profile, |
| 467 bool restore_from_auth_cookies) { | 471 bool restore_from_auth_cookies) { |
| 468 CHECK((authenticator_.get() && authenticator_->authentication_profile()) || | 472 CHECK((authenticator_.get() && authenticator_->authentication_profile()) || |
| 469 !restore_from_auth_cookies); | 473 !restore_from_auth_cookies); |
| 470 if (!login_manager_.get()) | 474 if (!login_manager_.get()) |
| 471 return; | 475 return; |
| 472 | 476 |
| 473 if (chrome::IsRunningInForcedAppMode() || | 477 if (chrome::IsRunningInForcedAppMode() || |
| 474 CommandLine::ForCurrentProcess()->HasSwitch( | 478 CommandLine::ForCurrentProcess()->HasSwitch( |
| 475 chromeos::switches::kOobeSkipPostLogin)) | 479 chromeos::switches::kOobeSkipPostLogin)) |
| 476 return; | 480 return; |
| 477 | 481 |
| 478 UserManager::Get()->SetMergeSessionState( | 482 UserManager::Get()->SetMergeSessionState( |
| 479 UserManager::MERGE_STATUS_IN_PROCESS); | 483 UserManager::MERGE_STATUS_PREPARING); |
| 480 | 484 |
| 481 // Remove legacy OAuth1 token if we have one. If it's valid, we should already | 485 // Remove legacy OAuth1 token if we have one. If it's valid, we should already |
| 482 // have OAuth2 refresh token in TokenService that could be used to retrieve | 486 // have OAuth2 refresh token in TokenService that could be used to retrieve |
| 483 // all other tokens and user_context. | 487 // all other tokens and user_context. |
| 484 login_manager_->RestoreSession( | 488 login_manager_->RestoreSession( |
| 485 user_profile, | 489 user_profile, |
| 486 authenticator_.get() && authenticator_->authentication_profile() | 490 authenticator_.get() && authenticator_->authentication_profile() |
| 487 ? authenticator_->authentication_profile()->GetRequestContext() | 491 ? authenticator_->authentication_profile()->GetRequestContext() |
| 488 : NULL, | 492 : NULL, |
| 489 session_restore_strategy_, | 493 session_restore_strategy_, |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 } | 732 } |
| 729 | 733 |
| 730 void LoginUtilsImpl::StopBackgroundFetchers() { | 734 void LoginUtilsImpl::StopBackgroundFetchers() { |
| 731 login_manager_.reset(); | 735 login_manager_.reset(); |
| 732 } | 736 } |
| 733 | 737 |
| 734 void LoginUtilsImpl::OnCompletedAuthentication(Profile* user_profile) { | 738 void LoginUtilsImpl::OnCompletedAuthentication(Profile* user_profile) { |
| 735 StartSignedInServices(user_profile); | 739 StartSignedInServices(user_profile); |
| 736 } | 740 } |
| 737 | 741 |
| 742 void LoginUtilsImpl::OnStartMergeSession(Profile* user_profile) { |
| 743 UserManager::Get()->SetMergeSessionState( |
| 744 UserManager::MERGE_STATUS_IN_PROCESS); |
| 745 |
| 746 if (should_finalize_profile_) |
| 747 FinalizePrepareProfile(user_profile); |
| 748 |
| 749 should_finalize_profile_ = false; |
| 750 } |
| 751 |
| 738 void LoginUtilsImpl::OnCompletedMergeSession() { | 752 void LoginUtilsImpl::OnCompletedMergeSession() { |
| 739 UserManager::Get()->SetMergeSessionState(UserManager::MERGE_STATUS_DONE); | 753 UserManager::Get()->SetMergeSessionState(UserManager::MERGE_STATUS_DONE); |
| 740 } | 754 } |
| 741 | 755 |
| 742 void LoginUtilsImpl::OnFoundStoredTokens() { | 756 void LoginUtilsImpl::OnFoundStoredTokens() { |
| 743 // We don't need authenticator instance any more since its cookie jar | 757 // We don't need authenticator instance any more since its cookie jar |
| 744 // is not going to needed to mint OAuth tokens. Reset it so that | 758 // is not going to needed to mint OAuth tokens. Reset it so that |
| 745 // ScreenLocker would create a separate instance. | 759 // ScreenLocker would create a separate instance. |
| 746 authenticator_ = NULL; | 760 authenticator_ = NULL; |
| 747 } | 761 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 bool LoginUtils::IsWhitelisted(const std::string& username) { | 801 bool LoginUtils::IsWhitelisted(const std::string& username) { |
| 788 CrosSettings* cros_settings = CrosSettings::Get(); | 802 CrosSettings* cros_settings = CrosSettings::Get(); |
| 789 bool allow_new_user = false; | 803 bool allow_new_user = false; |
| 790 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 804 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 791 if (allow_new_user) | 805 if (allow_new_user) |
| 792 return true; | 806 return true; |
| 793 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); | 807 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); |
| 794 } | 808 } |
| 795 | 809 |
| 796 } // namespace chromeos | 810 } // namespace chromeos |
| OLD | NEW |