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

Side by Side 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 unified diff | Download patch
OLDNEW
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 CreateSessionInternal(user_account_id, user_id_hash,
47 false /* browser_restart */);
48 }
49
50 void SessionManager::CreateSessionForRestart(const AccountId& user_account_id,
51 const std::string& user_id_hash) {
52 CreateSessionInternal(user_account_id, user_id_hash,
53 true /* 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 auto* user_manager = user_manager::UserManager::Get();
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
78 void SessionManager::CreateSessionInternal(const AccountId& user_account_id,
79 const std::string& user_id_hash,
80 bool browser_restart) {
81 DCHECK(std::find_if(sessions_.begin(), sessions_.end(),
82 [user_account_id](const Session& session) {
83 return session.user_account_id == user_account_id;
84 }) == sessions_.end());
85
86 sessions_.push_back({next_id_++, user_account_id});
87 NotifyUserLoggedIn(user_account_id, user_id_hash, browser_restart);
88 }
89
54 } // namespace session_manager 90 } // namespace session_manager
OLDNEW
« 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