Home | History | Annotate | Download | only in session
      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 ash {
     27 
     28 class SessionStateObserver;
     29 class UserInfo;
     30 
     31 // The index for the multi-profile item to use. The list is always LRU sorted
     32 // So that the index #0 is the currently active user.
     33 typedef int MultiProfileIndex;
     34 
     35 // A list of user_id.
     36 typedef std::vector<std::string> UserIdList;
     37 
     38 // Delegate for checking and modifying the session state.
     39 // TODO(oshima): Replace MultiProfileIndex with BrowsreContext, bacause
     40 // GetUserXXX are useful for non multi profile scenario in ash_shell.
     41 class ASH_EXPORT SessionStateDelegate {
     42  public:
     43   // Defines the cycle direction for |CycleActiveUser|.
     44   enum CycleUser {
     45     CYCLE_TO_NEXT_USER = 0,  // Cycle to the next user.
     46     CYCLE_TO_PREVIOUS_USER,  // Cycle to the previous user.
     47   };
     48 
     49   // Defines session state i.e. whether session is running or not and
     50   // whether user session is blocked by things like multi-profile login.
     51   enum SessionState {
     52     // When primary user login UI is shown i.e. after boot or sign out,
     53     // no active user session exists yet.
     54     SESSION_STATE_LOGIN_PRIMARY = 0,
     55 
     56     // Inside user session (including lock screen),
     57     // no login UI (primary or multi-profiles) is shown.
     58     SESSION_STATE_ACTIVE,
     59 
     60     // When secondary user login UI is shown i.e. other users are
     61     // already logged in and is currently adding another user to the session.
     62     SESSION_STATE_LOGIN_SECONDARY,
     63   };
     64 
     65   virtual ~SessionStateDelegate() {};
     66 
     67   // Returns the browser context for the user given by |index|.
     68   virtual content::BrowserContext* GetBrowserContextByIndex(
     69       MultiProfileIndex index) = 0;
     70 
     71   // Returns the browser context associated with the window.
     72   virtual content::BrowserContext* GetBrowserContextForWindow(
     73       aura::Window* window) = 0;
     74 
     75   // Returns the maximum possible number of logged in users.
     76   virtual int GetMaximumNumberOfLoggedInUsers() const = 0;
     77 
     78   // Returns the number of signed in users. If 0 is returned, there is either
     79   // no session in progress or no active user.
     80   virtual int NumberOfLoggedInUsers() const = 0;
     81 
     82   // Returns |true| if the session has been fully started for the active user.
     83   // When a user becomes active, the profile and browser UI are not immediately
     84   // available. Only once this method starts returning |true| is the browser
     85   // startup complete and both profile and UI are fully available.
     86   virtual bool IsActiveUserSessionStarted() const = 0;
     87 
     88   // Returns true if the screen can be locked.
     89   virtual bool CanLockScreen() const = 0;
     90 
     91   // Returns true if the screen is currently locked.
     92   virtual bool IsScreenLocked() const = 0;
     93 
     94   // Returns true if the screen should be locked when the system is about to
     95   // suspend.
     96   virtual bool ShouldLockScreenBeforeSuspending() const = 0;
     97 
     98   // Locks the screen. The locking happens asynchronously.
     99   virtual void LockScreen() = 0;
    100 
    101   // Unlocks the screen.
    102   virtual void UnlockScreen() = 0;
    103 
    104   // Returns |true| if user session blocked by some overlying UI. It can be
    105   // login screen, lock screen or screen for adding users into multi-profile
    106   // session.
    107   virtual bool IsUserSessionBlocked() const = 0;
    108 
    109   // Returns current session state.
    110   virtual SessionState GetSessionState() const = 0;
    111 
    112   // TODO(oshima): consolidate these two GetUserInfo.
    113 
    114   // Gets the user info for the user with the given |index|.
    115   // Note that |index| can at maximum be |NumberOfLoggedInUsers() - 1|.
    116   virtual const UserInfo* GetUserInfo(MultiProfileIndex index) const = 0;
    117 
    118   // Gets the avatar image for the user associated with the |context|.
    119   virtual const UserInfo* GetUserInfo(
    120       content::BrowserContext* context) const = 0;
    121 
    122   // Whether or not the window's title should show the avatar.
    123   virtual bool ShouldShowAvatar(aura::Window* window) const = 0;
    124 
    125   // Switches to another active user with |user_id|
    126   // (if that user has already signed in).
    127   virtual void SwitchActiveUser(const std::string& user_id) = 0;
    128 
    129   // Switches the active user to the next or previous user, with the same
    130   // ordering as GetLoggedInUsers.
    131   virtual void CycleActiveUser(CycleUser cycle_user) = 0;
    132 
    133   // Adds or removes sessions state observer.
    134   virtual void AddSessionStateObserver(SessionStateObserver* observer) = 0;
    135   virtual void RemoveSessionStateObserver(SessionStateObserver* observer) = 0;
    136 };
    137 
    138 }  // namespace ash
    139 
    140 #endif  // ASH_SESSION_SESSION_STATE_DELEGATE_H_
    141