• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROMEOS_LOGIN_LOGIN_STATE_H_
6 #define CHROMEOS_LOGIN_LOGIN_STATE_H_
7 
8 #include "base/basictypes.h"
9 #include "base/observer_list.h"
10 #include "chromeos/chromeos_export.h"
11 
12 namespace chromeos {
13 
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_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
22   };
23 
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
33   };
34 
35   class Observer {
36    public:
37     // Called when either the login state or the logged in user type changes.
38     virtual void LoggedInStateChanged() = 0;
39 
40    protected:
~Observer()41     virtual ~Observer() {}
42   };
43 
44   // Manage singleton instance.
45   static void Initialize();
46   static void Shutdown();
47   static LoginState* Get();
48   static bool IsInitialized();
49 
50   // Add/remove observers.
51   void AddObserver(Observer* observer);
52   void RemoveObserver(Observer* observer);
53 
54   // Set the logged in state and user type.
55   void SetLoggedInState(LoggedInState state, LoggedInUserType type);
56 
57   // Get the logged in user type.
58   LoggedInUserType GetLoggedInUserType() const;
59 
60   // Returns true if a user is considered to be logged in.
61   bool IsUserLoggedIn() const;
62 
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;
66 
67   // Returns true if logged in and is a guest, retail, or public user.
68   bool IsGuestUser() const;
69 
70   // Returns true if the user is an authenticated user (i.e. non public account)
71   bool IsUserAuthenticated() const;
72 
73   // Returns true if the user is authenticated by logging into Google account
74   // (i.e., non public nor locally managed account).
75   bool IsUserGaiaAuthenticated() const;
76 
set_always_logged_in(bool always_logged_in)77   void set_always_logged_in(bool always_logged_in) {
78     always_logged_in_ = always_logged_in;
79   }
80 
81  private:
82   LoginState();
83   virtual ~LoginState();
84 
85   void NotifyObservers();
86 
87   LoggedInState logged_in_state_;
88   LoggedInUserType logged_in_user_type_;
89   ObserverList<Observer> observer_list_;
90 
91   // If true, it always thinks the current status as logged in. Set to true by
92   // default running on a Linux desktop without flags and test cases. To test
93   // behaviors with a specific login state, call set_always_logged_in(false).
94   bool always_logged_in_;
95 
96   DISALLOW_COPY_AND_ASSIGN(LoginState);
97 };
98 
99 }  // namespace chromeos
100 
101 #endif  // CHROMEOS_LOGIN_LOGIN_STATE_H_
102