| 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 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 MessageLoop::current()->AssertIdle(); | 528 MessageLoop::current()->AssertIdle(); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 int pid_; | 532 int pid_; |
| 533 std::string command_line_; | 533 std::string command_line_; |
| 534 PrefService* local_state_; | 534 PrefService* local_state_; |
| 535 base::OneShotTimer<JobRestartRequest> timer_; | 535 base::OneShotTimer<JobRestartRequest> timer_; |
| 536 }; | 536 }; |
| 537 | 537 |
| 538 class LoginUtilsImpl : public LoginUtils, | 538 class LoginUtilsImpl |
| 539 public GaiaOAuthConsumer, | 539 : public LoginUtils, |
| 540 public OAuthLoginVerifier::Delegate, | 540 public GaiaOAuthConsumer, |
| 541 public net::NetworkChangeNotifier::OnlineStateObserver, | 541 public OAuthLoginVerifier::Delegate, |
| 542 public base::SupportsWeakPtr<LoginUtilsImpl> { | 542 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 543 public base::SupportsWeakPtr<LoginUtilsImpl> { |
| 543 public: | 544 public: |
| 544 LoginUtilsImpl() | 545 LoginUtilsImpl() |
| 545 : pending_requests_(false), | 546 : pending_requests_(false), |
| 546 using_oauth_(false), | 547 using_oauth_(false), |
| 547 has_cookies_(false), | 548 has_cookies_(false), |
| 548 delegate_(NULL), | 549 delegate_(NULL), |
| 549 job_restart_request_(NULL), | 550 job_restart_request_(NULL), |
| 550 should_restore_auth_session_(false) { | 551 should_restore_auth_session_(false) { |
| 551 net::NetworkChangeNotifier::AddOnlineStateObserver(this); | 552 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 552 } | 553 } |
| 553 | 554 |
| 554 virtual ~LoginUtilsImpl() { | 555 virtual ~LoginUtilsImpl() { |
| 555 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); | 556 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 556 } | 557 } |
| 557 | 558 |
| 558 // LoginUtils implementation: | 559 // LoginUtils implementation: |
| 559 virtual void DoBrowserLaunch(Profile* profile, | 560 virtual void DoBrowserLaunch(Profile* profile, |
| 560 LoginDisplayHost* login_host) OVERRIDE; | 561 LoginDisplayHost* login_host) OVERRIDE; |
| 561 virtual void PrepareProfile( | 562 virtual void PrepareProfile( |
| 562 const std::string& username, | 563 const std::string& username, |
| 563 const std::string& display_email, | 564 const std::string& display_email, |
| 564 const std::string& password, | 565 const std::string& password, |
| 565 bool pending_requests, | 566 bool pending_requests, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 592 virtual void OnOAuthGetAccessTokenFailure( | 593 virtual void OnOAuthGetAccessTokenFailure( |
| 593 const GoogleServiceAuthError& error) OVERRIDE; | 594 const GoogleServiceAuthError& error) OVERRIDE; |
| 594 | 595 |
| 595 // OAuthLoginVerifier::Delegate overrides. | 596 // OAuthLoginVerifier::Delegate overrides. |
| 596 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, | 597 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, |
| 597 const std::string& sid, | 598 const std::string& sid, |
| 598 const std::string& lsid, | 599 const std::string& lsid, |
| 599 const std::string& auth) OVERRIDE; | 600 const std::string& auth) OVERRIDE; |
| 600 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE; | 601 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE; |
| 601 | 602 |
| 602 // net::NetworkChangeNotifier::OnlineStateObserver overrides. | 603 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
| 603 virtual void OnOnlineStateChanged(bool online) OVERRIDE; | 604 virtual void OnConnectionTypeChanged( |
| 605 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 604 | 606 |
| 605 // Given the authenticated credentials from the cookie jar, try to exchange | 607 // Given the authenticated credentials from the cookie jar, try to exchange |
| 606 // fetch OAuth request, v1 and v2 tokens. | 608 // fetch OAuth request, v1 and v2 tokens. |
| 607 void FetchOAuth1AccessToken(Profile* auth_profile); | 609 void FetchOAuth1AccessToken(Profile* auth_profile); |
| 608 | 610 |
| 609 protected: | 611 protected: |
| 610 virtual std::string GetOffTheRecordCommandLine( | 612 virtual std::string GetOffTheRecordCommandLine( |
| 611 const GURL& start_url, | 613 const GURL& start_url, |
| 612 const CommandLine& base_command_line, | 614 const CommandLine& base_command_line, |
| 613 CommandLine *command_line); | 615 CommandLine *command_line); |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 if (!UserManager::Get()->IsUserLoggedIn() || | 1225 if (!UserManager::Get()->IsUserLoggedIn() || |
| 1224 UserManager::Get()->IsLoggedInAsGuest() || | 1226 UserManager::Get()->IsLoggedInAsGuest() || |
| 1225 UserManager::Get()->IsLoggedInAsDemoUser()) { | 1227 UserManager::Get()->IsLoggedInAsDemoUser()) { |
| 1226 return; | 1228 return; |
| 1227 } | 1229 } |
| 1228 | 1230 |
| 1229 if (!net::NetworkChangeNotifier::IsOffline()) { | 1231 if (!net::NetworkChangeNotifier::IsOffline()) { |
| 1230 should_restore_auth_session_ = false; | 1232 should_restore_auth_session_ = false; |
| 1231 KickStartAuthentication(user_profile); | 1233 KickStartAuthentication(user_profile); |
| 1232 } else { | 1234 } else { |
| 1233 // Even if we're online we should wait till initial OnOnlineStateChanged() | 1235 // Even if we're online we should wait till initial |
| 1234 // call. Otherwise starting fetchers too early may end up cancelling | 1236 // OnConnectionTypeChanged() call. Otherwise starting fetchers too early may |
| 1235 // all request when initial network state is processed. | 1237 // end up cancelling all request when initial network connection type is |
| 1236 // See http://crbug.com/121643. | 1238 // processed. See http://crbug.com/121643. |
| 1237 should_restore_auth_session_ = true; | 1239 should_restore_auth_session_ = true; |
| 1238 } | 1240 } |
| 1239 } | 1241 } |
| 1240 | 1242 |
| 1241 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { | 1243 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { |
| 1242 std::string oauth1_token; | 1244 std::string oauth1_token; |
| 1243 std::string oauth1_secret; | 1245 std::string oauth1_secret; |
| 1244 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | 1246 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
| 1245 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); | 1247 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); |
| 1246 } | 1248 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 void LoginUtilsImpl::OnOAuthVerificationSucceeded( | 1416 void LoginUtilsImpl::OnOAuthVerificationSucceeded( |
| 1415 const std::string& user_name, const std::string& sid, | 1417 const std::string& user_name, const std::string& sid, |
| 1416 const std::string& lsid, const std::string& auth) { | 1418 const std::string& lsid, const std::string& auth) { |
| 1417 // Kick off sync engine. | 1419 // Kick off sync engine. |
| 1418 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, | 1420 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, |
| 1419 std::string()); | 1421 std::string()); |
| 1420 StartSignedInServices(ProfileManager::GetDefaultProfile(), credentials); | 1422 StartSignedInServices(ProfileManager::GetDefaultProfile(), credentials); |
| 1421 } | 1423 } |
| 1422 | 1424 |
| 1423 | 1425 |
| 1424 void LoginUtilsImpl::OnOnlineStateChanged(bool online) { | 1426 void LoginUtilsImpl::OnConnectionTypeChanged( |
| 1425 if (online && UserManager::Get()->IsUserLoggedIn()) { | 1427 net::NetworkChangeNotifier::ConnectionType type) { |
| 1428 if (type != net::NetworkChangeNotifier::CONNECTION_NONE && |
| 1429 UserManager::Get()->IsUserLoggedIn()) { |
| 1426 if (oauth_login_verifier_.get() && | 1430 if (oauth_login_verifier_.get() && |
| 1427 !oauth_login_verifier_->is_done()) { | 1431 !oauth_login_verifier_->is_done()) { |
| 1428 // If we come online for the first time after successful offline login, | 1432 // If we come online for the first time after successful offline login, |
| 1429 // we need to kick of OAuth token verification process again. | 1433 // we need to kick of OAuth token verification process again. |
| 1430 oauth_login_verifier_->ContinueVerification(); | 1434 oauth_login_verifier_->ContinueVerification(); |
| 1431 } else if (should_restore_auth_session_) { | 1435 } else if (should_restore_auth_session_) { |
| 1432 should_restore_auth_session_ = false; | 1436 should_restore_auth_session_ = false; |
| 1433 Profile* user_profile = ProfileManager::GetDefaultProfile(); | 1437 Profile* user_profile = ProfileManager::GetDefaultProfile(); |
| 1434 KickStartAuthentication(user_profile); | 1438 KickStartAuthentication(user_profile); |
| 1435 } | 1439 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1450 bool LoginUtils::IsWhitelisted(const std::string& username) { | 1454 bool LoginUtils::IsWhitelisted(const std::string& username) { |
| 1451 CrosSettings* cros_settings = CrosSettings::Get(); | 1455 CrosSettings* cros_settings = CrosSettings::Get(); |
| 1452 bool allow_new_user = false; | 1456 bool allow_new_user = false; |
| 1453 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 1457 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 1454 if (allow_new_user) | 1458 if (allow_new_user) |
| 1455 return true; | 1459 return true; |
| 1456 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); | 1460 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); |
| 1457 } | 1461 } |
| 1458 | 1462 |
| 1459 } // namespace chromeos | 1463 } // namespace chromeos |
| OLD | NEW |