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

Side by Side Diff: chromeos/login/login_state.cc

Issue 13495003: Add LoginState class to src/chromeos/login (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « chromeos/login/login_state.h ('k') | chromeos/login/login_state_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chromeos/login/login_state.h"
6
7 #include "base/chromeos/chromeos_version.h"
8 #include "base/command_line.h"
9 #include "base/logging.h"
10 #include "chromeos/chromeos_switches.h"
11
12 namespace chromeos {
13
14 namespace {
15
16 // When running a Chrome OS build outside of a device (i.e. on a developer's
17 // workstation) and not running as login-manager, pretend like we're always
18 // logged in.
19 bool AlwaysLoggedIn() {
20 return !base::chromeos::IsRunningOnChromeOS() &&
21 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginManager);
22 }
23
24 } // namespace
25
26 static LoginState* g_login_state = NULL;
27
28 // static
29 void LoginState::Initialize() {
30 CHECK(!g_login_state);
31 g_login_state = new LoginState();
32 }
33
34 // static
35 void LoginState::Shutdown() {
36 CHECK(g_login_state);
37 delete g_login_state;
38 g_login_state = NULL;
39 }
40
41 // static
42 LoginState* LoginState::Get() {
43 CHECK(g_login_state) << "LoginState::Get() called before Initialize()";
44 return g_login_state;
45 }
46
47 // static
48 bool LoginState::IsInitialized() {
49 return g_login_state;
50 }
51
52 void LoginState::AddObserver(Observer* observer) {
53 observer_list_.AddObserver(observer);
54 }
55
56 void LoginState::RemoveObserver(Observer* observer) {
57 observer_list_.RemoveObserver(observer);
58 }
59
60 void LoginState::SetLoggedInState(LoggedInState state,
61 LoggedInUserType type) {
62 if (state == logged_in_state_)
63 return;
64 VLOG(1) << "LoggedInState: " << state << " UserType: " << type;
65 logged_in_state_ = state;
66 logged_in_user_type_ = type;
67 NotifyObservers();
68 }
69
70 LoginState::LoggedInState LoginState::GetLoggedInState() const {
71 if (AlwaysLoggedIn())
72 return LOGGED_IN_ACTIVE;
73 return logged_in_state_;
74 }
75
76 LoginState::LoggedInUserType LoginState::GetLoggedInUserType() const {
77 return logged_in_user_type_;
78 }
79
80 bool LoginState::IsUserLoggedIn() const {
81 return GetLoggedInState() == LOGGED_IN_ACTIVE;
82 }
83
84 bool LoginState::IsUserAuthenticated() const {
85 LoggedInUserType type = logged_in_user_type_;
86 return type == chromeos::LoginState::LOGGED_IN_USER_REGULAR ||
87 type == chromeos::LoginState::LOGGED_IN_USER_OWNER ||
88 type == chromeos::LoginState::LOGGED_IN_USER_LOCALLY_MANAGED;
89 }
90
91 // Private methods
92
93 LoginState::LoginState() : logged_in_state_(LOGGED_IN_OOBE),
94 logged_in_user_type_(LOGGED_IN_USER_NONE) {
95 }
96
97 LoginState::~LoginState() {
98 }
99
100 void LoginState::NotifyObservers() {
101 FOR_EACH_OBSERVER(LoginState::Observer, observer_list_,
102 LoggedInStateChanged(GetLoggedInState()));
103 }
104
105 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/login/login_state.h ('k') | chromeos/login/login_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698