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.
5 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
7 #include "base/logging.h"
8 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_stub.h"
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/shell.h"
15 #include "ash/shell_delegate.h"
16 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
17 #include "components/user_manager/user_info.h"
21 chrome::MultiUserWindowManager
* g_instance
= NULL
;
26 // Caching the current multi profile mode to avoid expensive detection
28 chrome::MultiUserWindowManager::MultiProfileMode
29 chrome::MultiUserWindowManager::multi_user_mode_
=
30 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_UNINITIALIZED
;
33 MultiUserWindowManager
* MultiUserWindowManager::GetInstance() {
37 MultiUserWindowManager
* MultiUserWindowManager::CreateInstance() {
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
;
44 ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) {
45 MultiUserWindowManagerChromeOS
* manager
=
46 new MultiUserWindowManagerChromeOS(ash::Shell::GetInstance()
47 ->session_state_delegate()
52 multi_user_mode_
= MULTI_PROFILE_MODE_SEPARATED
;
53 mode
= ash::MultiProfileUMA::SESSION_SEPARATE_DESKTOP_MODE
;
54 } else if (ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) {
55 // The side by side mode is using the Single user window manager since all
56 // windows are unmanaged side by side.
57 multi_user_mode_
= MULTI_PROFILE_MODE_MIXED
;
58 mode
= ash::MultiProfileUMA::SESSION_SIDE_BY_SIDE_MODE
;
60 ash::MultiProfileUMA::RecordSessionMode(mode
);
62 // If there was no instance created yet we create a dummy instance.
64 g_instance
= new MultiUserWindowManagerStub();
70 MultiUserWindowManager::MultiProfileMode
71 MultiUserWindowManager::GetMultiProfileMode() {
72 return multi_user_mode_
;
76 bool MultiUserWindowManager::ShouldShowAvatar(aura::Window
* window
) {
77 // Note: In case of the M-31 mode the window manager won't exist.
78 if (GetMultiProfileMode() == MULTI_PROFILE_MODE_SEPARATED
) {
79 // If the window is shown on a different desktop than the user, it should
80 // have the avatar icon
81 MultiUserWindowManager
* instance
= GetInstance();
82 return !instance
->IsWindowOnDesktopOfUser(window
,
83 instance
->GetWindowOwner(window
));
89 void MultiUserWindowManager::DeleteInstance() {
93 multi_user_mode_
= MULTI_PROFILE_MODE_UNINITIALIZED
;
96 void MultiUserWindowManager::SetInstanceForTest(
97 MultiUserWindowManager
* instance
,
98 MultiProfileMode mode
) {
101 g_instance
= instance
;
102 multi_user_mode_
= mode
;
105 } // namespace chrome