OLD | NEW |
(Empty) | |
| 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/observer_list.h" |
| 9 #include "chromeos/chromeos_export.h" |
| 10 #include "chromeos/dbus/session_manager_client.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 : public SessionManagerClient::Observer { |
| 16 public: |
| 17 enum State { |
| 18 LOGGED_IN_UNKNOWN, |
| 19 LOGGED_IN_OOBE, // Out of box experience not completed |
| 20 LOGGED_IN_NONE, // Not logged in |
| 21 LOGGED_IN_LOCKED, // A user has locked the screen |
| 22 LOGGED_IN_USER, // A normal user is logged in |
| 23 LOGGED_IN_OWNER, // The owner of the device is logged in |
| 24 LOGGED_IN_GUEST, // A guest is logged in (i.e. incognito) |
| 25 LOGGED_IN_RETAIL_MODE, // Is in retail mode |
| 26 LOGGED_IN_PUBLIC, // A public account is logged in |
| 27 LOGGED_IN_KIOSK_APP // Is in kiosk app mode |
| 28 }; |
| 29 |
| 30 class Observer { |
| 31 public: |
| 32 // Called when the login state changes. |
| 33 virtual void LoginStateChanged(LoginState::State state) = 0; |
| 34 |
| 35 protected: |
| 36 virtual ~Observer() {} |
| 37 }; |
| 38 |
| 39 // Manage singleton instance. Must be initialized after DBusThreadManager. |
| 40 static void Initialize(); |
| 41 static void Shutdown(); |
| 42 static LoginState* Get(); |
| 43 static bool IsInitialized(); |
| 44 |
| 45 // Add/remove observers. |
| 46 void AddObserver(Observer* observer); |
| 47 void RemoveObserver(Observer* observer); |
| 48 |
| 49 // Set the base login state to |state|. Note, other factors (e.g. screen lock) |
| 50 // may affect the result of GetLoginState(). |
| 51 void SetLoginState(LoginState::State state); |
| 52 |
| 53 // Returns the current login state. |
| 54 LoginState::State GetLoginState() const; |
| 55 |
| 56 // Returns true if |state_| is a logged in state. |
| 57 bool IsUserLoggedIn(); |
| 58 |
| 59 // Tracks wherther the user is logged in and the browser process has started. |
| 60 void SetSessionStarted(bool session_started); |
| 61 bool IsSessionStarted() const; |
| 62 |
| 63 private: |
| 64 LoginState(); |
| 65 virtual ~LoginState(); |
| 66 |
| 67 // SessionManagerClient::Observer |
| 68 virtual void LockScreen() OVERRIDE; |
| 69 virtual void UnlockScreen() OVERRIDE; |
| 70 |
| 71 void NotifyObservers(); |
| 72 |
| 73 State state_; |
| 74 bool session_started_; |
| 75 bool screen_locked_; |
| 76 ObserverList<LoginState::Observer> observer_list_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(LoginState); |
| 79 }; |
| 80 |
| 81 } // namespace chromeos |
| 82 |
| 83 #endif // CHROMEOS_LOGIN_LOGIN_STATE_H_ |
OLD | NEW |