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