Commit eabe0a6d authored by Anqing Zhao's avatar Anqing Zhao Committed by Commit Bot

Extract several methods shared by two xx_session_manager

Following methods are extracted to remove duplicated code.
- InitializePrimaryProfileServices
- NotifyUserProfileLoaded
- StartTetherServiceIfPossible

Bug: 977489
Change-Id: Iad19b0e23f3d9e11273468890a5d21a2168ff2e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2030959
Commit-Queue: Anqing Zhao <anqing@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737657}
parent 7b296d06
......@@ -152,37 +152,13 @@ void StartUserSession(Profile* user_profile, const std::string& login_user_id) {
ProfileHelper::Get()->ProfileStartup(user_profile);
lock_screen_apps::StateController::Get()->SetPrimaryProfile(user_profile);
if (user->GetType() == user_manager::USER_TYPE_REGULAR) {
// App install logs are uploaded via the user's communication channel with
// the management server. This channel exists for regular users only.
// The |AppInstallEventLogManagerWrapper| manages its own lifetime and
// self-destructs on logout.
policy::AppInstallEventLogManagerWrapper::CreateForProfile(user_profile);
}
arc::ArcServiceLauncher::Get()->OnPrimaryUserProfilePrepared(user_profile);
crostini::CrostiniManager* crostini_manager =
crostini::CrostiniManager::GetForProfile(user_profile);
if (crostini_manager)
crostini_manager->MaybeUpgradeCrostini();
g_browser_process->platform_part()->InitializePrimaryProfileServices(
user_profile);
user_session_mgr->InitializePrimaryProfileServices(user_profile, user);
if (user->GetType() == user_manager::USER_TYPE_CHILD) {
user_session_mgr->InitializeChildUserServices(user_profile);
}
// Send the PROFILE_PREPARED notification and call SessionStarted()
// so that the Launcher and other Profile dependent classes are created.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources(),
content::Details<Profile>(user_profile));
session_manager::SessionManager::Get()->NotifyUserProfileLoaded(
ProfileHelper::Get()->GetUserByProfile(user_profile)->GetAccountId());
user_session_mgr->NotifyUserProfileLoaded(user_profile, user);
// This call will set session state to SESSION_STATE_ACTIVE (same one).
session_manager::SessionManager::Get()->SessionStarted();
......@@ -201,9 +177,8 @@ void StartUserSession(Profile* user_profile, const std::string& login_user_id) {
UserSessionManager::GetInstance()->RestoreAuthenticationSession(
user_profile);
TetherService* tether_service = TetherService::Get(user_profile);
if (tether_service)
tether_service->StartTetherIfPossible();
UserSessionManager::GetInstance()->StartTetherServiceIfPossible(
user_profile);
// Associates AppListClient with the current active profile.
AppListClientImpl::GetInstance()->UpdateProfile();
......
......@@ -1675,21 +1675,9 @@ void UserSessionManager::FinalizePrepareProfile(Profile* profile) {
profile->OnLogin();
// Send the notification before creating the browser so additional objects
// that need the profile (e.g. the launcher) can be created first.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources(),
content::Details<Profile>(profile));
// Initialize various services only for primary user.
// TODO(https://crbug.com/977489): There's a lot of code duplication with
// StartUserSession in chrome_session_manager.cc, which is (only!) run for
// session starts after crashes. This needs to be refactored.
const user_manager::User* user =
ProfileHelper::Get()->GetUserByProfile(profile);
session_manager::SessionManager::Get()->NotifyUserProfileLoaded(
user->GetAccountId());
NotifyUserProfileLoaded(profile, user);
// Initialize various services only for primary user.
if (user_manager->GetPrimaryUser() == user) {
......@@ -1697,28 +1685,8 @@ void UserSessionManager::FinalizePrepareProfile(Profile* profile) {
InitializeCerts(profile);
InitializeCRLSetFetcher(user);
InitializeCertificateTransparencyComponents(user);
lock_screen_apps::StateController::Get()->SetPrimaryProfile(profile);
if (user->GetType() == user_manager::USER_TYPE_REGULAR) {
// App install logs are uploaded via the user's communication channel with
// the management server. This channel exists for regular users only.
// The |AppInstallEventLogManagerWrapper| manages its own lifetime and
// self-destructs on logout.
policy::AppInstallEventLogManagerWrapper::CreateForProfile(profile);
}
arc::ArcServiceLauncher::Get()->OnPrimaryUserProfilePrepared(profile);
crostini::CrostiniManager* crostini_manager =
crostini::CrostiniManager::GetForProfile(profile);
if (crostini_manager)
crostini_manager->MaybeUpgradeCrostini();
g_browser_process->platform_part()->InitializePrimaryProfileServices(
profile);
TetherService* tether_service = TetherService::Get(profile);
if (tether_service)
tether_service->StartTetherIfPossible();
InitializePrimaryProfileServices(profile, user);
StartTetherServiceIfPossible(profile);
// PrefService is ready, check whether we need to force a VPN connection.
always_on_vpn_manager_ =
......@@ -2032,6 +2000,46 @@ void UserSessionManager::InitializeChildUserServices(Profile* profile) {
ScreenTimeControllerFactory::GetForBrowserContext(profile);
}
void UserSessionManager::InitializePrimaryProfileServices(
Profile* profile,
const user_manager::User* user) {
lock_screen_apps::StateController::Get()->SetPrimaryProfile(profile);
if (user->GetType() == user_manager::USER_TYPE_REGULAR) {
// App install logs are uploaded via the user's communication channel with
// the management server. This channel exists for regular users only.
// The |AppInstallEventLogManagerWrapper| manages its own lifetime and
// self-destructs on logout.
policy::AppInstallEventLogManagerWrapper::CreateForProfile(profile);
}
arc::ArcServiceLauncher::Get()->OnPrimaryUserProfilePrepared(profile);
crostini::CrostiniManager* crostini_manager =
crostini::CrostiniManager::GetForProfile(profile);
if (crostini_manager)
crostini_manager->MaybeUpgradeCrostini();
g_browser_process->platform_part()->InitializePrimaryProfileServices(profile);
}
void UserSessionManager::NotifyUserProfileLoaded(
Profile* profile,
const user_manager::User* user) {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources(),
content::Details<Profile>(profile));
session_manager::SessionManager::Get()->NotifyUserProfileLoaded(
user->GetAccountId());
}
void UserSessionManager::StartTetherServiceIfPossible(Profile* profile) {
TetherService* tether_service = TetherService::Get(profile);
if (tether_service)
tether_service->StartTetherIfPossible();
}
void UserSessionManager::OnRestoreActiveSessions(
base::Optional<SessionManagerClient::ActiveSessionsMap> sessions) {
if (!sessions.has_value()) {
......
......@@ -236,6 +236,18 @@ class UserSessionManager
// Initialize child user profile services that depend on the policy.
void InitializeChildUserServices(Profile* profile);
// Initialize all services that need the primary profile.
void InitializePrimaryProfileServices(Profile* profile,
const user_manager::User* user);
// Send the notification before creating the browser so additional objects
// that need the profile (e.g. the launcher) can be created first.
void NotifyUserProfileLoaded(Profile* profile,
const user_manager::User* user);
// Start the Tether service if it is ready.
void StartTetherServiceIfPossible(Profile* profile);
// Invoked when the user is logging in for the first time, or is logging in to
// an ephemeral session type, such as guest or a public session.
void SetFirstLoginPrefs(Profile* profile,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment