multi_user_window_manager.cc revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 6 7#include "base/logging.h" 8#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_stub.h" 9 10#if defined(OS_CHROMEOS) 11#include "ash/ash_switches.h" 12#include "ash/multi_profile_uma.h" 13#include "ash/session/session_state_delegate.h" 14#include "ash/session/user_info.h" 15#include "ash/shell.h" 16#include "ash/shell_delegate.h" 17#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" 18#endif 19 20namespace { 21chrome::MultiUserWindowManager* g_instance = NULL; 22} // namespace 23 24namespace chrome { 25 26// Caching the current multi profile mode to avoid expensive detection 27// operations. 28chrome::MultiUserWindowManager::MultiProfileMode 29 chrome::MultiUserWindowManager::multi_user_mode_ = 30 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_UNINITIALIZED; 31 32// static 33MultiUserWindowManager* MultiUserWindowManager::GetInstance() { 34 return g_instance; 35} 36 37MultiUserWindowManager* MultiUserWindowManager::CreateInstance() { 38 DCHECK(!g_instance); 39 multi_user_mode_ = MULTI_PROFILE_MODE_OFF; 40#if defined(OS_CHROMEOS) 41 ash::MultiProfileUMA::SessionMode mode = 42 ash::MultiProfileUMA::SESSION_SINGLE_USER_MODE; 43 if (!g_instance && 44 ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) { 45 g_instance = 46 new MultiUserWindowManagerChromeOS(ash::Shell::GetInstance() 47 ->session_state_delegate() 48 ->GetUserInfo(0) 49 ->GetUserID()); 50 multi_user_mode_ = MULTI_PROFILE_MODE_SEPARATED; 51 mode = ash::MultiProfileUMA::SESSION_SEPARATE_DESKTOP_MODE; 52 } else if (ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) { 53 // The side by side mode is using the Single user window manager since all 54 // windows are unmanaged side by side. 55 multi_user_mode_ = MULTI_PROFILE_MODE_MIXED; 56 mode = ash::MultiProfileUMA::SESSION_SIDE_BY_SIDE_MODE; 57 } 58 ash::MultiProfileUMA::RecordSessionMode(mode); 59#endif 60 // If there was no instance created yet we create a dummy instance. 61 if (!g_instance) 62 g_instance = new MultiUserWindowManagerStub(); 63 64 return g_instance; 65} 66 67// static 68MultiUserWindowManager::MultiProfileMode 69MultiUserWindowManager::GetMultiProfileMode() { 70 return multi_user_mode_; 71} 72 73// satic 74bool MultiUserWindowManager::ShouldShowAvatar(aura::Window* window) { 75 // Note: In case of the M-31 mode the window manager won't exist. 76 if (GetMultiProfileMode() == MULTI_PROFILE_MODE_SEPARATED) { 77 // If the window is shown on a different desktop than the user, it should 78 // have the avatar icon 79 MultiUserWindowManager* instance = GetInstance(); 80 return !instance->IsWindowOnDesktopOfUser(window, 81 instance->GetWindowOwner(window)); 82 } 83 return false; 84} 85 86// static 87void MultiUserWindowManager::DeleteInstance() { 88 DCHECK(g_instance); 89 delete g_instance; 90 g_instance = NULL; 91 multi_user_mode_ = MULTI_PROFILE_MODE_UNINITIALIZED; 92} 93 94void MultiUserWindowManager::SetInstanceForTest( 95 MultiUserWindowManager* instance, 96 MultiProfileMode mode) { 97 if (g_instance) 98 DeleteInstance(); 99 g_instance = instance; 100 multi_user_mode_ = mode; 101} 102 103} // namespace chrome 104