Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(581)

Unified Diff: components/session_manager/core/session_manager.cc

Issue 2468483002: session_manager: Tracks user sessions (Closed)
Patch Set: replace func overload with better names Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/session_manager/core/session_manager.cc
diff --git a/components/session_manager/core/session_manager.cc b/components/session_manager/core/session_manager.cc
index 3d2c4b5a40a2ee3c4065859e6925897290fed1ba..4d72c12f561bdb9cbbefa8e61d495435cf3807f2 100644
--- a/components/session_manager/core/session_manager.cc
+++ b/components/session_manager/core/session_manager.cc
@@ -4,13 +4,16 @@
#include "components/session_manager/core/session_manager.h"
+#include <algorithm>
+
#include "base/logging.h"
#include "build/build_config.h"
+#include "components/user_manager/user_manager.h"
namespace session_manager {
// static
-SessionManager* SessionManager::instance = NULL;
+SessionManager* SessionManager::instance = nullptr;
SessionManager::SessionManager() {
DCHECK(!SessionManager::Get());
@@ -18,8 +21,8 @@ SessionManager::SessionManager() {
}
SessionManager::~SessionManager() {
- DCHECK(instance == this);
- SessionManager::SetInstance(NULL);
+ DCHECK_EQ(instance, this);
+ SessionManager::SetInstance(nullptr);
}
// static
@@ -38,6 +41,18 @@ void SessionManager::SetSessionState(SessionState state) {
}
}
+void SessionManager::CreateSession(const AccountId& user_account_id,
+ const std::string& user_id_hash) {
+ CreateSessionInternal(user_account_id, user_id_hash,
+ false /* browser_restart */);
+}
+
+void SessionManager::CreateSessionForRestart(const AccountId& user_account_id,
+ const std::string& user_id_hash) {
+ CreateSessionInternal(user_account_id, user_id_hash,
+ true /* browser_restart */);
+}
+
bool SessionManager::IsSessionStarted() const {
return session_started_;
}
@@ -46,9 +61,30 @@ void SessionManager::SessionStarted() {
session_started_ = true;
}
+void SessionManager::NotifyUserLoggedIn(const AccountId& user_account_id,
+ const std::string& user_id_hash,
+ bool browser_restart) {
+ auto* user_manager = user_manager::UserManager::Get();
+ if (!user_manager)
+ return;
+ user_manager->UserLoggedIn(user_account_id, user_id_hash, browser_restart);
+}
+
// static
void SessionManager::SetInstance(SessionManager* session_manager) {
SessionManager::instance = session_manager;
}
+void SessionManager::CreateSessionInternal(const AccountId& user_account_id,
+ const std::string& user_id_hash,
+ bool browser_restart) {
+ DCHECK(std::find_if(sessions_.begin(), sessions_.end(),
+ [user_account_id](const Session& session) {
+ return session.user_account_id == user_account_id;
+ }) == sessions_.end());
+
+ sessions_.push_back({next_id_++, user_account_id});
+ NotifyUserLoggedIn(user_account_id, user_id_hash, browser_restart);
+}
+
} // namespace session_manager
« no previous file with comments | « components/session_manager/core/session_manager.h ('k') | components/session_manager/session_manager_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698