Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / ash / multi_user / multi_user_window_manager.cc
blob497ebe47cc6053192409ddf8c55a4e6fb528b66a
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"
18 #endif
20 namespace {
21 chrome::MultiUserWindowManager* g_instance = NULL;
22 } // namespace
24 namespace chrome {
26 // Caching the current multi profile mode to avoid expensive detection
27 // operations.
28 chrome::MultiUserWindowManager::MultiProfileMode
29 chrome::MultiUserWindowManager::multi_user_mode_ =
30 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_UNINITIALIZED;
32 // static
33 MultiUserWindowManager* MultiUserWindowManager::GetInstance() {
34 return g_instance;
37 MultiUserWindowManager* 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 MultiUserWindowManagerChromeOS* manager =
46 new MultiUserWindowManagerChromeOS(ash::Shell::GetInstance()
47 ->session_state_delegate()
48 ->GetUserInfo(0)
49 ->GetUserID());
50 g_instance = manager;
51 manager->Init();
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);
61 #endif
62 // If there was no instance created yet we create a dummy instance.
63 if (!g_instance)
64 g_instance = new MultiUserWindowManagerStub();
66 return g_instance;
69 // static
70 MultiUserWindowManager::MultiProfileMode
71 MultiUserWindowManager::GetMultiProfileMode() {
72 return multi_user_mode_;
75 // satic
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));
85 return false;
88 // static
89 void MultiUserWindowManager::DeleteInstance() {
90 DCHECK(g_instance);
91 delete g_instance;
92 g_instance = NULL;
93 multi_user_mode_ = MULTI_PROFILE_MODE_UNINITIALIZED;
96 void MultiUserWindowManager::SetInstanceForTest(
97 MultiUserWindowManager* instance,
98 MultiProfileMode mode) {
99 if (g_instance)
100 DeleteInstance();
101 g_instance = instance;
102 multi_user_mode_ = mode;
105 } // namespace chrome