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 #ifndef CHROMEOS_LOGIN_LOGIN_STATE_H_
6 #define CHROMEOS_LOGIN_LOGIN_STATE_H_
8 #include "base/basictypes.h"
9 #include "base/observer_list.h"
10 #include "chromeos/chromeos_export.h"
14 // Tracks the login state of chrome, accessible to Ash and other chromeos code.
15 class CHROMEOS_EXPORT LoginState
{
18 LOGGED_IN_OOBE
, // Out of box experience not completed
19 LOGGED_IN_NONE
, // Not logged in
20 LOGGED_IN_SAFE_MODE
, // Not logged in and login not allowed for non-owners
21 LOGGED_IN_ACTIVE
// A user has logged in
24 enum LoggedInUserType
{
25 LOGGED_IN_USER_NONE
, // User is not logged in
26 LOGGED_IN_USER_REGULAR
, // A regular user is logged in
27 LOGGED_IN_USER_OWNER
, // The owner of the device is logged in
28 LOGGED_IN_USER_GUEST
, // A guest is logged in (i.e. incognito)
29 LOGGED_IN_USER_RETAIL_MODE
, // Is in retail mode
30 LOGGED_IN_USER_PUBLIC_ACCOUNT
, // A public account is logged in
31 LOGGED_IN_USER_LOCALLY_MANAGED
, // A locally managed user is logged in
32 LOGGED_IN_USER_KIOSK_APP
// Is in kiosk app mode
37 // Called when either the login state or the logged in user type changes.
38 virtual void LoggedInStateChanged() = 0;
41 virtual ~Observer() {}
44 // Manage singleton instance.
45 static void Initialize();
46 static void Shutdown();
47 static LoginState
* Get();
48 static bool IsInitialized();
50 // Add/remove observers.
51 void AddObserver(Observer
* observer
);
52 void RemoveObserver(Observer
* observer
);
54 // Set the logged in state and user type.
55 void SetLoggedInState(LoggedInState state
, LoggedInUserType type
);
57 // Get the logged in user type.
58 LoggedInUserType
GetLoggedInUserType() const;
60 // Returns true if a user is considered to be logged in.
61 bool IsUserLoggedIn() const;
63 // Returns true if |logged_in_state_| is safe mode (i.e. the user is not yet
64 // logged in, and only the owner will be allowed to log in).
65 bool IsInSafeMode() const;
67 // Returns true if logged in and is a guest, retail, or public user.
68 bool IsGuestUser() const;
70 // Returns true if logged in as a kiosk app.
71 bool IsKioskApp() const;
73 // Whether a network profile is created for the user.
74 bool UserHasNetworkProfile() const;
76 // Returns true if the user is an authenticated user (i.e. non public account)
77 bool IsUserAuthenticated() const;
79 // Returns true if the user is authenticated by logging into Google account
80 // (i.e., non public nor locally managed account).
81 bool IsUserGaiaAuthenticated() const;
83 void set_always_logged_in(bool always_logged_in
) {
84 always_logged_in_
= always_logged_in
;
89 virtual ~LoginState();
91 void NotifyObservers();
93 LoggedInState logged_in_state_
;
94 LoggedInUserType logged_in_user_type_
;
95 ObserverList
<Observer
> observer_list_
;
97 // If true, it always thinks the current status as logged in. Set to true by
98 // default running on a Linux desktop without flags and test cases. To test
99 // behaviors with a specific login state, call set_always_logged_in(false).
100 bool always_logged_in_
;
102 DISALLOW_COPY_AND_ASSIGN(LoginState
);
105 } // namespace chromeos
107 #endif // CHROMEOS_LOGIN_LOGIN_STATE_H_