Chromium Code Reviews| 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 <algorithm> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "components/user_manager/user_manager.h" | |
| 9 | 12 |
| 10 namespace session_manager { | 13 namespace session_manager { |
| 11 | 14 |
| 12 // static | 15 // static |
| 13 SessionManager* SessionManager::instance = NULL; | 16 SessionManager* SessionManager::instance = nullptr; |
| 14 | 17 |
| 15 SessionManager::SessionManager() { | 18 SessionManager::SessionManager() { |
| 16 DCHECK(!SessionManager::Get()); | 19 DCHECK(!SessionManager::Get()); |
| 17 SessionManager::SetInstance(this); | 20 SessionManager::SetInstance(this); |
| 18 } | 21 } |
| 19 | 22 |
| 20 SessionManager::~SessionManager() { | 23 SessionManager::~SessionManager() { |
| 21 DCHECK(instance == this); | 24 DCHECK_EQ(instance, this); |
| 22 SessionManager::SetInstance(NULL); | 25 SessionManager::SetInstance(nullptr); |
| 23 } | 26 } |
| 24 | 27 |
| 25 // static | 28 // static |
| 26 SessionManager* SessionManager::Get() { | 29 SessionManager* SessionManager::Get() { |
| 27 return SessionManager::instance; | 30 return SessionManager::instance; |
| 28 } | 31 } |
| 29 | 32 |
| 30 void SessionManager::SetSessionState(SessionState state) { | 33 void SessionManager::SetSessionState(SessionState state) { |
| 31 VLOG(1) << "Changing session state to: " << static_cast<int>(state); | 34 VLOG(1) << "Changing session state to: " << static_cast<int>(state); |
| 32 | 35 |
| 33 if (session_state_ != state) { | 36 if (session_state_ != state) { |
| 34 // TODO(nkostylev): Notify observers about the state change. | 37 // TODO(nkostylev): Notify observers about the state change. |
| 35 // TODO(nkostylev): Add code to process session state change and probably | 38 // TODO(nkostylev): Add code to process session state change and probably |
| 36 // replace delegate_ if needed. | 39 // replace delegate_ if needed. |
| 37 session_state_ = state; | 40 session_state_ = state; |
| 38 } | 41 } |
| 39 } | 42 } |
| 40 | 43 |
| 44 void SessionManager::CreateSession(const AccountId& user_account_id, | |
| 45 const std::string& user_id_hash, | |
| 46 bool browser_restart) { | |
| 47 DCHECK(std::find_if(sessions_.begin(), sessions_.end(), | |
|
achuithb
2016/10/31 21:55:57
Nice
| |
| 48 [user_account_id](const Session& session) { | |
| 49 return session.user_account_id == user_account_id; | |
| 50 }) == sessions_.end()); | |
| 51 | |
| 52 sessions_.push_back({next_id_++, user_account_id}); | |
| 53 NotifyUserLoggedIn(user_account_id, user_id_hash, browser_restart); | |
| 54 } | |
| 55 | |
| 41 bool SessionManager::IsSessionStarted() const { | 56 bool SessionManager::IsSessionStarted() const { |
| 42 return session_started_; | 57 return session_started_; |
| 43 } | 58 } |
| 44 | 59 |
| 45 void SessionManager::SessionStarted() { | 60 void SessionManager::SessionStarted() { |
| 46 session_started_ = true; | 61 session_started_ = true; |
| 47 } | 62 } |
| 48 | 63 |
| 64 void SessionManager::NotifyUserLoggedIn(const AccountId& user_account_id, | |
| 65 const std::string& user_id_hash, | |
| 66 bool browser_restart) { | |
| 67 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | |
|
achuithb
2016/10/31 21:55:57
auto* may be fine here
xiyuan
2016/10/31 22:29:45
Done.
| |
| 68 if (!user_manager) | |
| 69 return; | |
| 70 user_manager->UserLoggedIn(user_account_id, user_id_hash, browser_restart); | |
| 71 } | |
| 72 | |
| 49 // static | 73 // static |
| 50 void SessionManager::SetInstance(SessionManager* session_manager) { | 74 void SessionManager::SetInstance(SessionManager* session_manager) { |
| 51 SessionManager::instance = session_manager; | 75 SessionManager::instance = session_manager; |
| 52 } | 76 } |
| 53 | 77 |
| 54 } // namespace session_manager | 78 } // namespace session_manager |
| OLD | NEW |