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