1 // Copyright 2014 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 "components/session_manager/core/session_manager.h" 6 7 #include "base/logging.h" 8 9 #if defined(OS_CHROMEOS) 10 #include "base/command_line.h" 11 #include "base/sys_info.h" 12 #include "chromeos/chromeos_switches.h" 13 #endif 14 15 namespace session_manager { 16 17 // static 18 SessionManager* SessionManager::instance = NULL; 19 20 SessionManager::SessionManager() : session_state_(SESSION_STATE_UNKNOWN) { 21 DCHECK(!SessionManager::Get()); 22 SessionManager::SetInstance(this); 23 } 24 25 SessionManager::~SessionManager() { 26 DCHECK(instance == this); 27 SessionManager::SetInstance(NULL); 28 } 29 30 // static 31 SessionManager* SessionManager::Get() { 32 return SessionManager::instance; 33 } 34 35 void SessionManager::SetSessionState(SessionState state) { 36 VLOG(1) << "Changing session state to: " << state; 37 38 if (session_state_ != state) { 39 // TODO(nkostylev): Notify observers about the state change. 40 // TODO(nkostylev): Add code to process session state change and probably 41 // replace delegate_ if needed. 42 session_state_ = state; 43 } 44 } 45 46 void SessionManager::Initialize(SessionManagerDelegate* delegate) { 47 DCHECK(delegate); 48 delegate_.reset(delegate); 49 delegate_->SetSessionManager(this); 50 } 51 52 // static 53 void SessionManager::SetInstance(SessionManager* session_manager) { 54 SessionManager::instance = session_manager; 55 } 56 57 void SessionManager::Start() { 58 delegate_->Start(); 59 } 60 61 // static 62 bool SessionManager::HasBrowserRestarted() { 63 #if defined(OS_CHROMEOS) 64 CommandLine* command_line = CommandLine::ForCurrentProcess(); 65 return base::SysInfo::IsRunningOnChromeOS() && 66 command_line->HasSwitch(chromeos::switches::kLoginUser); 67 #else 68 return false; 69 #endif 70 } 71 72 SessionManagerDelegate::SessionManagerDelegate() : session_manager_(NULL) { 73 } 74 75 SessionManagerDelegate::~SessionManagerDelegate() { 76 } 77 78 void SessionManagerDelegate::SetSessionManager( 79 session_manager::SessionManager* session_manager) { 80 session_manager_ = session_manager; 81 } 82 83 } // namespace session_manager 84