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_NONE
, // Not logged in
19 LOGGED_IN_SAFE_MODE
, // Not logged in and login not allowed for non-owners
20 LOGGED_IN_ACTIVE
// A user has logged in
23 enum LoggedInUserType
{
24 LOGGED_IN_USER_NONE
, // User is not logged in
25 LOGGED_IN_USER_REGULAR
, // A regular user is logged in
26 LOGGED_IN_USER_OWNER
, // The owner of the device is logged in
27 LOGGED_IN_USER_GUEST
, // A guest is logged in (i.e. incognito)
28 LOGGED_IN_USER_RETAIL_MODE
, // Is in retail mode
29 LOGGED_IN_USER_PUBLIC_ACCOUNT
, // A user is logged in to a public session.
30 LOGGED_IN_USER_SUPERVISED
, // A supervised user is logged in
31 LOGGED_IN_USER_KIOSK_APP
// Is in kiosk app mode
36 // Called when either the login state or the logged in user type changes.
37 virtual void LoggedInStateChanged() = 0;
40 virtual ~Observer() {}
43 // Manage singleton instance.
44 static void Initialize();
45 static void Shutdown();
46 static LoginState
* Get();
47 static bool IsInitialized();
49 // Add/remove observers.
50 void AddObserver(Observer
* observer
);
51 void RemoveObserver(Observer
* observer
);
53 // Sets the logged in state, user type, and primary user hash when the
54 // primary user initialy logs in. Also notifies observers.
55 void SetLoggedInStateAndPrimaryUser(
57 LoggedInUserType type
,
58 const std::string
& primary_user_hash
);
60 // Sets the logged in state and user type. Also notifies observers. Used
61 // in tests or situations where there is no primary user (e.g. from the
63 void SetLoggedInState(LoggedInState state
, LoggedInUserType type
);
65 // Gets the logged in user type.
66 LoggedInUserType
GetLoggedInUserType() const;
68 // Returns true if a user is considered to be logged in.
69 bool IsUserLoggedIn() const;
71 // Returns true if |logged_in_state_| is safe mode (i.e. the user is not yet
72 // logged in, and only the owner will be allowed to log in).
73 bool IsInSafeMode() const;
75 // Returns true if logged in to a guest session.
76 bool IsGuestSessionUser() const;
78 // Returns true if logged in to a public session.
79 bool IsPublicSessionUser() const;
81 // Returns true if logged in as a kiosk app.
82 bool IsKioskApp() const;
84 // Whether a network profile is created for the user.
85 bool UserHasNetworkProfile() const;
87 // Returns true if the user is an authenticated user (i.e. the user is not
88 // using an anonymous session like public or guest session)
89 bool IsUserAuthenticated() const;
91 // Returns true if the user is authenticated by logging into Google account
92 // (i.e. not using an anonymous nor supervised session).
93 bool IsUserGaiaAuthenticated() const;
95 void set_always_logged_in(bool always_logged_in
) {
96 always_logged_in_
= always_logged_in
;
99 const std::string
& primary_user_hash() const { return primary_user_hash_
; }
103 virtual ~LoginState();
105 void NotifyObservers();
107 LoggedInState logged_in_state_
;
108 LoggedInUserType logged_in_user_type_
;
109 std::string primary_user_hash_
;
110 ObserverList
<Observer
> observer_list_
;
112 // If true, it always thinks the current status as logged in. Set to true by
113 // default running on a Linux desktop without flags and test cases. To test
114 // behaviors with a specific login state, call set_always_logged_in(false).
115 bool always_logged_in_
;
117 DISALLOW_COPY_AND_ASSIGN(LoginState
);
120 } // namespace chromeos
122 #endif // CHROMEOS_LOGIN_LOGIN_STATE_H_