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