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_ACTIVE // A user has logged in 21 }; 22 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 public account is logged in 30 LOGGED_IN_USER_LOCALLY_MANAGED, // A locally managed user is logged in 31 LOGGED_IN_USER_KIOSK_APP // Is in kiosk app mode 32 }; 33 34 class Observer { 35 public: 36 // Called when either the login state or the logged in user type changes. 37 virtual void LoggedInStateChanged(LoggedInState state) = 0; 38 39 protected: 40 virtual ~Observer() {} 41 }; 42 43 // Manage singleton instance. 44 static void Initialize(); 45 static void Shutdown(); 46 static LoginState* Get(); 47 static bool IsInitialized(); 48 49 // Add/remove observers. 50 void AddObserver(Observer* observer); 51 void RemoveObserver(Observer* observer); 52 53 // Set the logged in state and user type. 54 void SetLoggedInState(LoggedInState state, LoggedInUserType type); 55 56 // Get the logged in state / user type. 57 LoggedInState GetLoggedInState() const; 58 LoggedInUserType GetLoggedInUserType() const; 59 60 // Returns true if |logged_in_state_| is active. 61 bool IsUserLoggedIn() const; 62 63 // Returns true if logged in and is a guest, retail, public, or kiosk user. 64 bool IsGuestUser() const; 65 66 // Returns true if the user is an authenticated user (i.e. non public account) 67 bool IsUserAuthenticated() const; 68 69 // Returns true if the user is authenticated by logging into Google account 70 // (i.e., non public nor locally managed account). 71 bool IsUserGaiaAuthenticated() const; 72 73 private: 74 LoginState(); 75 virtual ~LoginState(); 76 77 void NotifyObservers(); 78 79 LoggedInState logged_in_state_; 80 LoggedInUserType logged_in_user_type_; 81 ObserverList<Observer> observer_list_; 82 83 DISALLOW_COPY_AND_ASSIGN(LoginState); 84 }; 85 86 } // namespace chromeos 87 88 #endif // CHROMEOS_LOGIN_LOGIN_STATE_H_ 89