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.
5 #include "components/session_manager/core/session_manager.h"
7 #include "base/logging.h"
9 #if defined(OS_CHROMEOS)
10 #include "base/command_line.h"
11 #include "base/sys_info.h"
12 #include "chromeos/chromeos_switches.h"
15 namespace session_manager
{
18 SessionManager
* SessionManager::instance
= NULL
;
20 SessionManager::SessionManager() : session_state_(SESSION_STATE_UNKNOWN
) {
21 DCHECK(!SessionManager::Get());
22 SessionManager::SetInstance(this);
25 SessionManager::~SessionManager() {
26 DCHECK(instance
== this);
27 SessionManager::SetInstance(NULL
);
31 SessionManager
* SessionManager::Get() {
32 return SessionManager::instance
;
35 void SessionManager::SetSessionState(SessionState state
) {
36 VLOG(1) << "Changing session state to: " << state
;
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
;
46 void SessionManager::Initialize(SessionManagerDelegate
* delegate
) {
48 delegate_
.reset(delegate
);
49 delegate_
->SetSessionManager(this);
53 void SessionManager::SetInstance(SessionManager
* session_manager
) {
54 SessionManager::instance
= session_manager
;
57 void SessionManager::Start() {
62 bool SessionManager::HasBrowserRestarted() {
63 #if defined(OS_CHROMEOS)
64 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
65 return base::SysInfo::IsRunningOnChromeOS() &&
66 command_line
->HasSwitch(chromeos::switches::kLoginUser
);
72 SessionManagerDelegate::SessionManagerDelegate() : session_manager_(NULL
) {
75 SessionManagerDelegate::~SessionManagerDelegate() {
78 void SessionManagerDelegate::SetSessionManager(
79 session_manager::SessionManager
* session_manager
) {
80 session_manager_
= session_manager
;
83 } // namespace session_manager