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

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

Issue 9404011: Explicitly wait for user policy before completing login. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
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 <vector> 7 #include <vector>
8 8
9 #include "base/bind.h"
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
11 #include "base/file_path.h" 12 #include "base/file_path.h"
12 #include "base/file_util.h" 13 #include "base/file_util.h"
13 #include "base/location.h" 14 #include "base/location.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/singleton.h" 17 #include "base/memory/singleton.h"
17 #include "base/path_service.h" 18 #include "base/path_service.h"
18 #include "base/string_util.h" 19 #include "base/string_util.h"
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 public GaiaOAuthConsumer, 536 public GaiaOAuthConsumer,
536 public OAuthLoginVerifier::Delegate, 537 public OAuthLoginVerifier::Delegate,
537 public net::NetworkChangeNotifier::OnlineStateObserver, 538 public net::NetworkChangeNotifier::OnlineStateObserver,
538 public base::SupportsWeakPtr<LoginUtilsImpl> { 539 public base::SupportsWeakPtr<LoginUtilsImpl> {
539 public: 540 public:
540 LoginUtilsImpl() 541 LoginUtilsImpl()
541 : pending_requests_(false), 542 : pending_requests_(false),
542 using_oauth_(false), 543 using_oauth_(false),
543 has_cookies_(false), 544 has_cookies_(false),
544 delegate_(NULL), 545 delegate_(NULL),
545 job_restart_request_(NULL) { 546 job_restart_request_(NULL),
547 user_policy_ready_(false),
548 profile_pending_creation_(NULL) {
546 net::NetworkChangeNotifier::AddOnlineStateObserver(this); 549 net::NetworkChangeNotifier::AddOnlineStateObserver(this);
547 } 550 }
548 551
549 virtual ~LoginUtilsImpl() { 552 virtual ~LoginUtilsImpl() {
550 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); 553 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
551 } 554 }
552 555
553 // LoginUtils implementation: 556 // LoginUtils implementation:
554 virtual void PrepareProfile( 557 virtual void PrepareProfile(
555 const std::string& username, 558 const std::string& username,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 const std::string& token, 644 const std::string& token,
642 const std::string& secret); 645 const std::string& secret);
643 646
644 // Check user's profile for kApplicationLocale setting. 647 // Check user's profile for kApplicationLocale setting.
645 void RespectLocalePreference(Profile* pref); 648 void RespectLocalePreference(Profile* pref);
646 649
647 // Callback for asynchronous profile creation. 650 // Callback for asynchronous profile creation.
648 void OnProfileCreated(Profile* profile, 651 void OnProfileCreated(Profile* profile,
649 Profile::CreateStatus status); 652 Profile::CreateStatus status);
650 653
654 // Callback for asynchronous notification that user policy is ready.
655 void OnUserPolicyReady();
656
657 // Invoked to resume profile creation after the profile is created and user
658 // policy has been loaded.
659 void ResumeProfileCreation(Profile* user_profile);
660
651 std::string password_; 661 std::string password_;
652 GaiaAuthConsumer::ClientLoginResult credentials_; 662 GaiaAuthConsumer::ClientLoginResult credentials_;
653 bool pending_requests_; 663 bool pending_requests_;
654 bool using_oauth_; 664 bool using_oauth_;
655 bool has_cookies_; 665 bool has_cookies_;
656 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). 666 // Has to be scoped_refptr, see comment for CreateAuthenticator(...).
657 scoped_refptr<Authenticator> authenticator_; 667 scoped_refptr<Authenticator> authenticator_;
658 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_; 668 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_;
659 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; 669 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_;
660 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; 670 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_;
661 671
662 // Delegate to be fired when the profile will be prepared. 672 // Delegate to be fired when the profile will be prepared.
663 LoginUtils::Delegate* delegate_; 673 LoginUtils::Delegate* delegate_;
664 674
665 // Used to restart Chrome to switch to the guest mode. 675 // Used to restart Chrome to switch to the guest mode.
666 JobRestartRequest* job_restart_request_; 676 JobRestartRequest* job_restart_request_;
667 677
678 // Profile creation should only resume once user policy is ready. Since both
679 // profile creation and user policy readiness notifications come
Mattias Nissler (ping if slow) 2012/02/16 10:24:11 s/come/are reported/
680 // asynchronously, these fields are used to track whether both are done.
681 bool user_policy_ready_;
682 Profile* profile_pending_creation_;
683
668 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); 684 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl);
669 }; 685 };
670 686
671 class LoginUtilsWrapper { 687 class LoginUtilsWrapper {
672 public: 688 public:
673 static LoginUtilsWrapper* GetInstance() { 689 static LoginUtilsWrapper* GetInstance() {
674 return Singleton<LoginUtilsWrapper>::get(); 690 return Singleton<LoginUtilsWrapper>::get();
675 } 691 }
676 692
677 LoginUtils* get() { 693 LoginUtils* get() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 // PrefService has the right values. 760 // PrefService has the right values.
745 // Profile creation is also resumed if the fetch attempt fails. 761 // Profile creation is also resumed if the fetch attempt fails.
746 bool wait_for_policy_fetch = 762 bool wait_for_policy_fetch =
747 using_oauth_ && 763 using_oauth_ &&
748 authenticator_.get() && 764 authenticator_.get() &&
749 (connector->GetUserAffiliation(username) == 765 (connector->GetUserAffiliation(username) ==
750 policy::USER_AFFILIATION_MANAGED); 766 policy::USER_AFFILIATION_MANAGED);
751 767
752 // Initialize user policy before the profile is created so the profile 768 // Initialize user policy before the profile is created so the profile
753 // initialization code sees the cached policy settings. 769 // initialization code sees the cached policy settings.
754 connector->InitializeUserPolicy(username, wait_for_policy_fetch); 770 user_policy_ready_ = false;
771 profile_pending_creation_ = NULL;
772 connector->InitializeUserPolicy(
Nikita (slow) 2012/02/20 16:10:24 What's the cost (and what happens behind the scene
Joao da Silva 2012/02/20 16:23:15 The cost is always the same. A couple of objects a
773 username,
774 wait_for_policy_fetch,
775 base::Bind(&LoginUtilsImpl::OnUserPolicyReady, AsWeakPtr()));
755 776
756 if (wait_for_policy_fetch) { 777 if (wait_for_policy_fetch) {
757 // Profile creation will block until user policy is fetched, which 778 // Profile creation will block until user policy is fetched, which
758 // requires the DeviceManagement token. Try to fetch it now. 779 // requires the DeviceManagement token. Try to fetch it now.
759 VLOG(1) << "Profile creation requires policy token, fetching now"; 780 VLOG(1) << "Profile creation requires policy token, fetching now";
760 policy_oauth_fetcher_.reset( 781 policy_oauth_fetcher_.reset(
761 new PolicyOAuthFetcher(authenticator_->authentication_profile())); 782 new PolicyOAuthFetcher(authenticator_->authentication_profile()));
762 policy_oauth_fetcher_->Start(); 783 policy_oauth_fetcher_->Start();
763 } 784 }
764 785
765 // The default profile will have been changed because the ProfileManager 786 // The default profile will have been changed because the ProfileManager
766 // will process the notification that the UserManager sends out. 787 // will process the notification that the UserManager sends out.
767 ProfileManager::CreateDefaultProfileAsync( 788 ProfileManager::CreateDefaultProfileAsync(
768 base::Bind(&LoginUtilsImpl::OnProfileCreated, AsWeakPtr())); 789 base::Bind(&LoginUtilsImpl::OnProfileCreated, AsWeakPtr()));
Mattias Nissler (ping if slow) 2012/02/16 10:24:11 Since user policy is not initialized at this point
Nikita (slow) 2012/02/20 16:10:24 I think this part could be done in a separate CL p
Joao da Silva 2012/02/20 16:23:15 Yes. This turned out to be a larger issue and we'v
769 } 790 }
770 791
771 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { 792 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) {
772 if (delegate_ == delegate) 793 if (delegate_ == delegate)
773 delegate_ = NULL; 794 delegate_ = NULL;
774 } 795 }
775 796
797 void LoginUtilsImpl::OnUserPolicyReady() {
798 user_policy_ready_ = true;
799 if (profile_pending_creation_) {
800 ResumeProfileCreation(profile_pending_creation_);
801 profile_pending_creation_ = NULL;
802 }
803 }
804
776 void LoginUtilsImpl::OnProfileCreated( 805 void LoginUtilsImpl::OnProfileCreated(
777 Profile* user_profile, 806 Profile* user_profile,
778 Profile::CreateStatus status) { 807 Profile::CreateStatus status) {
779 CHECK(user_profile); 808 CHECK(user_profile);
780 switch (status) { 809 switch (status) {
781 case Profile::CREATE_STATUS_INITIALIZED: 810 case Profile::CREATE_STATUS_INITIALIZED:
811 if (user_policy_ready_)
812 ResumeProfileCreation(user_profile);
813 else
814 profile_pending_creation_ = user_profile;
782 break; 815 break;
783 case Profile::CREATE_STATUS_CREATED: { 816 case Profile::CREATE_STATUS_CREATED: {
784 if (UserManager::Get()->current_user_is_new()) 817 if (UserManager::Get()->current_user_is_new())
785 SetFirstLoginPrefs(user_profile->GetPrefs()); 818 SetFirstLoginPrefs(user_profile->GetPrefs());
786 // Make sure that the google service username is properly set (we do this 819 // Make sure that the google service username is properly set (we do this
787 // on every sign in, not just the first login, to deal with existing 820 // on every sign in, not just the first login, to deal with existing
788 // profiles that might not have it set yet). 821 // profiles that might not have it set yet).
789 StringPrefMember google_services_username; 822 StringPrefMember google_services_username;
790 google_services_username.Init(prefs::kGoogleServicesUsername, 823 google_services_username.Init(prefs::kGoogleServicesUsername,
791 user_profile->GetPrefs(), NULL); 824 user_profile->GetPrefs(), NULL);
792 google_services_username.SetValue( 825 google_services_username.SetValue(
793 UserManager::Get()->logged_in_user().display_email()); 826 UserManager::Get()->logged_in_user().display_email());
794 // Make sure we flip every profile to not share proxies if the user hasn't 827 // Make sure we flip every profile to not share proxies if the user hasn't
795 // specified so explicitly. 828 // specified so explicitly.
796 const PrefService::Preference* use_shared_proxies_pref = 829 const PrefService::Preference* use_shared_proxies_pref =
797 user_profile->GetPrefs()->FindPreference(prefs::kUseSharedProxies); 830 user_profile->GetPrefs()->FindPreference(prefs::kUseSharedProxies);
798 if (use_shared_proxies_pref->IsDefaultValue()) 831 if (use_shared_proxies_pref->IsDefaultValue())
799 user_profile->GetPrefs()->SetBoolean(prefs::kUseSharedProxies, false); 832 user_profile->GetPrefs()->SetBoolean(prefs::kUseSharedProxies, false);
800 RespectLocalePreference(user_profile); 833 RespectLocalePreference(user_profile);
801 return; 834 break;
802 } 835 }
803 case Profile::CREATE_STATUS_FAIL: 836 case Profile::CREATE_STATUS_FAIL:
804 default: 837 default:
805 NOTREACHED(); 838 NOTREACHED();
806 return; 839 break;
807 } 840 }
841 }
808 842
843 void LoginUtilsImpl::ResumeProfileCreation(Profile* user_profile) {
809 BootTimesLoader* btl = BootTimesLoader::Get(); 844 BootTimesLoader* btl = BootTimesLoader::Get();
810 btl->AddLoginTimeMarker("UserProfileGotten", false); 845 btl->AddLoginTimeMarker("UserProfileGotten", false);
811 846
812 if (using_oauth_) { 847 if (using_oauth_) {
813 // Reuse the access token fetched by the PolicyOAuthFetcher, if it was 848 // Reuse the access token fetched by the PolicyOAuthFetcher, if it was
814 // used to fetch policies before Profile creation. 849 // used to fetch policies before Profile creation.
815 if (policy_oauth_fetcher_.get() && 850 if (policy_oauth_fetcher_.get() &&
816 !policy_oauth_fetcher_->oauth1_token().empty()) { 851 !policy_oauth_fetcher_->oauth1_token().empty()) {
817 VLOG(1) << "Resuming profile creation after fetching policy token"; 852 VLOG(1) << "Resuming profile creation after fetching policy token";
818 StoreOAuth1AccessToken(user_profile, 853 StoreOAuth1AccessToken(user_profile,
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 bool LoginUtils::IsWhitelisted(const std::string& username) { 1441 bool LoginUtils::IsWhitelisted(const std::string& username) {
1407 CrosSettings* cros_settings = CrosSettings::Get(); 1442 CrosSettings* cros_settings = CrosSettings::Get();
1408 bool allow_new_user = false; 1443 bool allow_new_user = false;
1409 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); 1444 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
1410 if (allow_new_user) 1445 if (allow_new_user)
1411 return true; 1446 return true;
1412 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); 1447 return cros_settings->FindEmailInList(kAccountsPrefUsers, username);
1413 } 1448 }
1414 1449
1415 } // namespace chromeos 1450 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698