Commit 388e681b authored by skuhne's avatar skuhne Committed by Commit bot

Fixing crash upon window manager creation

BUG=452608
TEST=existing unit tests

Review URL: https://codereview.chromium.org/890293002

Cr-Commit-Position: refs/heads/master@{#314276}
parent e6e20775
......@@ -223,6 +223,7 @@ void WallpaperPrivateApiMultiUserUnittest::SetUpMultiUserWindowManager(
chrome::MultiUserWindowManager::MultiProfileMode mode) {
multi_user_window_manager_ =
new chrome::MultiUserWindowManagerChromeOS(active_user_id);
multi_user_window_manager_->Init();
chrome::MultiUserWindowManager::SetInstanceForTest(
multi_user_window_manager_, mode);
// We do not want animations while the test is going on.
......
......@@ -146,6 +146,7 @@ TEST_F(MessageCenterNotificationManagerTest, MultiUserUpdates) {
std::string active_user_id = multi_user_util::GetUserIDFromProfile(&profile);
chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager =
new chrome::MultiUserWindowManagerChromeOS(active_user_id);
multi_user_window_manager->Init();
chrome::MultiUserWindowManager::SetInstanceForTest(
multi_user_window_manager,
chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED);
......
......@@ -60,6 +60,7 @@ void MultiUserContextMenuChromeOSTest::SetUp() {
window_->Show();
multi_user_window_manager_ = new chrome::MultiUserWindowManagerChromeOS("A");
multi_user_window_manager_->Init();
chrome::MultiUserWindowManager::SetInstanceForTest(multi_user_window_manager_,
chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED);
EXPECT_TRUE(multi_user_window_manager_);
......
......@@ -42,11 +42,13 @@ MultiUserWindowManager* MultiUserWindowManager::CreateInstance() {
ash::MultiProfileUMA::SESSION_SINGLE_USER_MODE;
if (!g_instance &&
ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) {
g_instance =
MultiUserWindowManagerChromeOS* manager =
new MultiUserWindowManagerChromeOS(ash::Shell::GetInstance()
->session_state_delegate()
->GetUserInfo(0)
->GetUserID());
g_instance = manager;
manager->Init();
multi_user_mode_ = MULTI_PROFILE_MODE_SEPARATED;
mode = ash::MultiProfileUMA::SESSION_SEPARATE_DESKTOP_MODE;
} else if (ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) {
......
......@@ -215,20 +215,6 @@ MultiUserWindowManagerChromeOS::MultiUserWindowManagerChromeOS(
message_center::MessageCenter::Get(), current_user_id)),
suppress_visibility_changes_(false),
animation_speed_(ANIMATION_SPEED_NORMAL) {
// Add a session state observer to be able to monitor session changes.
if (ash::Shell::HasInstance())
ash::Shell::GetInstance()->session_state_delegate()->
AddSessionStateObserver(this);
// The BrowserListObserver would have been better to use then the old
// notification system, but that observer fires before the window got created.
registrar_.Add(this, NOTIFICATION_BROWSER_WINDOW_READY,
content::NotificationService::AllSources());
// Add an app window observer & all already running apps.
Profile* profile = multi_user_util::GetProfileFromUserID(current_user_id);
if (profile)
AddUser(profile);
}
MultiUserWindowManagerChromeOS::~MultiUserWindowManagerChromeOS() {
......@@ -264,6 +250,29 @@ MultiUserWindowManagerChromeOS::~MultiUserWindowManagerChromeOS() {
RemoveSessionStateObserver(this);
}
void MultiUserWindowManagerChromeOS::Init() {
// Since we are setting the SessionStateObserver and adding the user, this
// function should get called only once.
DCHECK(user_id_to_app_observer_.find(current_user_id_) ==
user_id_to_app_observer_.end());
// Add a session state observer to be able to monitor session changes.
if (ash::Shell::HasInstance()) {
ash::Shell::GetInstance()->session_state_delegate()->
AddSessionStateObserver(this);
}
// The BrowserListObserver would have been better to use then the old
// notification system, but that observer fires before the window got created.
registrar_.Add(this, NOTIFICATION_BROWSER_WINDOW_READY,
content::NotificationService::AllSources());
// Add an app window observer & all already running apps.
Profile* profile = multi_user_util::GetProfileFromUserID(current_user_id_);
if (profile)
AddUser(profile);
}
void MultiUserWindowManagerChromeOS::SetWindowOwner(
aura::Window* window,
const std::string& user_id) {
......
......@@ -72,6 +72,9 @@ class MultiUserWindowManagerChromeOS
explicit MultiUserWindowManagerChromeOS(const std::string& active_user_id);
~MultiUserWindowManagerChromeOS() override;
// Initializes the manager after its creation. Should only be called once.
void Init();
// MultiUserWindowManager overrides:
void SetWindowOwner(
aura::Window* window, const std::string& user_id) override;
......
......@@ -180,6 +180,7 @@ void MultiUserWindowManagerChromeOSTest::SetUpForThisManyWindows(int windows) {
window_[i]->Show();
}
multi_user_window_manager_ = new chrome::MultiUserWindowManagerChromeOS("A");
multi_user_window_manager_->Init();
multi_user_window_manager_->SetAnimationSpeedForTest(
chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED);
chrome::MultiUserWindowManager::SetInstanceForTest(multi_user_window_manager_,
......
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