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

Side by Side Diff: chrome/browser/chromeos/login/session/user_session_manager.cc

Issue 417623002: user_manager component: Add UserManagerBase class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: check for LocalState, update test - make sure that policies are initialized on UserManager creation Created 6 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/session/user_session_manager.h" 5 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 19 matching lines...) Expand all
30 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" 30 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h"
31 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory .h" 31 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory .h"
32 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" 32 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
33 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" 33 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h"
34 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" 34 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
35 #include "chrome/browser/chromeos/login/users/user_manager.h" 35 #include "chrome/browser/chromeos/login/users/user_manager.h"
36 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" 36 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h"
37 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 37 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
38 #include "chrome/browser/chromeos/profiles/profile_helper.h" 38 #include "chrome/browser/chromeos/profiles/profile_helper.h"
39 #include "chrome/browser/chromeos/settings/cros_settings.h" 39 #include "chrome/browser/chromeos/settings/cros_settings.h"
40 #include "chrome/browser/component_updater/component_updater_service.h"
40 #include "chrome/browser/first_run/first_run.h" 41 #include "chrome/browser/first_run/first_run.h"
41 #include "chrome/browser/google/google_brand_chromeos.h" 42 #include "chrome/browser/google/google_brand_chromeos.h"
42 #include "chrome/browser/lifetime/application_lifetime.h" 43 #include "chrome/browser/lifetime/application_lifetime.h"
44 #include "chrome/browser/net/crl_set_fetcher.h"
43 #include "chrome/browser/net/nss_context.h" 45 #include "chrome/browser/net/nss_context.h"
44 #include "chrome/browser/profiles/profile.h" 46 #include "chrome/browser/profiles/profile.h"
45 #include "chrome/browser/profiles/profile_manager.h" 47 #include "chrome/browser/profiles/profile_manager.h"
46 #include "chrome/browser/rlz/rlz.h" 48 #include "chrome/browser/rlz/rlz.h"
47 #include "chrome/browser/signin/signin_manager_factory.h" 49 #include "chrome/browser/signin/signin_manager_factory.h"
48 #include "chrome/common/chrome_switches.h" 50 #include "chrome/common/chrome_switches.h"
49 #include "chrome/common/logging_chrome.h" 51 #include "chrome/common/logging_chrome.h"
50 #include "chrome/common/pref_names.h" 52 #include "chrome/common/pref_names.h"
51 #include "chromeos/cert_loader.h" 53 #include "chromeos/cert_loader.h"
52 #include "chromeos/chromeos_switches.h" 54 #include "chromeos/chromeos_switches.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 return; 311 return;
310 } 312 }
311 base::PostTaskAndReplyWithResult( 313 base::PostTaskAndReplyWithResult(
312 base::WorkerPool::GetTaskRunner(false), 314 base::WorkerPool::GetTaskRunner(false),
313 FROM_HERE, 315 FROM_HERE,
314 base::Bind(&base::PathExists, GetRlzDisabledFlagPath()), 316 base::Bind(&base::PathExists, GetRlzDisabledFlagPath()),
315 base::Bind(&UserSessionManager::InitRlzImpl, AsWeakPtr(), profile)); 317 base::Bind(&UserSessionManager::InitRlzImpl, AsWeakPtr(), profile));
316 #endif 318 #endif
317 } 319 }
318 320
319 bool UserSessionManager::HasBrowserRestarted() const {
320 CommandLine* command_line = CommandLine::ForCurrentProcess();
321 return base::SysInfo::IsRunningOnChromeOS() &&
322 command_line->HasSwitch(switches::kLoginUser);
323 }
324
325 OAuth2LoginManager::SessionRestoreStrategy 321 OAuth2LoginManager::SessionRestoreStrategy
326 UserSessionManager::GetSigninSessionRestoreStrategy() { 322 UserSessionManager::GetSigninSessionRestoreStrategy() {
327 return session_restore_strategy_; 323 return session_restore_strategy_;
328 } 324 }
329 325
330 // static 326 // static
331 void UserSessionManager::SetFirstLoginPrefs( 327 void UserSessionManager::SetFirstLoginPrefs(
332 PrefService* prefs, 328 PrefService* prefs,
333 const std::string& public_session_locale, 329 const std::string& public_session_locale,
334 const std::string& public_session_input_method) { 330 const std::string& public_session_input_method) {
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 FinalizePrepareProfile(profile); 729 FinalizePrepareProfile(profile);
734 } 730 }
735 731
736 void UserSessionManager::FinalizePrepareProfile(Profile* profile) { 732 void UserSessionManager::FinalizePrepareProfile(Profile* profile) {
737 BootTimesLoader* btl = BootTimesLoader::Get(); 733 BootTimesLoader* btl = BootTimesLoader::Get();
738 734
739 // Own TPM device if, for any reason, it has not been done in EULA screen. 735 // Own TPM device if, for any reason, it has not been done in EULA screen.
740 CryptohomeClient* client = DBusThreadManager::Get()->GetCryptohomeClient(); 736 CryptohomeClient* client = DBusThreadManager::Get()->GetCryptohomeClient();
741 btl->AddLoginTimeMarker("TPMOwn-Start", false); 737 btl->AddLoginTimeMarker("TPMOwn-Start", false);
742 if (cryptohome_util::TpmIsEnabled() && !cryptohome_util::TpmIsBeingOwned()) { 738 if (cryptohome_util::TpmIsEnabled() && !cryptohome_util::TpmIsBeingOwned()) {
743 if (cryptohome_util::TpmIsOwned()) { 739 if (cryptohome_util::TpmIsOwned())
744 client->CallTpmClearStoredPasswordAndBlock(); 740 client->CallTpmClearStoredPasswordAndBlock();
745 } else { 741 else
746 client->TpmCanAttemptOwnership(EmptyVoidDBusMethodCallback()); 742 client->TpmCanAttemptOwnership(EmptyVoidDBusMethodCallback());
747 }
748 } 743 }
749 btl->AddLoginTimeMarker("TPMOwn-End", false); 744 btl->AddLoginTimeMarker("TPMOwn-End", false);
750 745
751 UserManager* user_manager = UserManager::Get(); 746 UserManager* user_manager = UserManager::Get();
752 if (user_manager->IsLoggedInAsRegularUser()) { 747 if (user_manager->IsLoggedInAsRegularUser()) {
753 SAMLOfflineSigninLimiter* saml_offline_signin_limiter = 748 SAMLOfflineSigninLimiter* saml_offline_signin_limiter =
754 SAMLOfflineSigninLimiterFactory::GetForProfile(profile); 749 SAMLOfflineSigninLimiterFactory::GetForProfile(profile);
755 if (saml_offline_signin_limiter) 750 if (saml_offline_signin_limiter)
756 saml_offline_signin_limiter->SignedIn(user_context_.GetAuthFlow()); 751 saml_offline_signin_limiter->SignedIn(user_context_.GetAuthFlow());
757 } 752 }
758 753
759 profile->OnLogin(); 754 profile->OnLogin();
760 755
761 g_browser_process->platform_part()->SessionManager()->SetSessionState( 756 g_browser_process->platform_part()->SessionManager()->SetSessionState(
762 session_manager::SESSION_STATE_LOGGED_IN_NOT_ACTIVE); 757 session_manager::SESSION_STATE_LOGGED_IN_NOT_ACTIVE);
763 758
764 // Send the notification before creating the browser so additional objects 759 // Send the notification before creating the browser so additional objects
765 // that need the profile (e.g. the launcher) can be created first. 760 // that need the profile (e.g. the launcher) can be created first.
766 content::NotificationService::current()->Notify( 761 content::NotificationService::current()->Notify(
767 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 762 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
768 content::NotificationService::AllSources(), 763 content::NotificationService::AllSources(),
769 content::Details<Profile>(profile)); 764 content::Details<Profile>(profile));
770 765
771 InitializeCertsForPrimaryUser(profile); 766 // Initialize various services only for primary user.
772
773 // Initialize RLZ only for primary user.
774 const user_manager::User* user = 767 const user_manager::User* user =
775 ProfileHelper::Get()->GetUserByProfile(profile); 768 ProfileHelper::Get()->GetUserByProfile(profile);
776 if (user_manager->GetPrimaryUser() == user) 769 if (user_manager->GetPrimaryUser() == user) {
777 InitRlz(profile); 770 InitRlz(profile);
771 InitializeCerts(profile);
772 InitializeCRLSetFetcher(user);
773 }
778 774
779 // TODO(altimofeev): This pointer should probably never be NULL, but it looks 775 // TODO(nkostylev): This pointer should probably never be NULL, but it looks
780 // like LoginUtilsImpl::OnProfileCreated() may be getting called before 776 // like LoginUtilsImpl::OnProfileCreated() may be getting called before
781 // UserSessionManager::PrepareProfile() has set |delegate_| when Chrome is 777 // UserSessionManager::PrepareProfile() has set |delegate_| when Chrome is
782 // killed during shutdown in tests -- see http://crosbug.com/18269. Replace 778 // killed during shutdown in tests -- see http://crosbug.com/18269. Replace
783 // this 'if' statement with a CHECK(delegate_) once the underlying issue is 779 // this 'if' statement with a CHECK(delegate_) once the underlying issue is
784 // resolved. 780 // resolved.
785 if (delegate_) 781 if (delegate_)
786 delegate_->OnProfilePrepared(profile); 782 delegate_->OnProfilePrepared(profile);
787 } 783 }
788 784
789 void UserSessionManager::InitSessionRestoreStrategy() { 785 void UserSessionManager::InitSessionRestoreStrategy() {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 // Negative ping delay means to send ping immediately after a first search is 867 // Negative ping delay means to send ping immediately after a first search is
872 // recorded. 868 // recorded.
873 RLZTracker::InitRlzFromProfileDelayed( 869 RLZTracker::InitRlzFromProfileDelayed(
874 profile, UserManager::Get()->IsCurrentUserNew(), 870 profile, UserManager::Get()->IsCurrentUserNew(),
875 ping_delay < 0, base::TimeDelta::FromMilliseconds(abs(ping_delay))); 871 ping_delay < 0, base::TimeDelta::FromMilliseconds(abs(ping_delay)));
876 if (delegate_) 872 if (delegate_)
877 delegate_->OnRlzInitialized(); 873 delegate_->OnRlzInitialized();
878 #endif 874 #endif
879 } 875 }
880 876
881 void UserSessionManager::InitializeCertsForPrimaryUser(Profile* profile) { 877 void UserSessionManager::InitializeCerts(Profile* profile) {
882 // Now that the user profile has been initialized 878 // Now that the user profile has been initialized
883 // |GetNSSCertDatabaseForProfile| is safe to be used. 879 // |GetNSSCertDatabaseForProfile| is safe to be used.
884 UserManager* user_manager = UserManager::Get(); 880 if (CertLoader::IsInitialized() && base::SysInfo::IsRunningOnChromeOS()) {
885 const user_manager::User* primary_user = user_manager->GetPrimaryUser();
886 if (user_manager->IsUserLoggedIn() &&
887 primary_user &&
888 profile == ProfileHelper::Get()->GetProfileByUser(primary_user) &&
889 CertLoader::IsInitialized() &&
890 base::SysInfo::IsRunningOnChromeOS()) {
891 GetNSSCertDatabaseForProfile(profile, 881 GetNSSCertDatabaseForProfile(profile,
892 base::Bind(&OnGetNSSCertDatabaseForUser)); 882 base::Bind(&OnGetNSSCertDatabaseForUser));
893 } 883 }
894 } 884 }
895 885
886 void UserSessionManager::InitializeCRLSetFetcher(
887 const user_manager::User* user) {
888 const std::string username_hash = user->username_hash();
889 if (!username_hash.empty()) {
890 base::FilePath path;
891 path = ProfileHelper::GetProfilePathByUserIdHash(username_hash);
892 component_updater::ComponentUpdateService* cus =
893 g_browser_process->component_updater();
894 CRLSetFetcher* crl_set = g_browser_process->crl_set_fetcher();
895 if (crl_set && cus)
896 crl_set->StartInitialLoad(cus, path);
897 }
898 }
899
896 void UserSessionManager::OnRestoreActiveSessions( 900 void UserSessionManager::OnRestoreActiveSessions(
897 const SessionManagerClient::ActiveSessionsMap& sessions, 901 const SessionManagerClient::ActiveSessionsMap& sessions,
898 bool success) { 902 bool success) {
899 if (!success) { 903 if (!success) {
900 LOG(ERROR) << "Could not get list of active user sessions after crash."; 904 LOG(ERROR) << "Could not get list of active user sessions after crash.";
901 // If we could not get list of active user sessions it is safer to just 905 // If we could not get list of active user sessions it is safer to just
902 // sign out so that we don't get in the inconsistent state. 906 // sign out so that we don't get in the inconsistent state.
903 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession(); 907 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession();
904 return; 908 return;
905 } 909 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 971
968 void UserSessionManager::NotifyPendingUserSessionsRestoreFinished() { 972 void UserSessionManager::NotifyPendingUserSessionsRestoreFinished() {
969 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 973 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
970 user_sessions_restored_ = true; 974 user_sessions_restored_ = true;
971 FOR_EACH_OBSERVER(UserSessionStateObserver, 975 FOR_EACH_OBSERVER(UserSessionStateObserver,
972 session_state_observer_list_, 976 session_state_observer_list_,
973 PendingUserSessionsRestoreFinished()); 977 PendingUserSessionsRestoreFinished());
974 } 978 }
975 979
976 } // namespace chromeos 980 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698