OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/session_manager/core/session_manager.h" | 5 #include "components/session_manager/core/session_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 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 |
9 namespace session_manager { | 15 namespace session_manager { |
10 | 16 |
| 17 // static |
| 18 SessionManager* SessionManager::instance = NULL; |
| 19 |
11 SessionManager::SessionManager() : session_state_(SESSION_STATE_UNKNOWN) { | 20 SessionManager::SessionManager() : session_state_(SESSION_STATE_UNKNOWN) { |
| 21 DCHECK(!SessionManager::Get()); |
| 22 SessionManager::SetInstance(this); |
12 } | 23 } |
13 | 24 |
14 SessionManager::~SessionManager() { | 25 SessionManager::~SessionManager() { |
| 26 DCHECK(instance == this); |
| 27 SessionManager::SetInstance(NULL); |
| 28 } |
| 29 |
| 30 // static |
| 31 SessionManager* SessionManager::Get() { |
| 32 return SessionManager::instance; |
15 } | 33 } |
16 | 34 |
17 void SessionManager::SetSessionState(SessionState state) { | 35 void SessionManager::SetSessionState(SessionState state) { |
18 VLOG(1) << "Changing session state to: " << state; | 36 VLOG(1) << "Changing session state to: " << state; |
19 | 37 |
20 if (session_state_ != state) { | 38 if (session_state_ != state) { |
21 // TODO(nkostylev): Notify observers about the state change. | 39 // TODO(nkostylev): Notify observers about the state change. |
22 // TODO(nkostylev): Add code to process session state change and probably | 40 // TODO(nkostylev): Add code to process session state change and probably |
23 // replace delegate_ if needed. | 41 // replace delegate_ if needed. |
24 session_state_ = state; | 42 session_state_ = state; |
25 } | 43 } |
26 } | 44 } |
27 | 45 |
28 void SessionManager::Initialize(SessionManagerDelegate* delegate) { | 46 void SessionManager::Initialize(SessionManagerDelegate* delegate) { |
29 DCHECK(delegate); | 47 DCHECK(delegate); |
30 delegate_.reset(delegate); | 48 delegate_.reset(delegate); |
31 delegate_->SetSessionManager(this); | 49 delegate_->SetSessionManager(this); |
32 } | 50 } |
33 | 51 |
| 52 // static |
| 53 void SessionManager::SetInstance(SessionManager* session_manager) { |
| 54 SessionManager::instance = session_manager; |
| 55 } |
| 56 |
34 void SessionManager::Start() { | 57 void SessionManager::Start() { |
35 delegate_->Start(); | 58 delegate_->Start(); |
36 } | 59 } |
37 | 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 |
38 SessionManagerDelegate::SessionManagerDelegate() : session_manager_(NULL) { | 72 SessionManagerDelegate::SessionManagerDelegate() : session_manager_(NULL) { |
39 } | 73 } |
40 | 74 |
41 SessionManagerDelegate::~SessionManagerDelegate() { | 75 SessionManagerDelegate::~SessionManagerDelegate() { |
42 } | 76 } |
43 | 77 |
44 void SessionManagerDelegate::SetSessionManager( | 78 void SessionManagerDelegate::SetSessionManager( |
45 session_manager::SessionManager* session_manager) { | 79 session_manager::SessionManager* session_manager) { |
46 session_manager_ = session_manager; | 80 session_manager_ = session_manager; |
47 } | 81 } |
48 | 82 |
49 } // namespace session_manager | 83 } // namespace session_manager |
OLD | NEW |