Commit b89c3d3c authored by Jason Lin's avatar Jason Lin Committed by Commit Bot

Init PluginVmManagerImpl when the primary session is started

Previously, we do some initialization in PluginVmManagerImpl when the
primary profile is prepared. The initialization steps are:

1) reset some permissions stored as prefs
2) kill plugin vm dispatcher if chrome has crashed

When a user with custom flags signs in, Chrome restarts itself,
which causes the initialization steps to be run twice, which is
unnecessary. What's worse, the first time they are run they don't "see"
the custom flags, but we will soon need to make step 1 to be conditioned
by a custom flag. Doing the initialization when the primary session
is started solves these problems.

Bug: b/167491603
Test: manually test that the initialization steps are still working
Change-Id: I91dbb002e1f9c24ea4cb090a89e8241716a358e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2503758Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Jason Lin <lxj@google.com>
Cr-Commit-Position: refs/heads/master@{#821994}
parent f5fbd827
...@@ -97,6 +97,9 @@ void UserSessionInitializer::OnUserProfileLoaded(const AccountId& account_id) { ...@@ -97,6 +97,9 @@ void UserSessionInitializer::OnUserProfileLoaded(const AccountId& account_id) {
user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile);
if (user_manager::UserManager::Get()->GetPrimaryUser() == user) { if (user_manager::UserManager::Get()->GetPrimaryUser() == user) {
DCHECK_EQ(primary_profile_, nullptr);
primary_profile_ = profile;
InitRlz(profile); InitRlz(profile);
InitializeCerts(profile); InitializeCerts(profile);
InitializeCRLSetFetcher(); InitializeCRLSetFetcher();
...@@ -186,11 +189,6 @@ void UserSessionInitializer::InitializePrimaryProfileServices( ...@@ -186,11 +189,6 @@ void UserSessionInitializer::InitializePrimaryProfileServices(
arc::ArcServiceLauncher::Get()->OnPrimaryUserProfilePrepared(profile); arc::ArcServiceLauncher::Get()->OnPrimaryUserProfilePrepared(profile);
plugin_vm::PluginVmManager* plugin_vm_manager =
plugin_vm::PluginVmManagerFactory::GetForProfile(profile);
if (plugin_vm_manager)
plugin_vm_manager->OnPrimaryUserProfilePrepared();
crostini::CrostiniManager* crostini_manager = crostini::CrostiniManager* crostini_manager =
crostini::CrostiniManager::GetForProfile(profile); crostini::CrostiniManager::GetForProfile(profile);
if (crostini_manager) if (crostini_manager)
...@@ -204,6 +202,17 @@ void UserSessionInitializer::InitializePrimaryProfileServices( ...@@ -204,6 +202,17 @@ void UserSessionInitializer::InitializePrimaryProfileServices(
g_browser_process->platform_part()->InitializePrimaryProfileServices(profile); g_browser_process->platform_part()->InitializePrimaryProfileServices(profile);
} }
void UserSessionInitializer::OnUserSessionStarted(bool is_primary_user) {
if (is_primary_user) {
DCHECK_NE(primary_profile_, nullptr);
plugin_vm::PluginVmManager* plugin_vm_manager =
plugin_vm::PluginVmManagerFactory::GetForProfile(primary_profile_);
if (plugin_vm_manager)
plugin_vm_manager->OnPrimaryUserSessionStarted();
}
}
void UserSessionInitializer::InitRlzImpl(Profile* profile, void UserSessionInitializer::InitRlzImpl(Profile* profile,
const RlzInitParams& params) { const RlzInitParams& params) {
#if BUILDFLAG(ENABLE_RLZ) #if BUILDFLAG(ENABLE_RLZ)
......
...@@ -43,6 +43,7 @@ class UserSessionInitializer : public session_manager::SessionManagerObserver { ...@@ -43,6 +43,7 @@ class UserSessionInitializer : public session_manager::SessionManagerObserver {
// session_manager::SessionManagerObserver: // session_manager::SessionManagerObserver:
void OnUserProfileLoaded(const AccountId& account_id) override; void OnUserProfileLoaded(const AccountId& account_id) override;
void OnUserSessionStarted(bool is_primary_user) override;
// Initialize child user profile services that depend on the policy. // Initialize child user profile services that depend on the policy.
void InitializeChildUserServices(Profile* profile); void InitializeChildUserServices(Profile* profile);
...@@ -73,6 +74,8 @@ class UserSessionInitializer : public session_manager::SessionManagerObserver { ...@@ -73,6 +74,8 @@ class UserSessionInitializer : public session_manager::SessionManagerObserver {
// Initializes RLZ. If `disabled` is true, RLZ pings are disabled. // Initializes RLZ. If `disabled` is true, RLZ pings are disabled.
void InitRlzImpl(Profile* profile, const RlzInitParams& params); void InitRlzImpl(Profile* profile, const RlzInitParams& params);
Profile* primary_profile_ = nullptr;
base::OnceClosure init_rlz_impl_closure_for_testing_; base::OnceClosure init_rlz_impl_closure_for_testing_;
// Clipboard html image generator for the primary user. // Clipboard html image generator for the primary user.
......
...@@ -19,7 +19,7 @@ class MockPluginVmManager : public PluginVmManager { ...@@ -19,7 +19,7 @@ class MockPluginVmManager : public PluginVmManager {
MockPluginVmManager(const MockPluginVmManager&) = delete; MockPluginVmManager(const MockPluginVmManager&) = delete;
MockPluginVmManager& operator=(const MockPluginVmManager&) = delete; MockPluginVmManager& operator=(const MockPluginVmManager&) = delete;
MOCK_METHOD(void, OnPrimaryUserProfilePrepared, (), ()); MOCK_METHOD(void, OnPrimaryUserSessionStarted, (), ());
MOCK_METHOD(void, LaunchPluginVm, (LaunchPluginVmCallback callback), ()); MOCK_METHOD(void, LaunchPluginVm, (LaunchPluginVmCallback callback), ());
MOCK_METHOD(void, RelaunchPluginVm, (), ()); MOCK_METHOD(void, RelaunchPluginVm, (), ());
MOCK_METHOD(void, StopPluginVm, (const std::string& name, bool force), ()); MOCK_METHOD(void, StopPluginVm, (const std::string& name, bool force), ());
......
...@@ -23,7 +23,7 @@ class PluginVmManager : public KeyedService { ...@@ -23,7 +23,7 @@ class PluginVmManager : public KeyedService {
public: public:
using LaunchPluginVmCallback = base::OnceCallback<void(bool success)>; using LaunchPluginVmCallback = base::OnceCallback<void(bool success)>;
virtual void OnPrimaryUserProfilePrepared() = 0; virtual void OnPrimaryUserSessionStarted() = 0;
virtual void LaunchPluginVm(LaunchPluginVmCallback callback) = 0; virtual void LaunchPluginVm(LaunchPluginVmCallback callback) = 0;
virtual void RelaunchPluginVm() = 0; virtual void RelaunchPluginVm() = 0;
......
...@@ -114,7 +114,7 @@ PluginVmManagerImpl::~PluginVmManagerImpl() { ...@@ -114,7 +114,7 @@ PluginVmManagerImpl::~PluginVmManagerImpl() {
->RemoveObserver(this); ->RemoveObserver(this);
} }
void PluginVmManagerImpl::OnPrimaryUserProfilePrepared() { void PluginVmManagerImpl::OnPrimaryUserSessionStarted() {
vm_tools::plugin_dispatcher::ListVmRequest request; vm_tools::plugin_dispatcher::ListVmRequest request;
request.set_owner_id(owner_id_); request.set_owner_id(owner_id_);
request.set_vm_name_uuid(kPluginVmName); request.set_vm_name_uuid(kPluginVmName);
......
...@@ -48,7 +48,7 @@ class PluginVmManagerImpl ...@@ -48,7 +48,7 @@ class PluginVmManagerImpl
explicit PluginVmManagerImpl(Profile* profile); explicit PluginVmManagerImpl(Profile* profile);
~PluginVmManagerImpl() override; ~PluginVmManagerImpl() override;
void OnPrimaryUserProfilePrepared() override; void OnPrimaryUserSessionStarted() override;
// TODO(juwa): Don't allow launch/stop/uninstall to run simultaneously. // TODO(juwa): Don't allow launch/stop/uninstall to run simultaneously.
// |callback| is called either when VM tools are ready or if an error occurs. // |callback| is called either when VM tools are ready or if an error occurs.
......
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