NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / ash / multi_user / multi_user_window_manager.cc
blobc30b5cc4789d2eb5417bd9baf3b40cb285441e58
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_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 #endif
19 namespace {
20 chrome::MultiUserWindowManager* g_instance = NULL;
21 } // namespace
23 namespace chrome {
25 // Caching the current multi profile mode to avoid expensive detection
26 // operations.
27 chrome::MultiUserWindowManager::MultiProfileMode
28 chrome::MultiUserWindowManager::multi_user_mode_ =
29 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_UNINITIALIZED;
31 // static
32 MultiUserWindowManager* MultiUserWindowManager::GetInstance() {
33 return g_instance;
36 MultiUserWindowManager* MultiUserWindowManager::CreateInstance() {
37 DCHECK(!g_instance);
38 multi_user_mode_ = MULTI_PROFILE_MODE_OFF;
39 #if defined(OS_CHROMEOS)
40 ash::MultiProfileUMA::SessionMode mode =
41 ash::MultiProfileUMA::SESSION_SINGLE_USER_MODE;
42 if (!g_instance &&
43 ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) {
44 g_instance = new MultiUserWindowManagerChromeOS(
45 ash::Shell::GetInstance()->session_state_delegate()->GetUserID(0));
46 multi_user_mode_ = MULTI_PROFILE_MODE_SEPARATED;
47 mode = ash::MultiProfileUMA::SESSION_SEPARATE_DESKTOP_MODE;
48 } else if (ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) {
49 // The side by side mode is using the Single user window manager since all
50 // windows are unmanaged side by side.
51 multi_user_mode_ = MULTI_PROFILE_MODE_MIXED;
52 mode = ash::MultiProfileUMA::SESSION_SIDE_BY_SIDE_MODE;
54 ash::MultiProfileUMA::RecordSessionMode(mode);
55 #endif
56 // If there was no instance created yet we create a dummy instance.
57 if (!g_instance)
58 g_instance = new MultiUserWindowManagerStub();
60 return g_instance;
63 // static
64 MultiUserWindowManager::MultiProfileMode
65 MultiUserWindowManager::GetMultiProfileMode() {
66 return multi_user_mode_;
69 // static
70 void MultiUserWindowManager::DeleteInstance() {
71 DCHECK(g_instance);
72 delete g_instance;
73 g_instance = NULL;
74 multi_user_mode_ = MULTI_PROFILE_MODE_UNINITIALIZED;
77 void MultiUserWindowManager::SetInstanceForTest(
78 MultiUserWindowManager* instance,
79 MultiProfileMode mode) {
80 if (g_instance)
81 DeleteInstance();
82 g_instance = instance;
83 multi_user_mode_ = mode;
86 } // namespace chrome