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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/login/login_state.h ('k') | chromeos/login/login_state_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/login/login_state.cc
diff --git a/chromeos/login/login_state.cc b/chromeos/login/login_state.cc
new file mode 100644
index 0000000000000000000000000000000000000000..75fed89b851849a311cd6976b767e28e727fd1c0
--- /dev/null
+++ b/chromeos/login/login_state.cc
@@ -0,0 +1,105 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/login/login_state.h"
+
+#include "base/chromeos/chromeos_version.h"
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "chromeos/chromeos_switches.h"
+
+namespace chromeos {
+
+namespace {
+
+// When running a Chrome OS build outside of a device (i.e. on a developer's
+// workstation) and not running as login-manager, pretend like we're always
+// logged in.
+bool AlwaysLoggedIn() {
+ return !base::chromeos::IsRunningOnChromeOS() &&
+ !CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginManager);
+}
+
+} // namespace
+
+static LoginState* g_login_state = NULL;
+
+// static
+void LoginState::Initialize() {
+ CHECK(!g_login_state);
+ g_login_state = new LoginState();
+}
+
+// static
+void LoginState::Shutdown() {
+ CHECK(g_login_state);
+ delete g_login_state;
+ g_login_state = NULL;
+}
+
+// static
+LoginState* LoginState::Get() {
+ CHECK(g_login_state) << "LoginState::Get() called before Initialize()";
+ return g_login_state;
+}
+
+// static
+bool LoginState::IsInitialized() {
+ return g_login_state;
+}
+
+void LoginState::AddObserver(Observer* observer) {
+ observer_list_.AddObserver(observer);
+}
+
+void LoginState::RemoveObserver(Observer* observer) {
+ observer_list_.RemoveObserver(observer);
+}
+
+void LoginState::SetLoggedInState(LoggedInState state,
+ LoggedInUserType type) {
+ if (state == logged_in_state_)
+ return;
+ VLOG(1) << "LoggedInState: " << state << " UserType: " << type;
+ logged_in_state_ = state;
+ logged_in_user_type_ = type;
+ NotifyObservers();
+}
+
+LoginState::LoggedInState LoginState::GetLoggedInState() const {
+ if (AlwaysLoggedIn())
+ return LOGGED_IN_ACTIVE;
+ return logged_in_state_;
+}
+
+LoginState::LoggedInUserType LoginState::GetLoggedInUserType() const {
+ return logged_in_user_type_;
+}
+
+bool LoginState::IsUserLoggedIn() const {
+ return GetLoggedInState() == LOGGED_IN_ACTIVE;
+}
+
+bool LoginState::IsUserAuthenticated() const {
+ LoggedInUserType type = logged_in_user_type_;
+ return type == chromeos::LoginState::LOGGED_IN_USER_REGULAR ||
+ type == chromeos::LoginState::LOGGED_IN_USER_OWNER ||
+ type == chromeos::LoginState::LOGGED_IN_USER_LOCALLY_MANAGED;
+}
+
+// Private methods
+
+LoginState::LoginState() : logged_in_state_(LOGGED_IN_OOBE),
+ logged_in_user_type_(LOGGED_IN_USER_NONE) {
+}
+
+LoginState::~LoginState() {
+}
+
+void LoginState::NotifyObservers() {
+ FOR_EACH_OBSERVER(LoginState::Observer, observer_list_,
+ LoggedInStateChanged(GetLoggedInState()));
+}
+
+} // namespace chromeos
« 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