1// Copyright 2014 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 COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_
6#define COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_
7
8#include "base/memory/scoped_ptr.h"
9#include "components/session_manager/session_manager_export.h"
10
11namespace session_manager {
12
13class SessionManagerDelegate;
14
15// TODO(nkostylev): Get rid/consolidate with:
16// ash::SessionStateDelegate::SessionState and chromeos::LoggedInState.
17enum SESSION_EXPORT SessionState {
18  // Default value, when session state hasn't been initialized yet.
19  SESSION_STATE_UNKNOWN = 0,
20
21  // Running out of box UI.
22  SESSION_STATE_OOBE,
23
24  // Running login UI (primary user) but user sign in hasn't completed yet.
25  SESSION_STATE_LOGIN_PRIMARY,
26
27  // Running login UI (primary or secondary user), user sign in has been
28  // completed but login UI hasn't been hidden yet. This means that either
29  // some session initialization is happening or user has to go through some
30  // UI flow on the same login UI like select avatar, agree to terms of
31  // service etc.
32  SESSION_STATE_LOGGED_IN_NOT_ACTIVE,
33
34  // A user(s) has logged in *and* login UI is hidden i.e. user session is
35  // not blocked.
36  SESSION_STATE_ACTIVE,
37
38  // Same as SESSION_STATE_LOGIN_PRIMARY but for multi-profiles sign in i.e.
39  // when there's at least one user already active in the session.
40  SESSION_STATE_LOGIN_SECONDARY,
41};
42
43class SESSION_EXPORT SessionManager {
44 public:
45  SessionManager();
46  virtual ~SessionManager();
47
48  // Returns current SessionManager instance and NULL if it hasn't been
49  // initialized yet.
50  static SessionManager* Get();
51
52  SessionState session_state() const { return session_state_; }
53  virtual void SetSessionState(SessionState state);
54
55  // Let session delegate executed on its plan of actions depending on the
56  // current session type / state.
57  void Start();
58
59  // Returns true when the browser has crashed and restarted during the current
60  // user's session.
61  static bool HasBrowserRestarted();
62
63 protected:
64  // Initializes SessionManager with delegate.
65  void Initialize(SessionManagerDelegate* delegate);
66
67  // Sets SessionManager instance.
68  static void SetInstance(SessionManager* session_manager);
69
70 private:
71  // Pointer to the existing SessionManager instance (if any).
72  // Set in ctor, reset in dtor. Not owned since specific implementation of
73  // SessionManager should decide on its own appropriate owner of SessionManager
74  // instance. For src/chrome implementation such place is
75  // g_browser_process->platform_part().
76  static SessionManager* instance;
77
78  SessionState session_state_;
79  scoped_ptr<SessionManagerDelegate> delegate_;
80
81  DISALLOW_COPY_AND_ASSIGN(SessionManager);
82};
83
84class SESSION_EXPORT SessionManagerDelegate {
85 public:
86  SessionManagerDelegate();
87  virtual ~SessionManagerDelegate();
88
89  virtual void SetSessionManager(
90      session_manager::SessionManager* session_manager);
91
92  // Executes specific actions defined by this delegate.
93  virtual void Start() = 0;
94
95 protected:
96  session_manager::SessionManager* session_manager_;
97
98 private:
99  DISALLOW_COPY_AND_ASSIGN(SessionManagerDelegate);
100};
101
102}  // namespace session_manager
103
104#endif  // COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_
105