Chromium Code Reviews| 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..98ce84a2ce48f4b9637e761959bce40b50cf2e52 |
| --- /dev/null |
| +++ b/chromeos/login/login_state.cc |
| @@ -0,0 +1,101 @@ |
| +// 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_; |
| +} |
| + |
| +bool LoginState::IsUserLoggedIn() const { |
| + LoggedInState logged_in_state = GetLoggedInState(); |
| + if (logged_in_state == LOGGED_IN_OOBE || logged_in_state == LOGGED_IN_NONE) |
|
Nikita (slow)
2013/04/10 08:09:22
nit: this could be now simplified to
return GetLo
stevenjb
2013/04/10 16:32:17
Done.
|
| + return false; |
| + return true; |
| +} |
| + |
| +LoginState::LoggedInUserType LoginState::GetLoggedInUserType() const { |
| + return logged_in_user_type_; |
| +} |
| + |
| +// 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 |