Remove WebKitTestRunner::setClientWindowRect.
[chromium-blink-merge.git] / chromeos / login / login_state.cc
bloba1f1fbbc30d4963f1b1240c264047e0f67b54b9f
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.
5 #include "chromeos/login/login_state.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/sys_info.h"
10 #include "chromeos/chromeos_switches.h"
12 namespace chromeos {
14 namespace {
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::SysInfo::IsRunningOnChromeOS() &&
21 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginManager);
24 } // namespace
26 static LoginState* g_login_state = NULL;
28 // static
29 void LoginState::Initialize() {
30 CHECK(!g_login_state);
31 g_login_state = new LoginState();
34 // static
35 void LoginState::Shutdown() {
36 CHECK(g_login_state);
37 delete g_login_state;
38 g_login_state = NULL;
41 // static
42 LoginState* LoginState::Get() {
43 CHECK(g_login_state) << "LoginState::Get() called before Initialize()";
44 return g_login_state;
47 // static
48 bool LoginState::IsInitialized() {
49 return g_login_state;
52 void LoginState::AddObserver(Observer* observer) {
53 observer_list_.AddObserver(observer);
56 void LoginState::RemoveObserver(Observer* observer) {
57 observer_list_.RemoveObserver(observer);
60 void LoginState::SetLoggedInState(LoggedInState state,
61 LoggedInUserType type) {
62 if (state == logged_in_state_ && type == logged_in_user_type_)
63 return;
64 VLOG(1) << "LoggedInState: " << state << " UserType: " << type;
65 logged_in_state_ = state;
66 logged_in_user_type_ = type;
67 NotifyObservers();
70 LoginState::LoggedInUserType LoginState::GetLoggedInUserType() const {
71 return logged_in_user_type_;
74 bool LoginState::IsUserLoggedIn() const {
75 if (AlwaysLoggedIn())
76 return true;
77 return logged_in_state_ == LOGGED_IN_ACTIVE;
80 bool LoginState::IsInSafeMode() const {
81 DCHECK(!AlwaysLoggedIn() || logged_in_state_ != LOGGED_IN_SAFE_MODE);
82 return logged_in_state_ == LOGGED_IN_SAFE_MODE;
85 bool LoginState::IsGuestUser() const {
86 if (!IsUserLoggedIn())
87 return false;
88 switch (logged_in_user_type_) {
89 case LOGGED_IN_USER_NONE:
90 case LOGGED_IN_USER_REGULAR:
91 case LOGGED_IN_USER_OWNER:
92 case LOGGED_IN_USER_LOCALLY_MANAGED:
93 case LOGGED_IN_USER_KIOSK_APP:
94 return false;
95 case LOGGED_IN_USER_GUEST:
96 case LOGGED_IN_USER_RETAIL_MODE:
97 case LOGGED_IN_USER_PUBLIC_ACCOUNT:
98 return true;
100 NOTREACHED();
101 return false;
104 bool LoginState::IsUserAuthenticated() const {
105 LoggedInUserType type = logged_in_user_type_;
106 return type == chromeos::LoginState::LOGGED_IN_USER_REGULAR ||
107 type == chromeos::LoginState::LOGGED_IN_USER_OWNER ||
108 type == chromeos::LoginState::LOGGED_IN_USER_LOCALLY_MANAGED;
111 bool LoginState::IsUserGaiaAuthenticated() const {
112 LoggedInUserType type = logged_in_user_type_;
113 return type == chromeos::LoginState::LOGGED_IN_USER_REGULAR ||
114 type == chromeos::LoginState::LOGGED_IN_USER_OWNER;
117 // Private methods
119 LoginState::LoginState() : logged_in_state_(LOGGED_IN_OOBE),
120 logged_in_user_type_(LOGGED_IN_USER_NONE) {
123 LoginState::~LoginState() {
126 void LoginState::NotifyObservers() {
127 FOR_EACH_OBSERVER(LoginState::Observer, observer_list_,
128 LoggedInStateChanged());
131 } // namespace chromeos