Roll src/third_party/WebKit a6818f9:a3b4a2e (svn 202549:202551)
[chromium-blink-merge.git] / chromeos / login / login_state.h
blob394357e87f52947c355cc3cc5478238f360df8bc
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"
12 namespace chromeos {
14 // Tracks the login state of chrome, accessible to Ash and other chromeos code.
15 class CHROMEOS_EXPORT LoginState {
16 public:
17 enum LoggedInState {
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_PUBLIC_ACCOUNT, // A user is logged in to a public session.
29 LOGGED_IN_USER_SUPERVISED, // A supervised user is logged in
30 LOGGED_IN_USER_KIOSK_APP // Is in kiosk app mode
33 class Observer {
34 public:
35 // Called when either the login state or the logged in user type changes.
36 virtual void LoggedInStateChanged() = 0;
38 protected:
39 virtual ~Observer() {}
42 // Manage singleton instance.
43 static void Initialize();
44 static void Shutdown();
45 static LoginState* Get();
46 static bool IsInitialized();
48 // Add/remove observers.
49 void AddObserver(Observer* observer);
50 void RemoveObserver(Observer* observer);
52 // Sets the logged in state, user type, and primary user hash when the
53 // primary user initialy logs in. Also notifies observers.
54 void SetLoggedInStateAndPrimaryUser(
55 LoggedInState state,
56 LoggedInUserType type,
57 const std::string& primary_user_hash);
59 // Sets the logged in state and user type. Also notifies observers. Used
60 // in tests or situations where there is no primary user (e.g. from the
61 // login screen).
62 void SetLoggedInState(LoggedInState state, LoggedInUserType type);
64 // Gets the logged in user type.
65 LoggedInUserType GetLoggedInUserType() const;
67 // Returns true if a user is considered to be logged in.
68 bool IsUserLoggedIn() const;
70 // Returns true if |logged_in_state_| is safe mode (i.e. the user is not yet
71 // logged in, and only the owner will be allowed to log in).
72 bool IsInSafeMode() const;
74 // Returns true if logged in to a guest session.
75 bool IsGuestSessionUser() const;
77 // Returns true if logged in to a public session.
78 bool IsPublicSessionUser() const;
80 // Returns true if logged in as a kiosk app.
81 bool IsKioskApp() const;
83 // Whether a network profile is created for the user.
84 bool UserHasNetworkProfile() const;
86 // Returns true if the user is an authenticated user (i.e. the user is not
87 // using an anonymous session like public or guest session)
88 bool IsUserAuthenticated() const;
90 // Returns true if the user is authenticated by logging into Google account
91 // (i.e. not using an anonymous nor supervised session).
92 bool IsUserGaiaAuthenticated() const;
94 void set_always_logged_in(bool always_logged_in) {
95 always_logged_in_ = always_logged_in;
98 const std::string& primary_user_hash() const { return primary_user_hash_; }
100 private:
101 LoginState();
102 virtual ~LoginState();
104 void NotifyObservers();
106 LoggedInState logged_in_state_;
107 LoggedInUserType logged_in_user_type_;
108 std::string primary_user_hash_;
109 base::ObserverList<Observer> observer_list_;
111 // If true, it always thinks the current status as logged in. Set to true by
112 // default running on a Linux desktop without flags and test cases. To test
113 // behaviors with a specific login state, call set_always_logged_in(false).
114 bool always_logged_in_;
116 DISALLOW_COPY_AND_ASSIGN(LoginState);
119 } // namespace chromeos
121 #endif // CHROMEOS_LOGIN_LOGIN_STATE_H_