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" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/signin/about_signin_internals_factory.h" | 23 #include "chrome/browser/signin/about_signin_internals_factory.h" |
24 #include "chrome/browser/signin/signin_global_error.h" | 24 #include "chrome/browser/signin/signin_global_error.h" |
25 #include "chrome/browser/signin/signin_internals_util.h" | 25 #include "chrome/browser/signin/signin_internals_util.h" |
26 #include "chrome/browser/signin/signin_manager_factory.h" | 26 #include "chrome/browser/signin/signin_manager_factory.h" |
27 #include "chrome/browser/signin/token_service.h" | 27 #include "chrome/browser/signin/token_service.h" |
28 #include "chrome/browser/signin/token_service_factory.h" | 28 #include "chrome/browser/signin/token_service_factory.h" |
29 #include "chrome/browser/sync/profile_sync_service.h" | 29 #include "chrome/browser/sync/profile_sync_service.h" |
30 #include "chrome/browser/sync/sync_prefs.h" | 30 #include "chrome/browser/sync/sync_prefs.h" |
31 #include "chrome/browser/ui/global_error/global_error_service.h" | 31 #include "chrome/browser/ui/global_error/global_error_service.h" |
32 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 32 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 33 #include "chrome/browser/ui/host_desktop.h" |
| 34 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" |
33 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
34 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
35 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
36 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
37 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
38 #include "google_apis/gaia/gaia_auth_fetcher.h" | 40 #include "google_apis/gaia/gaia_auth_fetcher.h" |
39 #include "google_apis/gaia/gaia_auth_util.h" | 41 #include "google_apis/gaia/gaia_auth_util.h" |
40 #include "google_apis/gaia/gaia_constants.h" | 42 #include "google_apis/gaia/gaia_constants.h" |
41 #include "google_apis/gaia/gaia_urls.h" | 43 #include "google_apis/gaia/gaia_urls.h" |
42 #include "net/cookies/cookie_monster.h" | 44 #include "net/cookies/cookie_monster.h" |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 CompleteSigninAfterPolicyLoad(); | 717 CompleteSigninAfterPolicyLoad(); |
716 return; | 718 return; |
717 } | 719 } |
718 | 720 |
719 // Stash away a copy of our CloudPolicyClient (should not already have one). | 721 // Stash away a copy of our CloudPolicyClient (should not already have one). |
720 DCHECK(!policy_client_); | 722 DCHECK(!policy_client_); |
721 policy_client_.swap(client); | 723 policy_client_.swap(client); |
722 | 724 |
723 DVLOG(1) << "Policy registration succeeded: dm_token=" | 725 DVLOG(1) << "Policy registration succeeded: dm_token=" |
724 << policy_client_->dm_token(); | 726 << policy_client_->dm_token(); |
725 // TODO(dconnelly): Prompt user for whether they want to create a new profile | 727 |
726 // or not (http://crbug.com/171236), and either call SignOut() if they cancel, | 728 // Allow user to create a new profile before continuing with sign-in. |
727 // TransferCredentialsToNewProfile() to create a new profile, or | 729 ProfileSigninConfirmationDialog::ShowDialog( |
728 // LoadPolicyWithCachedClient() if they want to sign in for the current | 730 profile_, |
729 // profile. | 731 possibly_invalid_username_, |
730 // For now, just call LoadPolicyWithCachedClient() to immediately load policy | 732 base::Bind(&SigninManager::SignOut, |
731 // into the current profile and finish signing in. | 733 weak_pointer_factory_.GetWeakPtr()), |
732 LoadPolicyWithCachedClient(policy_client_.Pass()); | 734 base::Bind(&SigninManager::TransferCredentialsToNewProfile, |
| 735 weak_pointer_factory_.GetWeakPtr()), |
| 736 base::Bind(&SigninManager::LoadPolicyWithCachedClient, |
| 737 weak_pointer_factory_.GetWeakPtr())); |
733 } | 738 } |
734 | 739 |
735 void SigninManager::LoadPolicyWithCachedClient( | 740 void SigninManager::LoadPolicyWithCachedClient() { |
736 scoped_ptr<policy::CloudPolicyClient> client) { | 741 DCHECK(policy_client_); |
737 DCHECK(client); | |
738 policy::UserPolicySigninService* policy_service = | 742 policy::UserPolicySigninService* policy_service = |
739 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); | 743 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); |
740 policy_service->FetchPolicyForSignedInUser( | 744 policy_service->FetchPolicyForSignedInUser( |
741 client.Pass(), | 745 policy_client_.Pass(), |
742 base::Bind(&SigninManager::OnPolicyFetchComplete, | 746 base::Bind(&SigninManager::OnPolicyFetchComplete, |
743 weak_pointer_factory_.GetWeakPtr())); | 747 weak_pointer_factory_.GetWeakPtr())); |
744 } | 748 } |
745 | 749 |
746 void SigninManager::OnPolicyFetchComplete(bool success) { | 750 void SigninManager::OnPolicyFetchComplete(bool success) { |
747 // For now, we allow signin to complete even if the policy fetch fails. If | 751 // For now, we allow signin to complete even if the policy fetch fails. If |
748 // we ever want to change this behavior, we could call SignOut() here | 752 // we ever want to change this behavior, we could call SignOut() here |
749 // instead. | 753 // instead. |
750 DLOG_IF(ERROR, !success) << "Error fetching policy for user"; | 754 DLOG_IF(ERROR, !success) << "Error fetching policy for user"; |
751 DVLOG_IF(1, success) << "Policy fetch successful - completing signin"; | 755 DVLOG_IF(1, success) << "Policy fetch successful - completing signin"; |
(...skipping 29 matching lines...) Expand all Loading... |
781 if (status == Profile::CREATE_STATUS_INITIALIZED) { | 785 if (status == Profile::CREATE_STATUS_INITIALIZED) { |
782 DCHECK(!possibly_invalid_username_.empty()); | 786 DCHECK(!possibly_invalid_username_.empty()); |
783 DCHECK(policy_client_); | 787 DCHECK(policy_client_); |
784 // Sign in to the just-created profile and fetch policy for it. | 788 // Sign in to the just-created profile and fetch policy for it. |
785 SigninManager* signin_manager = | 789 SigninManager* signin_manager = |
786 SigninManagerFactory::GetForProfile(profile); | 790 SigninManagerFactory::GetForProfile(profile); |
787 DCHECK(signin_manager); | 791 DCHECK(signin_manager); |
788 signin_manager->possibly_invalid_username_ = possibly_invalid_username_; | 792 signin_manager->possibly_invalid_username_ = possibly_invalid_username_; |
789 signin_manager->last_result_ = last_result_; | 793 signin_manager->last_result_ = last_result_; |
790 signin_manager->temp_oauth_login_tokens_ = temp_oauth_login_tokens_; | 794 signin_manager->temp_oauth_login_tokens_ = temp_oauth_login_tokens_; |
791 signin_manager->LoadPolicyWithCachedClient(policy_client_.Pass()); | 795 signin_manager->policy_client_.reset(policy_client_.release()); |
| 796 signin_manager->LoadPolicyWithCachedClient(); |
792 // Allow sync to start up if it is not overridden by policy. | 797 // Allow sync to start up if it is not overridden by policy. |
793 browser_sync::SyncPrefs prefs(profile->GetPrefs()); | 798 browser_sync::SyncPrefs prefs(profile->GetPrefs()); |
794 prefs.SetSyncSetupCompleted(); | 799 prefs.SetSyncSetupCompleted(); |
795 | 800 |
796 // We've transferred our credentials to the new profile - sign out. | 801 // We've transferred our credentials to the new profile - sign out. |
797 SignOut(); | 802 SignOut(); |
798 } | 803 } |
799 } | 804 } |
800 #endif | 805 #endif |
801 | 806 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 NotifySigninValueChanged(field, value)); | 921 NotifySigninValueChanged(field, value)); |
917 } | 922 } |
918 | 923 |
919 void SigninManager::NotifyDiagnosticsObservers( | 924 void SigninManager::NotifyDiagnosticsObservers( |
920 const TimedSigninStatusField& field, | 925 const TimedSigninStatusField& field, |
921 const std::string& value) { | 926 const std::string& value) { |
922 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, | 927 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, |
923 signin_diagnostics_observers_, | 928 signin_diagnostics_observers_, |
924 NotifySigninValueChanged(field, value)); | 929 NotifySigninValueChanged(field, value)); |
925 } | 930 } |
OLD | NEW |