Commit 59c5c0d1 authored by James Cook's avatar James Cook Committed by Commit Bot

cros: Eliminate MultiUserWindowManager::MultiUserMode

There's only one mode (split desktops). The uninitialized state isn't
needed anymore.  It was added a long time ago as an optimization to
avoid looking up flag values and those flags no longer exist.

Bug: none
Test: unit_tests, browser_tests, manually test teleporting windows between user sessions and verify avatar icons appear in the frames
Change-Id: Icc660ca2af047b39066ae501a5c6dc6a28f7aa8f
Reviewed-on: https://chromium-review.googlesource.com/687986Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505195}
parent cf78893d
......@@ -50,6 +50,7 @@
#include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#include "chrome/browser/ui/ash/session_controller_client.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
......@@ -231,8 +232,7 @@ ChromeLauncherController::ChromeLauncherController(Profile* profile,
// On Chrome OS using multi profile we want to switch the content of the shelf
// with a user change. Note that for unit tests the instance can be NULL.
if (chrome::MultiUserWindowManager::GetMultiProfileMode() !=
chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF) {
if (SessionControllerClient::IsMultiProfileAvailable()) {
user_switch_observer_.reset(
new ChromeLauncherControllerUserSwitchObserver(this));
}
......@@ -240,8 +240,7 @@ ChromeLauncherController::ChromeLauncherController(Profile* profile,
std::unique_ptr<AppWindowLauncherController> extension_app_window_controller;
// Create our v1/v2 application / browser monitors which will inform the
// launcher of status changes.
if (chrome::MultiUserWindowManager::GetMultiProfileMode() ==
chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_ON) {
if (SessionControllerClient::IsMultiProfileAvailable()) {
// If running in separated destkop mode, we create the multi profile version
// of status monitor.
browser_status_monitor_.reset(new MultiProfileBrowserStatusMonitor(this));
......
......@@ -20,12 +20,6 @@ namespace {
MultiUserWindowManager* g_instance = nullptr;
} // namespace
// Caching the current multi profile mode to avoid expensive detection
// operations.
MultiUserWindowManager::MultiProfileMode
MultiUserWindowManager::multi_user_mode_ =
MultiUserWindowManager::MULTI_PROFILE_MODE_UNINITIALIZED;
// static
MultiUserWindowManager* MultiUserWindowManager::GetInstance() {
return g_instance;
......@@ -33,7 +27,6 @@ MultiUserWindowManager* MultiUserWindowManager::GetInstance() {
MultiUserWindowManager* MultiUserWindowManager::CreateInstance() {
DCHECK(!g_instance);
multi_user_mode_ = MULTI_PROFILE_MODE_OFF;
ash::MultiProfileUMA::SessionMode mode =
ash::MultiProfileUMA::SESSION_SINGLE_USER_MODE;
// TODO(crbug.com/557406): Enable this component in Mash. The object itself
......@@ -45,7 +38,6 @@ MultiUserWindowManager* MultiUserWindowManager::CreateInstance() {
user_manager::UserManager::Get()->GetActiveUser()->GetAccountId());
g_instance = manager;
manager->Init();
multi_user_mode_ = MULTI_PROFILE_MODE_ON;
mode = ash::MultiProfileUMA::SESSION_SEPARATE_DESKTOP_MODE;
}
ash::MultiProfileUMA::RecordSessionMode(mode);
......@@ -57,31 +49,25 @@ MultiUserWindowManager* MultiUserWindowManager::CreateInstance() {
return g_instance;
}
// static
MultiUserWindowManager::MultiProfileMode
MultiUserWindowManager::GetMultiProfileMode() {
return multi_user_mode_;
}
// static
bool MultiUserWindowManager::ShouldShowAvatar(aura::Window* window) {
// Note: In case of the M-31 mode the window manager won't exist.
if (GetMultiProfileMode() == MULTI_PROFILE_MODE_ON) {
// If the window is shown on a different desktop than the user, it should
// have the avatar icon
MultiUserWindowManager* instance = GetInstance();
return !instance->IsWindowOnDesktopOfUser(window,
instance->GetWindowOwner(window));
}
return false;
// Session restore can open a window for the first user before the instance
// is created.
if (!g_instance)
return false;
// Show the avatar icon if the window is on a different desktop than the
// window's owner's desktop. The stub implementation does the right thing
// for single-user mode.
return !g_instance->IsWindowOnDesktopOfUser(
window, g_instance->GetWindowOwner(window));
}
// static
void MultiUserWindowManager::DeleteInstance() {
DCHECK(g_instance);
delete g_instance;
g_instance = NULL;
multi_user_mode_ = MULTI_PROFILE_MODE_UNINITIALIZED;
g_instance = nullptr;
}
void MultiUserWindowManager::SetInstanceForTest(
......@@ -89,7 +75,6 @@ void MultiUserWindowManager::SetInstanceForTest(
if (g_instance)
DeleteInstance();
g_instance = instance;
multi_user_mode_ = MULTI_PROFILE_MODE_ON;
}
} // namespace chrome
......@@ -56,13 +56,6 @@ class MultiUserWindowManager {
virtual ~Observer() {}
};
// The multi profile mode in use.
enum MultiProfileMode {
MULTI_PROFILE_MODE_UNINITIALIZED, // Not initialized yet.
MULTI_PROFILE_MODE_OFF, // Single user mode.
MULTI_PROFILE_MODE_ON, // Each user has their own desktop.
};
// Creates an instance of the MultiUserWindowManager.
// Note: This function might fail if due to the desired mode the
// MultiUserWindowManager is not required.
......@@ -72,11 +65,6 @@ class MultiUserWindowManager {
// this will return NULL.
static MultiUserWindowManager* GetInstance();
// Return the current multi profile mode operation. If CreateInstance was not
// yet called (or was already destroyed), MULTI_PROFILE_MODE_UNINITIALIZED
// will get returned.
static MultiProfileMode GetMultiProfileMode();
// Whether or not the window's title should show the avatar. On chromeos,
// this is true when the owner of the window is different from the owner of
// the desktop.
......@@ -139,10 +127,6 @@ class MultiUserWindowManager {
protected:
virtual ~MultiUserWindowManager() {}
private:
// Caching the current multi profile mode since the detection is expensive.
static MultiProfileMode multi_user_mode_;
};
} // namespace chrome
......
......@@ -529,23 +529,20 @@ bool MultiUserWindowManagerChromeOS::ShowWindowForUserIntern(
WindowToEntryMap::iterator it = window_to_entry_.find(window);
it->second->set_show_for_user(account_id);
// Show avatar icon on the teleported window.
if (GetMultiProfileMode() == MULTI_PROFILE_MODE_ON) {
// Tests could either not have a UserManager or the UserManager does not
// know the window owner.
const user_manager::User* const window_owner =
user_manager::UserManager::IsInitialized()
? user_manager::UserManager::Get()->FindUser(owner)
: nullptr;
const bool teleported = !IsWindowOnDesktopOfUser(window, owner);
if (window_owner && teleported) {
window->SetProperty(
aura::client::kAvatarIconKey,
new gfx::ImageSkia(GetAvatarImageForUser(window_owner)));
} else {
window->ClearProperty(aura::client::kAvatarIconKey);
}
// Tests could either not have a UserManager or the UserManager does not
// know the window owner.
const user_manager::User* const window_owner =
user_manager::UserManager::IsInitialized()
? user_manager::UserManager::Get()->FindUser(owner)
: nullptr;
const bool teleported = !IsWindowOnDesktopOfUser(window, owner);
if (window_owner && teleported) {
window->SetProperty(
aura::client::kAvatarIconKey,
new gfx::ImageSkia(GetAvatarImageForUser(window_owner)));
} else {
window->ClearProperty(aura::client::kAvatarIconKey);
}
// Show the window if the added user is the current one.
......
......@@ -229,6 +229,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNonClientFrameViewAshTest,
aura::Window* window = browser()->window()->GetNativeWindow();
EXPECT_FALSE(chrome::MultiUserWindowManager::ShouldShowAvatar(window));
EXPECT_FALSE(frame_view->profile_indicator_icon());
const AccountId current_account_id =
multi_user_util::GetAccountIdFromProfile(browser()->profile());
......
......@@ -144,9 +144,6 @@ void SystemMenuModelBuilder::AddFrameToggleItems(ui::SimpleMenuModel* model) {
void SystemMenuModelBuilder::AppendTeleportMenu(ui::SimpleMenuModel* model) {
#if defined(OS_CHROMEOS)
DCHECK(browser()->window());
if (chrome::MultiUserWindowManager::GetMultiProfileMode() !=
chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_ON)
return;
// Don't show the menu for incognito windows.
if (browser()->profile()->IsOffTheRecord())
......
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