1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147

ash / public / cpp / session / session_controller.h [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_PUBLIC_CPP_SESSION_SESSION_CONTROLLER_H_
#define ASH_PUBLIC_CPP_SESSION_SESSION_CONTROLLER_H_

#include <stdint.h>

#include <string>
#include <vector>

#include "ash/public/cpp/ash_public_export.h"
#include "ash/public/cpp/session/session_types.h"
#include "base/functional/callback_forward.h"
#include "base/time/time.h"

class AccountId;

namespace ash {

class SessionObserver;
class SessionControllerClient;
class SessionActivationObserver;

// Interface to manage user sessions in ash.
class ASH_PUBLIC_EXPORT SessionController {
 public:
  // Get the instance of session controller.
  static SessionController* Get();

  // Sets the client interface.
  virtual void SetClient(SessionControllerClient* client) = 0;

  // Sets the ash session info.
  virtual void SetSessionInfo(const SessionInfo& info) = 0;

  // Updates a user session. This is called when a user session is added or
  // its meta data (e.g. name, avatar) is changed. There is no method to remove
  // a user session because ash/chrome does not support that. All users are
  // logged out at the same time.
  virtual void UpdateUserSession(const UserSession& user_session) = 0;

  // Sets the order of user sessions. The order is keyed by the session id.
  // Currently, session manager set a LRU order with the first one being the
  // active user session.
  virtual void SetUserSessionOrder(
      const std::vector<uint32_t>& user_session_ids) = 0;

  // Prepares ash for lock screen. Currently this ensures the current active
  // window could not be used to mimic the lock screen. Lock screen is created
  // after this call returns.
  using PrepareForLockCallback = base::OnceClosure;
  virtual void PrepareForLock(PrepareForLockCallback callback) = 0;

  // Runs the pre-lock animation to start locking ash. When the call returns,
  // |locked| == true means that the ash post-lock animation is finished and ash
  // is fully locked. Otherwise |locked| is false, which means something is
  // wrong for the lock and ash is not locked. When the call returns with a true
  // |locked|, screen locker runs the post lock jobs such as a11y announcement
  // etc. Invoked by the screen locker during initialization.
  using StartLockCallback = base::OnceCallback<void(bool locked)>;
  virtual void StartLock(StartLockCallback callback) = 0;

  // Notifies ash that chrome lock animations are finished. This is the last
  // event for locking. SessionController forwards it to PowerEventObserver.
  virtual void NotifyChromeLockAnimationsComplete() = 0;

  // Runs the pre-unlock animation. Invoked by the screen locker before
  // dismissing. When the mojo call returns, screen locker takes that as a
  // signal of finished unlock animation and dismisses itself.
  // The boolean parameter will be `true` if the unlock animation was aborted,
  // resulting in the lock screen being reshown. It will be false otherwise and
  // the unlock will proceed as normal.
  using RunUnlockAnimationCallback = base::OnceCallback<void(bool)>;
  virtual void RunUnlockAnimation(RunUnlockAnimationCallback callback) = 0;

  // Notifies that chrome is terminating.
  virtual void NotifyChromeTerminating() = 0;

  // Adds a countdown timer to the system tray menu and creates or updates a
  // notification saying the session length is limited (e.g. a public session in
  // a library). Setting |length_limit| to zero removes the notification.
  virtual void SetSessionLengthLimit(base::TimeDelta length_limit,
                                     base::Time start_time) = 0;

  // Returns whether it's ok to switch the active multiprofile user. May affect
  // or be affected by system state such as window overview mode and screen
  // casting.
  using CanSwitchActiveUserCallback = base::OnceCallback<void(bool can_switch)>;
  virtual void CanSwitchActiveUser(CanSwitchActiveUserCallback callback) = 0;

  // Shows a dialog to explain the implications of signing in multiple users.
  // If |on_accept| is false, |permanently_accept| is ignored.
  using ShowMultiprofilesIntroDialogCallback =
      base::OnceCallback<void(bool on_accept, bool permanently_accept)>;
  virtual void ShowMultiprofilesIntroDialog(
      ShowMultiprofilesIntroDialogCallback callback) = 0;

  // Shows a dialog to confirm that the user wants to teleport a window to
  // another desktop. If |on_accept| is false, |permanently_accept| is ignored.
  using ShowTeleportWarningDialogCallback =
      base::OnceCallback<void(bool on_accept, bool permanently_accept)>;
  virtual void ShowTeleportWarningDialog(
      ShowTeleportWarningDialogCallback callback) = 0;

  // Shows a dialog that explains that the given user is no longer allowed in
  // the session due to a policy change, and aborts the session.
  virtual void ShowMultiprofilesSessionAbortedDialog(
      const std::string& user_email) = 0;

  // Adds/removes session activation observer. The observer is called when
  // session with |account_id| is becoming active or inactive. The observer is
  // immediately called for upon registration with the current status.
  virtual void AddSessionActivationObserverForAccountId(
      const AccountId& account_id,
      SessionActivationObserver* observer) = 0;
  virtual void RemoveSessionActivationObserverForAccountId(
      const AccountId& account_id,
      SessionActivationObserver* observer) = 0;

  // Adds/remove session observer.
  virtual void AddObserver(SessionObserver* observer) = 0;
  virtual void RemoveObserver(SessionObserver* observer) = 0;

  // Returns true if the screen is currently locked.
  virtual bool IsScreenLocked() const = 0;

  // Return the number of users that have previously logged in on the device.
  // Returns nullopt in the event where we cannot query the number of existing
  // users, for instance, when `UserManager` is uninitialized.
  virtual std::optional<int> GetExistingUsersCount() const = 0;

  // Notifies the first user session has finished post login works.
  virtual void NotifyFirstSessionReady() = 0;

  // Notifies the user specified by `account_id` is going to be removed soon.
  virtual void NotifyUserToBeRemoved(const AccountId& account_id) = 0;

 protected:
  SessionController();
  virtual ~SessionController();
};

}  // namespace ash

#endif  // ASH_PUBLIC_CPP_SESSION_SESSION_CONTROLLER_H_