Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_ | 5 #ifndef COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_ |
| 6 #define COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_ | 6 #define COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <vector> | |
| 9 | |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "components/session_manager/session_manager_export.h" | 11 #include "components/session_manager/session_manager_export.h" |
| 10 #include "components/session_manager/session_manager_types.h" | 12 #include "components/session_manager/session_manager_types.h" |
| 11 | 13 |
| 14 class AccountId; | |
| 15 | |
| 12 namespace session_manager { | 16 namespace session_manager { |
| 13 | 17 |
| 14 class SESSION_EXPORT SessionManager { | 18 class SESSION_EXPORT SessionManager { |
| 15 public: | 19 public: |
| 16 SessionManager(); | 20 SessionManager(); |
| 17 virtual ~SessionManager(); | 21 virtual ~SessionManager(); |
| 18 | 22 |
| 19 // Returns current SessionManager instance and NULL if it hasn't been | 23 // Returns current SessionManager instance and NULL if it hasn't been |
| 20 // initialized yet. | 24 // initialized yet. |
| 21 static SessionManager* Get(); | 25 static SessionManager* Get(); |
| 22 | 26 |
| 23 SessionState session_state() const { return session_state_; } | |
| 24 virtual void SetSessionState(SessionState state); | 27 virtual void SetSessionState(SessionState state); |
| 25 | 28 |
| 29 // Creates a session for the given user. | |
| 30 virtual void CreateSession(const AccountId& user_account_id, | |
| 31 const std::string& user_id_hash, | |
| 32 bool browser_restart = false); | |
|
achuithb
2016/10/31 21:55:57
I think we're not supposed to use default argument
xiyuan
2016/10/31 22:29:45
Changed to use function overloading and removed "v
| |
| 33 | |
| 26 // Returns true if we're logged in and browser has been started i.e. | 34 // Returns true if we're logged in and browser has been started i.e. |
| 27 // browser_creator.LaunchBrowser(...) was called after sign in | 35 // browser_creator.LaunchBrowser(...) was called after sign in |
| 28 // or restart after crash. | 36 // or restart after crash. |
| 29 virtual bool IsSessionStarted() const; | 37 virtual bool IsSessionStarted() const; |
| 30 | 38 |
| 31 // Called when browser session is started i.e. after | 39 // Called when browser session is started i.e. after |
| 32 // browser_creator.LaunchBrowser(...) was called after user sign in. | 40 // browser_creator.LaunchBrowser(...) was called after user sign in. |
| 33 // When user is at the image screen IsUserLoggedIn() will return true | 41 // When user is at the image screen IsUserLoggedIn() will return true |
| 34 // but IsSessionStarted() will return false. During the kiosk splash screen, | 42 // but IsSessionStarted() will return false. During the kiosk splash screen, |
| 35 // we perform additional initialization after the user is logged in but | 43 // we perform additional initialization after the user is logged in but |
| 36 // before the session has been started. | 44 // before the session has been started. |
| 37 virtual void SessionStarted(); | 45 virtual void SessionStarted(); |
| 38 | 46 |
| 47 SessionState session_state() const { return session_state_; } | |
| 48 const std::vector<Session>& sessions() const { return sessions_; } | |
| 49 | |
| 39 protected: | 50 protected: |
| 51 // Notifies UserManager about a user signs in when creating a user session. | |
| 52 virtual void NotifyUserLoggedIn(const AccountId& user_account_id, | |
| 53 const std::string& user_id_hash, | |
| 54 bool browser_restart); | |
| 55 | |
| 40 // Sets SessionManager instance. | 56 // Sets SessionManager instance. |
| 41 static void SetInstance(SessionManager* session_manager); | 57 static void SetInstance(SessionManager* session_manager); |
| 42 | 58 |
| 43 private: | 59 private: |
| 44 // Pointer to the existing SessionManager instance (if any). | 60 // Pointer to the existing SessionManager instance (if any). |
| 45 // Set in ctor, reset in dtor. Not owned since specific implementation of | 61 // Set in ctor, reset in dtor. Not owned since specific implementation of |
| 46 // SessionManager should decide on its own appropriate owner of SessionManager | 62 // SessionManager should decide on its own appropriate owner of SessionManager |
| 47 // instance. For src/chrome implementation such place is | 63 // instance. For src/chrome implementation such place is |
| 48 // g_browser_process->platform_part(). | 64 // g_browser_process->platform_part(). |
| 49 static SessionManager* instance; | 65 static SessionManager* instance; |
| 50 | 66 |
| 51 SessionState session_state_ = SessionState::UNKNOWN; | 67 SessionState session_state_ = SessionState::UNKNOWN; |
| 52 | 68 |
| 53 // True if SessionStarted() has been called. | 69 // True if SessionStarted() has been called. |
| 54 bool session_started_ = false; | 70 bool session_started_ = false; |
| 55 | 71 |
| 72 // Id of the primary session, i.e. the first user session. | |
| 73 static const SessionId kPrimarySessionId = 1; | |
| 74 | |
| 75 // ID assigned to the next session. | |
| 76 SessionId next_id_ = kPrimarySessionId; | |
| 77 | |
| 78 // Keeps track of user sessions. | |
| 79 std::vector<Session> sessions_; | |
| 80 | |
| 56 DISALLOW_COPY_AND_ASSIGN(SessionManager); | 81 DISALLOW_COPY_AND_ASSIGN(SessionManager); |
| 57 }; | 82 }; |
| 58 | 83 |
| 59 } // namespace session_manager | 84 } // namespace session_manager |
| 60 | 85 |
| 61 #endif // COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_ | 86 #endif // COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_ |
| OLD | NEW |