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

Side by Side Diff: components/session_manager/core/session_manager.cc

Issue 2468483002: session_manager: Tracks user sessions (Closed)
Patch Set: no default arg and other comments in #2 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 CreateSession(user_account_id, user_id_hash, false /* browser_restart */);
47 }
48
49 void SessionManager::CreateSession(const AccountId& user_account_id,
50 const std::string& user_id_hash,
51 bool browser_restart) {
52 DCHECK(std::find_if(sessions_.begin(), sessions_.end(),
53 [user_account_id](const Session& session) {
54 return session.user_account_id == user_account_id;
55 }) == sessions_.end());
56
57 sessions_.push_back({next_id_++, user_account_id});
58 NotifyUserLoggedIn(user_account_id, user_id_hash, browser_restart);
59 }
60
41 bool SessionManager::IsSessionStarted() const { 61 bool SessionManager::IsSessionStarted() const {
42 return session_started_; 62 return session_started_;
43 } 63 }
44 64
45 void SessionManager::SessionStarted() { 65 void SessionManager::SessionStarted() {
46 session_started_ = true; 66 session_started_ = true;
47 } 67 }
48 68
69 void SessionManager::NotifyUserLoggedIn(const AccountId& user_account_id,
70 const std::string& user_id_hash,
71 bool browser_restart) {
72 auto* user_manager = user_manager::UserManager::Get();
73 if (!user_manager)
74 return;
75 user_manager->UserLoggedIn(user_account_id, user_id_hash, browser_restart);
76 }
77
49 // static 78 // static
50 void SessionManager::SetInstance(SessionManager* session_manager) { 79 void SessionManager::SetInstance(SessionManager* session_manager) {
51 SessionManager::instance = session_manager; 80 SessionManager::instance = session_manager;
52 } 81 }
53 82
54 } // namespace session_manager 83 } // namespace session_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698