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

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

Issue 9147026: API for connection type (Ethernet/WIFI/WWAN ...) in NetworkChangeNotifier. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Review comments Created 8 years, 7 months 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
OLDNEW
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
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
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 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::IsOffline()) {
1234 should_restore_auth_session_ = false; 1236 should_restore_auth_session_ = false;
1235 KickStartAuthentication(user_profile); 1237 KickStartAuthentication(user_profile);
1236 } else { 1238 } else {
1237 // Even if we're online we should wait till initial OnOnlineStateChanged() 1239 // Even if we're online we should wait till initial
1238 // call. Otherwise starting fetchers too early may end up cancelling 1240 // OnConnectionTypeChanged() call. Otherwise starting fetchers too early may
1239 // all request when initial network state is processed. 1241 // end up cancelling all request when initial network connection type is
1240 // See http://crbug.com/121643. 1242 // processed. See http://crbug.com/121643.
1241 should_restore_auth_session_ = true; 1243 should_restore_auth_session_ = true;
1242 } 1244 }
1243 } 1245 }
1244 1246
1245 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { 1247 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) {
1246 std::string oauth1_token; 1248 std::string oauth1_token;
1247 std::string oauth1_secret; 1249 std::string oauth1_secret;
1248 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) 1250 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret))
1249 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); 1251 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret);
1250 } 1252 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 void LoginUtilsImpl::OnOAuthVerificationSucceeded( 1420 void LoginUtilsImpl::OnOAuthVerificationSucceeded(
1419 const std::string& user_name, const std::string& sid, 1421 const std::string& user_name, const std::string& sid,
1420 const std::string& lsid, const std::string& auth) { 1422 const std::string& lsid, const std::string& auth) {
1421 // Kick off sync engine. 1423 // Kick off sync engine.
1422 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, 1424 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth,
1423 std::string()); 1425 std::string());
1424 StartSignedInServices(ProfileManager::GetDefaultProfile(), credentials); 1426 StartSignedInServices(ProfileManager::GetDefaultProfile(), credentials);
1425 } 1427 }
1426 1428
1427 1429
1428 void LoginUtilsImpl::OnOnlineStateChanged(bool online) { 1430 void LoginUtilsImpl::OnConnectionTypeChanged(
1429 if (online && UserManager::Get()->IsUserLoggedIn()) { 1431 net::NetworkChangeNotifier::ConnectionType type) {
1432 if (type != net::NetworkChangeNotifier::CONNECTION_NONE &&
1433 UserManager::Get()->IsUserLoggedIn()) {
1430 if (oauth_login_verifier_.get() && 1434 if (oauth_login_verifier_.get() &&
1431 !oauth_login_verifier_->is_done()) { 1435 !oauth_login_verifier_->is_done()) {
1432 // If we come online for the first time after successful offline login, 1436 // If we come online for the first time after successful offline login,
1433 // we need to kick of OAuth token verification process again. 1437 // we need to kick of OAuth token verification process again.
1434 oauth_login_verifier_->ContinueVerification(); 1438 oauth_login_verifier_->ContinueVerification();
1435 } else if (should_restore_auth_session_) { 1439 } else if (should_restore_auth_session_) {
1436 should_restore_auth_session_ = false; 1440 should_restore_auth_session_ = false;
1437 Profile* user_profile = ProfileManager::GetDefaultProfile(); 1441 Profile* user_profile = ProfileManager::GetDefaultProfile();
1438 KickStartAuthentication(user_profile); 1442 KickStartAuthentication(user_profile);
1439 } 1443 }
(...skipping 14 matching lines...) Expand all
1454 bool LoginUtils::IsWhitelisted(const std::string& username) { 1458 bool LoginUtils::IsWhitelisted(const std::string& username) {
1455 CrosSettings* cros_settings = CrosSettings::Get(); 1459 CrosSettings* cros_settings = CrosSettings::Get();
1456 bool allow_new_user = false; 1460 bool allow_new_user = false;
1457 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); 1461 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
1458 if (allow_new_user) 1462 if (allow_new_user)
1459 return true; 1463 return true;
1460 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); 1464 return cros_settings->FindEmailInList(kAccountsPrefUsers, username);
1461 } 1465 }
1462 1466
1463 } // namespace chromeos 1467 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/net/network_change_notifier_chromeos.h » ('j') | net/base/network_change_notifier.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698