summaryrefslogtreecommitdiffstats
path: root/components/session_manager/core/session_manager.h
blob: d2e97043d4a5f9f59a01d8beb5029641b200269f (plain)
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
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_
#define COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_

#include "base/memory/scoped_ptr.h"
#include "components/session_manager/session_manager_export.h"

namespace session_manager {

class SessionManagerDelegate;

// TODO(nkostylev): Get rid/consolidate with:
// ash::SessionStateDelegate::SessionState and chromeos::LoggedInState.
enum SESSION_EXPORT SessionState {
  // Default value, when session state hasn't been initialized yet.
  SESSION_STATE_UNKNOWN = 0,

  // Running out of box UI.
  SESSION_STATE_OOBE,

  // Running login UI (primary user) but user sign in hasn't completed yet.
  SESSION_STATE_LOGIN_PRIMARY,

  // Running login UI (primary or secondary user), user sign in has been
  // completed but login UI hasn't been hidden yet. This means that either
  // some session initialization is happening or user has to go through some
  // UI flow on the same login UI like select avatar, agree to terms of
  // service etc.
  SESSION_STATE_LOGGED_IN_NOT_ACTIVE,

  // A user(s) has logged in *and* login UI is hidden i.e. user session is
  // not blocked.
  SESSION_STATE_ACTIVE,

  // Same as SESSION_STATE_LOGIN_PRIMARY but for multi-profiles sign in i.e.
  // when there's at least one user already active in the session.
  SESSION_STATE_LOGIN_SECONDARY,
};

class SESSION_EXPORT SessionManager {
 public:
  SessionManager();
  virtual ~SessionManager();

  // Returns current SessionManager instance and NULL if it hasn't been
  // initialized yet.
  static SessionManager* Get();

  SessionState session_state() const { return session_state_; }
  virtual void SetSessionState(SessionState state);

  // Let session delegate executed on its plan of actions depending on the
  // current session type / state.
  void Start();

  // Returns true when the browser has crashed and restarted during the current
  // user's session.
  static bool HasBrowserRestarted();

 protected:
  // Initializes SessionManager with delegate.
  void Initialize(SessionManagerDelegate* delegate);

  // Sets SessionManager instance.
  static void SetInstance(SessionManager* session_manager);

 private:
  // Pointer to the existing SessionManager instance (if any).
  // Set in ctor, reset in dtor. Not owned since specific implementation of
  // SessionManager should decide on its own appropriate owner of SessionManager
  // instance. For src/chrome implementation such place is
  // g_browser_process->platform_part().
  static SessionManager* instance;

  SessionState session_state_;
  scoped_ptr<SessionManagerDelegate> delegate_;

  DISALLOW_COPY_AND_ASSIGN(SessionManager);
};

class SESSION_EXPORT SessionManagerDelegate {
 public:
  SessionManagerDelegate();
  virtual ~SessionManagerDelegate();

  virtual void SetSessionManager(
      session_manager::SessionManager* session_manager);

  // Executes specific actions defined by this delegate.
  virtual void Start() = 0;

 protected:
  session_manager::SessionManager* session_manager_;

 private:
  DISALLOW_COPY_AND_ASSIGN(SessionManagerDelegate);
};

}  // namespace session_manager

#endif  // COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_