Home | History | Annotate | Download | only in multi_user
      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_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
     18 
     19 namespace {
     20 chrome::MultiUserWindowManager* g_instance = NULL;
     21 }  // namespace
     22 
     23 namespace chrome {
     24 
     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;
     30 
     31 // static
     32 MultiUserWindowManager* MultiUserWindowManager::GetInstance() {
     33   return g_instance;
     34 }
     35 
     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       !ash::switches::UseFullMultiProfileMode()) {
     45     g_instance = new MultiUserWindowManagerChromeOS(
     46         ash::Shell::GetInstance()->session_state_delegate()->GetUserID(0));
     47     multi_user_mode_ = MULTI_PROFILE_MODE_SEPARATED;
     48     mode = ash::MultiProfileUMA::SESSION_SEPARATE_DESKTOP_MODE;
     49   } else if (ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) {
     50     // The side by side mode is using the Single user window manager since all
     51     // windows are unmanaged side by side.
     52     multi_user_mode_ = MULTI_PROFILE_MODE_MIXED;
     53     mode = ash::MultiProfileUMA::SESSION_SIDE_BY_SIDE_MODE;
     54   }
     55   ash::MultiProfileUMA::RecordSessionMode(mode);
     56 #endif
     57   // If there was no instance created yet we create a dummy instance.
     58   if (!g_instance)
     59     g_instance = new MultiUserWindowManagerStub();
     60 
     61   return g_instance;
     62 }
     63 
     64 // static
     65 MultiUserWindowManager::MultiProfileMode
     66 MultiUserWindowManager::GetMultiProfileMode() {
     67   return multi_user_mode_;
     68 }
     69 
     70 // static
     71 void MultiUserWindowManager::DeleteInstance() {
     72   DCHECK(g_instance);
     73   delete g_instance;
     74   g_instance = NULL;
     75   multi_user_mode_ = MULTI_PROFILE_MODE_UNINITIALIZED;
     76 }
     77 
     78 void MultiUserWindowManager::SetInstanceForTest(
     79     MultiUserWindowManager* instance,
     80     MultiProfileMode mode) {
     81   if (g_instance)
     82     DeleteInstance();
     83   g_instance = instance;
     84   multi_user_mode_ = mode;
     85 }
     86 
     87 }  // namespace chrome
     88