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 ASH_SESSION_SESSION_STATE_DELEGATE_H_
6 #define ASH_SESSION_SESSION_STATE_DELEGATE_H_
11 #include "ash/ash_export.h"
12 #include "base/strings/string16.h"
26 namespace user_manager
{
28 } // namespace user_manager
32 class SessionStateObserver
;
34 // The index for the multi-profile item to use. The list is always LRU sorted
35 // So that the index #0 is the currently active user.
36 typedef int MultiProfileIndex
;
39 typedef std::vector
<std::string
> UserIdList
;
41 // Delegate for checking and modifying the session state.
42 // TODO(oshima): Replace MultiProfileIndex with BrowsreContext, bacause
43 // GetUserXXX are useful for non multi profile scenario in ash_shell.
44 class ASH_EXPORT SessionStateDelegate
{
46 // Defines the cycle direction for |CycleActiveUser|.
48 CYCLE_TO_NEXT_USER
= 0, // Cycle to the next user.
49 CYCLE_TO_PREVIOUS_USER
, // Cycle to the previous user.
53 ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER
= 0,
54 ADD_USER_ERROR_OUT_OF_USERS
,
55 ADD_USER_ERROR_MAXIMUM_USERS_REACHED
,
58 // Defines session state i.e. whether session is running or not and
59 // whether user session is blocked by things like multi-profile login.
61 // When primary user login UI is shown i.e. after boot or sign out,
62 // no active user session exists yet.
63 SESSION_STATE_LOGIN_PRIMARY
= 0,
65 // Inside user session (including lock screen),
66 // no login UI (primary or multi-profiles) is shown.
69 // When secondary user login UI is shown i.e. other users are
70 // already logged in and is currently adding another user to the session.
71 SESSION_STATE_LOGIN_SECONDARY
,
74 virtual ~SessionStateDelegate() {};
76 // Returns the browser context for the user given by |index|.
77 virtual content::BrowserContext
* GetBrowserContextByIndex(
78 MultiProfileIndex index
) = 0;
80 // Returns the browser context associated with the window.
81 virtual content::BrowserContext
* GetBrowserContextForWindow(
82 aura::Window
* window
) = 0;
84 // Returns the maximum possible number of logged in users.
85 virtual int GetMaximumNumberOfLoggedInUsers() const = 0;
87 // Returns the number of signed in users. If 0 is returned, there is either
88 // no session in progress or no active user.
89 virtual int NumberOfLoggedInUsers() const = 0;
91 // Returns true if there is possible to add more users to multiprofile
92 // session. Error is stored in |error| if it is not NULL and function
94 virtual bool CanAddUserToMultiProfile(AddUserError
* error
) const;
96 // Returns |true| if the session has been fully started for the active user.
97 // When a user becomes active, the profile and browser UI are not immediately
98 // available. Only once this method starts returning |true| is the browser
99 // startup complete and both profile and UI are fully available.
100 virtual bool IsActiveUserSessionStarted() const = 0;
102 // Returns true if the screen can be locked.
103 virtual bool CanLockScreen() const = 0;
105 // Returns true if the screen is currently locked.
106 virtual bool IsScreenLocked() const = 0;
108 // Returns true if the screen should be locked when the system is about to
110 virtual bool ShouldLockScreenBeforeSuspending() const = 0;
112 // Locks the screen. The locking happens asynchronously.
113 virtual void LockScreen() = 0;
115 // Unlocks the screen.
116 virtual void UnlockScreen() = 0;
118 // Returns |true| if user session blocked by some overlying UI. It can be
119 // login screen, lock screen or screen for adding users into multi-profile
121 virtual bool IsUserSessionBlocked() const = 0;
123 // Returns current session state.
124 virtual SessionState
GetSessionState() const = 0;
126 // TODO(oshima): consolidate these two GetUserInfo.
128 // Gets the user info for the user with the given |index|.
129 // Note that |index| can at maximum be |NumberOfLoggedInUsers() - 1|.
130 virtual const user_manager::UserInfo
* GetUserInfo(
131 MultiProfileIndex index
) const = 0;
133 // Gets the avatar image for the user associated with the |context|.
134 virtual const user_manager::UserInfo
* GetUserInfo(
135 content::BrowserContext
* context
) const = 0;
137 // Whether or not the window's title should show the avatar.
138 virtual bool ShouldShowAvatar(aura::Window
* window
) const = 0;
140 // Switches to another active user with |user_id|
141 // (if that user has already signed in).
142 virtual void SwitchActiveUser(const std::string
& user_id
) = 0;
144 // Switches the active user to the next or previous user, with the same
145 // ordering as GetLoggedInUsers.
146 virtual void CycleActiveUser(CycleUser cycle_user
) = 0;
148 // Returns true if primary user policy does not forbid multiple signin.
149 virtual bool IsMultiProfileAllowedByPrimaryUserPolicy() const = 0;
151 // Adds or removes sessions state observer.
152 virtual void AddSessionStateObserver(SessionStateObserver
* observer
) = 0;
153 virtual void RemoveSessionStateObserver(SessionStateObserver
* observer
) = 0;
155 bool IsInSecondaryLoginScreen() const;
160 #endif // ASH_SESSION_SESSION_STATE_DELEGATE_H_