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..564d5868a71e64adc28be50a87c225a9218ce707 |
--- /dev/null |
+++ b/chromeos/login/login_state.cc |
@@ -0,0 +1,88 @@ |
+// 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 "chromeos/dbus/dbus_thread_manager.h" |
+ |
+namespace chromeos { |
+ |
+static LoginState* g_login_state = NULL; |
+ |
+// static |
+void LoginState::Initialize() { |
+ CHECK(!g_login_state); |
bartfab (slow)
2013/04/03 08:21:36
#include "base/logging.h"
stevenjb
2013/04/03 17:21:42
Done.
|
+ 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; |
+} |
+ |
+void LoginState::AddObserver(Observer* observer) { |
+ observer_list_.AddObserver(observer); |
+} |
+ |
+void LoginState::RemoveObserver(Observer* observer) { |
+ observer_list_.RemoveObserver(observer); |
+} |
+ |
+void LoginState::SetLoginState(LoginState::State state) { |
+ if (state == state_) |
+ return; |
+ VLOG(1) << "Login State: " << state; |
+ state_ = state; |
+ NotifyObservers(); |
+} |
+ |
+LoginState::State LoginState::GetLoginState() const { |
+ if (screen_locked_) |
+ return LOGGED_IN_LOCKED; |
+ return state_; |
+} |
+ |
+bool LoginState::IsLoggedIn() { |
+ if (state_ == LOGGED_IN_OOBE || |
+ state_ == LOGGED_IN_NONE) { |
+ return false; |
+ } |
+ return true; |
+} |
+ |
+// Private methods |
+ |
+LoginState::LoginState() : state_(LOGGED_IN_OOBE), |
+ screen_locked_(false) { |
+ DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); |
+} |
+ |
+LoginState::~LoginState() { |
+ DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); |
+} |
+ |
+void LoginState::LockScreen() { |
+ screen_locked_ = true; |
+ NotifyObservers(); |
+} |
+ |
+void LoginState::UnlockScreen() { |
+ screen_locked_ = false; |
+ NotifyObservers(); |
+} |
+ |
+void LoginState::NotifyObservers() { |
+ FOR_EACH_OBSERVER(LoginState::Observer, observer_list_, |
+ LoginStateChanged(GetLoginState())); |
+} |
+ |
+} // namespace chromeos |