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/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/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/string_split.h" | 13 #include "base/string_split.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/content_settings/cookie_settings.h" | 18 #include "chrome/browser/content_settings/cookie_settings.h" |
| 19 #include "chrome/browser/policy/user_policy_signin_service.h" | |
| 20 #include "chrome/browser/policy/user_policy_signin_service_factory.h" | |
|
Joao da Silva
2013/02/07 23:01:25
#ifdef ENABLE_CONFIGURATION_POLICY
Andrew T Wilson (Slow)
2013/02/08 10:48:07
Done.
| |
| 19 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/signin/about_signin_internals.h" | 23 #include "chrome/browser/signin/about_signin_internals.h" |
| 22 #include "chrome/browser/signin/about_signin_internals_factory.h" | 24 #include "chrome/browser/signin/about_signin_internals_factory.h" |
| 23 #include "chrome/browser/signin/signin_global_error.h" | 25 #include "chrome/browser/signin/signin_global_error.h" |
| 24 #include "chrome/browser/signin/signin_internals_util.h" | 26 #include "chrome/browser/signin/signin_internals_util.h" |
| 25 #include "chrome/browser/signin/token_service.h" | 27 #include "chrome/browser/signin/token_service.h" |
| 26 #include "chrome/browser/signin/token_service_factory.h" | 28 #include "chrome/browser/signin/token_service_factory.h" |
| 27 #include "chrome/browser/sync/profile_sync_service.h" | 29 #include "chrome/browser/sync/profile_sync_service.h" |
| 28 #include "chrome/browser/ui/global_error/global_error_service.h" | 30 #include "chrome/browser/ui/global_error/global_error_service.h" |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 | 641 |
| 640 void SigninManager::OnGetUserInfoSuccess(const UserInfoMap& data) { | 642 void SigninManager::OnGetUserInfoSuccess(const UserInfoMap& data) { |
| 641 NotifyDiagnosticsObservers(GET_USER_INFO_STATUS, "Successful"); | 643 NotifyDiagnosticsObservers(GET_USER_INFO_STATUS, "Successful"); |
| 642 | 644 |
| 643 UserInfoMap::const_iterator email_iter = data.find(kGetInfoEmailKey); | 645 UserInfoMap::const_iterator email_iter = data.find(kGetInfoEmailKey); |
| 644 UserInfoMap::const_iterator display_email_iter = | 646 UserInfoMap::const_iterator display_email_iter = |
| 645 data.find(kGetInfoDisplayEmailKey); | 647 data.find(kGetInfoDisplayEmailKey); |
| 646 if (email_iter == data.end()) { | 648 if (email_iter == data.end()) { |
| 647 OnGetUserInfoKeyNotFound(kGetInfoEmailKey); | 649 OnGetUserInfoKeyNotFound(kGetInfoEmailKey); |
| 648 return; | 650 return; |
| 649 } else if (display_email_iter == data.end()) { | 651 } |
| 652 if (display_email_iter == data.end()) { | |
| 650 OnGetUserInfoKeyNotFound(kGetInfoDisplayEmailKey); | 653 OnGetUserInfoKeyNotFound(kGetInfoDisplayEmailKey); |
| 651 return; | 654 return; |
| 652 } else { | 655 } |
| 653 DCHECK(email_iter->first == kGetInfoEmailKey); | 656 DCHECK(email_iter->first == kGetInfoEmailKey); |
| 654 DCHECK(display_email_iter->first == kGetInfoDisplayEmailKey); | 657 DCHECK(display_email_iter->first == kGetInfoDisplayEmailKey); |
| 655 | 658 |
| 656 // When signing in with credentials, the possibly invalid name is the Gaia | 659 // When signing in with credentials, the possibly invalid name is the Gaia |
| 657 // display name. If the name returned by GetUserInfo does not match what is | 660 // display name. If the name returned by GetUserInfo does not match what is |
| 658 // expected, return an error. | 661 // expected, return an error. |
| 659 if (type_ == SIGNIN_TYPE_WITH_CREDENTIALS && | 662 if (type_ == SIGNIN_TYPE_WITH_CREDENTIALS && |
| 660 base::strcasecmp(display_email_iter->second.c_str(), | 663 base::strcasecmp(display_email_iter->second.c_str(), |
| 661 possibly_invalid_username_.c_str()) != 0) { | 664 possibly_invalid_username_.c_str()) != 0) { |
| 662 OnGetUserInfoKeyNotFound(kGetInfoDisplayEmailKey); | 665 OnGetUserInfoKeyNotFound(kGetInfoDisplayEmailKey); |
| 663 return; | 666 return; |
| 664 } | 667 } |
| 665 | 668 |
| 666 SetAuthenticatedUsername(email_iter->second); | 669 possibly_invalid_username_ = email_iter->second; |
| 667 possibly_invalid_username_.clear(); | 670 |
| 668 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 671 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) |
| 669 authenticated_username_); | 672 // If we have an OAuth token, try loading policy for this user now, before |
| 673 // any signed in services are initialized. If there's no oauth token (the | |
| 674 // user is using the old ClientLogin flow) then policy will get loaded once | |
| 675 // the TokenService finishes initializing (not ideal, but it's a reasonable | |
| 676 // fallback). | |
| 677 if (!temp_oauth_login_tokens_.refresh_token.empty()) { | |
| 678 policy::UserPolicySigninService* policy_service = | |
| 679 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); | |
| 680 policy_service->RegisterPolicyClient( | |
| 681 possibly_invalid_username_, | |
| 682 temp_oauth_login_tokens_.refresh_token, | |
| 683 base::Bind(&SigninManager::OnRegisteredForPolicy, | |
| 684 base::Unretained(this))); | |
| 685 return; | |
| 670 } | 686 } |
| 687 #endif | |
| 688 | |
| 689 // Not waiting for policy load - just complete signin directly. | |
| 690 CompleteSigninAfterPolicyLoad(); | |
| 691 } | |
| 692 | |
| 693 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) | |
| 694 void SigninManager::OnRegisteredForPolicy( | |
|
Joao da Silva
2013/02/07 23:01:25
Does this have to exist? policy_service->RegisterP
Andrew T Wilson (Slow)
2013/02/08 10:48:07
Yeah, per our previous conversation we want to put
| |
| 695 scoped_ptr<policy::CloudPolicyClient> client) { | |
| 696 // If there's no token for the user (no policy) just finish signing in. | |
| 697 if (!client.get()) { | |
| 698 DVLOG(1) << "Policy registration failed"; | |
| 699 CompleteSigninAfterPolicyLoad(); | |
| 700 return; | |
| 701 } | |
| 702 | |
| 703 DVLOG(1) << "Policy registration succeeded: dm_token=" << client->dm_token(); | |
| 704 // TODO(dconnelly): Prompt user for whether they want to create a new profile | |
| 705 // or not (http://crbug.com/171236). For now, just immediately load policy. | |
| 706 policy::UserPolicySigninService* policy_service = | |
| 707 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); | |
| 708 policy_service->FetchPolicyForSignedInUser( | |
| 709 client.Pass(), | |
| 710 base::Bind(&SigninManager::OnPolicyFetchComplete, | |
| 711 base::Unretained(this))); | |
| 712 | |
|
Joao da Silva
2013/02/07 23:01:25
remove extra newline
Andrew T Wilson (Slow)
2013/02/08 10:48:07
Done.
| |
| 713 } | |
| 714 | |
| 715 void SigninManager::OnPolicyFetchComplete(bool success) { | |
| 716 // For now, we allow signin to complete even if the policy fetch fails. If | |
| 717 // we ever want to change this behavior, we could call SignOut() here | |
| 718 // instead. | |
| 719 DLOG_IF(ERROR, !success) << "Error fetching policy for user"; | |
| 720 DVLOG_IF(1, success) << "Policy fetch successful - completing signin"; | |
| 721 CompleteSigninAfterPolicyLoad(); | |
| 722 } | |
| 723 #endif | |
| 724 | |
| 725 void SigninManager::CompleteSigninAfterPolicyLoad() { | |
| 726 DCHECK(!possibly_invalid_username_.empty()); | |
| 727 SetAuthenticatedUsername(possibly_invalid_username_); | |
| 728 possibly_invalid_username_.clear(); | |
| 729 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | |
| 730 authenticated_username_); | |
| 731 | |
| 671 GoogleServiceSigninSuccessDetails details(authenticated_username_, | 732 GoogleServiceSigninSuccessDetails details(authenticated_username_, |
| 672 password_); | 733 password_); |
| 673 content::NotificationService::current()->Notify( | 734 content::NotificationService::current()->Notify( |
| 674 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 735 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| 675 content::Source<Profile>(profile_), | 736 content::Source<Profile>(profile_), |
| 676 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); | 737 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
| 677 | 738 |
| 678 password_.clear(); // Don't need it anymore. | 739 password_.clear(); // Don't need it anymore. |
| 679 DisableOneClickSignIn(profile_); // Don't ever offer again. | 740 DisableOneClickSignIn(profile_); // Don't ever offer again. |
| 680 | 741 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 NotifySigninValueChanged(field, value)); | 827 NotifySigninValueChanged(field, value)); |
| 767 } | 828 } |
| 768 | 829 |
| 769 void SigninManager::NotifyDiagnosticsObservers( | 830 void SigninManager::NotifyDiagnosticsObservers( |
| 770 const TimedSigninStatusField& field, | 831 const TimedSigninStatusField& field, |
| 771 const std::string& value) { | 832 const std::string& value) { |
| 772 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, | 833 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, |
| 773 signin_diagnostics_observers_, | 834 signin_diagnostics_observers_, |
| 774 NotifySigninValueChanged(field, value)); | 835 NotifySigninValueChanged(field, value)); |
| 775 } | 836 } |
| OLD | NEW |