• 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 ASH_SESSION_SESSION_STATE_DELEGATE_H_
6 #define ASH_SESSION_SESSION_STATE_DELEGATE_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "ash/ash_export.h"
12 #include "base/strings/string16.h"
13 
14 namespace aura {
15 class Window;
16 }  // namespace aura
17 
18 namespace content {
19 class BrowserContext;
20 }
21 
22 namespace gfx {
23 class ImageSkia;
24 }  // namespace gfx
25 
26 namespace user_manager {
27 class UserInfo;
28 }  // namespace user_manager
29 
30 namespace ash {
31 
32 class SessionStateObserver;
33 
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;
37 
38 // A list of user_id.
39 typedef std::vector<std::string> UserIdList;
40 
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 {
45  public:
46   // Defines the cycle direction for |CycleActiveUser|.
47   enum CycleUser {
48     CYCLE_TO_NEXT_USER = 0,  // Cycle to the next user.
49     CYCLE_TO_PREVIOUS_USER,  // Cycle to the previous user.
50   };
51 
52   enum AddUserError {
53     ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER = 0,
54     ADD_USER_ERROR_OUT_OF_USERS,
55     ADD_USER_ERROR_MAXIMUM_USERS_REACHED,
56   };
57 
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.
60   enum SessionState {
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,
64 
65     // Inside user session (including lock screen),
66     // no login UI (primary or multi-profiles) is shown.
67     SESSION_STATE_ACTIVE,
68 
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,
72   };
73 
~SessionStateDelegate()74   virtual ~SessionStateDelegate() {};
75 
76   // Returns the browser context for the user given by |index|.
77   virtual content::BrowserContext* GetBrowserContextByIndex(
78       MultiProfileIndex index) = 0;
79 
80   // Returns the browser context associated with the window.
81   virtual content::BrowserContext* GetBrowserContextForWindow(
82       aura::Window* window) = 0;
83 
84   // Returns the maximum possible number of logged in users.
85   virtual int GetMaximumNumberOfLoggedInUsers() const = 0;
86 
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;
90 
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
93   // returned false.
94   virtual bool CanAddUserToMultiProfile(AddUserError* error) const;
95 
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;
101 
102   // Returns true if the screen can be locked.
103   virtual bool CanLockScreen() const = 0;
104 
105   // Returns true if the screen is currently locked.
106   virtual bool IsScreenLocked() const = 0;
107 
108   // Returns true if the screen should be locked when the system is about to
109   // suspend.
110   virtual bool ShouldLockScreenBeforeSuspending() const = 0;
111 
112   // Locks the screen. The locking happens asynchronously.
113   virtual void LockScreen() = 0;
114 
115   // Unlocks the screen.
116   virtual void UnlockScreen() = 0;
117 
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
120   // session.
121   virtual bool IsUserSessionBlocked() const = 0;
122 
123   // Returns current session state.
124   virtual SessionState GetSessionState() const = 0;
125 
126   // TODO(oshima): consolidate these two GetUserInfo.
127 
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;
132 
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;
136 
137   // Whether or not the window's title should show the avatar.
138   virtual bool ShouldShowAvatar(aura::Window* window) const = 0;
139 
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;
143 
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;
147 
148   // Returns true if primary user policy does not forbid multiple signin.
149   virtual bool IsMultiProfileAllowedByPrimaryUserPolicy() const = 0;
150 
151   // Adds or removes sessions state observer.
152   virtual void AddSessionStateObserver(SessionStateObserver* observer) = 0;
153   virtual void RemoveSessionStateObserver(SessionStateObserver* observer) = 0;
154 
155   bool IsInSecondaryLoginScreen() const;
156 };
157 
158 }  // namespace ash
159 
160 #endif  // ASH_SESSION_SESSION_STATE_DELEGATE_H_
161