| 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/signin/signin_manager.h" | 5 #include "chrome/browser/signin/signin_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 bool SigninManager::IsSigninProcess(int process_id) const { | 112 bool SigninManager::IsSigninProcess(int process_id) const { |
| 113 return process_id == signin_host_id_; | 113 return process_id == signin_host_id_; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool SigninManager::HasSigninProcess() const { | 116 bool SigninManager::HasSigninProcess() const { |
| 117 return signin_host_id_ != ChildProcessHost::kInvalidUniqueID; | 117 return signin_host_id_ != ChildProcessHost::kInvalidUniqueID; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void SigninManager::AddMergeSessionObserver( |
| 121 GoogleAutoLoginHelper::Observer* observer) { |
| 122 if (merge_session_helper_) |
| 123 merge_session_helper_->AddObserver(observer); |
| 124 } |
| 125 |
| 126 void SigninManager::RemoveMergeSessionObserver( |
| 127 GoogleAutoLoginHelper::Observer* observer) { |
| 128 if (merge_session_helper_) |
| 129 merge_session_helper_->RemoveObserver(observer); |
| 130 } |
| 131 |
| 120 SigninManager::~SigninManager() { | 132 SigninManager::~SigninManager() { |
| 121 } | 133 } |
| 122 | 134 |
| 123 void SigninManager::InitTokenService() { | 135 void SigninManager::InitTokenService() { |
| 124 ProfileOAuth2TokenService* token_service = | 136 ProfileOAuth2TokenService* token_service = |
| 125 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 137 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 126 if (token_service && !GetAuthenticatedUsername().empty()) | 138 if (token_service && !GetAuthenticatedUsername().empty()) |
| 127 token_service->LoadCredentials(); | 139 token_service->LoadCredentials(); |
| 128 } | 140 } |
| 129 | 141 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 if ((!user.empty() && !IsAllowedUsername(user)) || !IsSigninAllowed()) { | 374 if ((!user.empty() && !IsAllowedUsername(user)) || !IsSigninAllowed()) { |
| 363 // User is signed in, but the username is invalid - the administrator must | 375 // User is signed in, but the username is invalid - the administrator must |
| 364 // have changed the policy since the last signin, so sign out the user. | 376 // have changed the policy since the last signin, so sign out the user. |
| 365 SignOut(); | 377 SignOut(); |
| 366 } | 378 } |
| 367 | 379 |
| 368 account_id_helper_.reset(new SigninAccountIdHelper(profile)); | 380 account_id_helper_.reset(new SigninAccountIdHelper(profile)); |
| 369 } | 381 } |
| 370 | 382 |
| 371 void SigninManager::Shutdown() { | 383 void SigninManager::Shutdown() { |
| 384 if (merge_session_helper_) |
| 385 merge_session_helper_->CancelAll(); |
| 386 |
| 372 local_state_pref_registrar_.RemoveAll(); | 387 local_state_pref_registrar_.RemoveAll(); |
| 373 account_id_helper_.reset(); | 388 account_id_helper_.reset(); |
| 374 SigninManagerBase::Shutdown(); | 389 SigninManagerBase::Shutdown(); |
| 375 } | 390 } |
| 376 | 391 |
| 377 void SigninManager::OnGoogleServicesUsernamePatternChanged() { | 392 void SigninManager::OnGoogleServicesUsernamePatternChanged() { |
| 378 if (!GetAuthenticatedUsername().empty() && | 393 if (!GetAuthenticatedUsername().empty() && |
| 379 !IsAllowedUsername(GetAuthenticatedUsername())) { | 394 !IsAllowedUsername(GetAuthenticatedUsername())) { |
| 380 // Signed in user is invalid according to the current policy so sign | 395 // Signed in user is invalid according to the current policy so sign |
| 381 // the user out. | 396 // the user out. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 } else { | 565 } else { |
| 551 // No oauth token or callback, so just complete our pending signin. | 566 // No oauth token or callback, so just complete our pending signin. |
| 552 CompletePendingSignin(); | 567 CompletePendingSignin(); |
| 553 } | 568 } |
| 554 } | 569 } |
| 555 | 570 |
| 556 void SigninManager::CompletePendingSignin() { | 571 void SigninManager::CompletePendingSignin() { |
| 557 DCHECK(!possibly_invalid_username_.empty()); | 572 DCHECK(!possibly_invalid_username_.empty()); |
| 558 OnSignedIn(possibly_invalid_username_); | 573 OnSignedIn(possibly_invalid_username_); |
| 559 | 574 |
| 575 // If inline sign in is enabled, but new profile management is not, perform a |
| 576 // merge session now to push the user's credentials into the cookie jar. |
| 577 bool do_merge_session_in_signin_manager = |
| 578 !switches::IsEnableWebBasedSignin() && |
| 579 !switches::IsNewProfileManagement(); |
| 580 |
| 581 if (do_merge_session_in_signin_manager) |
| 582 merge_session_helper_.reset(new GoogleAutoLoginHelper(profile_, NULL)); |
| 583 |
| 560 DCHECK(!temp_oauth_login_tokens_.refresh_token.empty()); | 584 DCHECK(!temp_oauth_login_tokens_.refresh_token.empty()); |
| 561 DCHECK(!GetAuthenticatedUsername().empty()); | 585 DCHECK(!GetAuthenticatedUsername().empty()); |
| 562 ProfileOAuth2TokenService* token_service = | 586 ProfileOAuth2TokenService* token_service = |
| 563 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 587 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 564 token_service->UpdateCredentials(GetAuthenticatedUsername(), | 588 token_service->UpdateCredentials(GetAuthenticatedUsername(), |
| 565 temp_oauth_login_tokens_.refresh_token); | 589 temp_oauth_login_tokens_.refresh_token); |
| 566 temp_oauth_login_tokens_ = ClientOAuthResult(); | 590 temp_oauth_login_tokens_ = ClientOAuthResult(); |
| 591 |
| 592 if (do_merge_session_in_signin_manager) |
| 593 merge_session_helper_->LogIn(); |
| 567 } | 594 } |
| 568 | 595 |
| 569 void SigninManager::OnExternalSigninCompleted(const std::string& username) { | 596 void SigninManager::OnExternalSigninCompleted(const std::string& username) { |
| 570 OnSignedIn(username); | 597 OnSignedIn(username); |
| 571 } | 598 } |
| 572 | 599 |
| 573 void SigninManager::OnSignedIn(const std::string& username) { | 600 void SigninManager::OnSignedIn(const std::string& username) { |
| 574 SetAuthenticatedUsername(username); | 601 SetAuthenticatedUsername(username); |
| 575 possibly_invalid_username_.clear(); | 602 possibly_invalid_username_.clear(); |
| 576 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 603 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 } | 645 } |
| 619 } | 646 } |
| 620 | 647 |
| 621 void SigninManager::ProhibitSignout(bool prohibit_signout) { | 648 void SigninManager::ProhibitSignout(bool prohibit_signout) { |
| 622 prohibit_signout_ = prohibit_signout; | 649 prohibit_signout_ = prohibit_signout; |
| 623 } | 650 } |
| 624 | 651 |
| 625 bool SigninManager::IsSignoutProhibited() const { | 652 bool SigninManager::IsSignoutProhibited() const { |
| 626 return prohibit_signout_; | 653 return prohibit_signout_; |
| 627 } | 654 } |
| OLD | NEW |